LimitedPrecisionReal.st
author Claus Gittinger <cg@exept.de>
Fri, 10 Jan 1997 20:01:23 +0100
changeset 2141 bba0027204fd
parent 1893 c66af5c46272
child 2388 df5e0eb88999
permissions -rw-r--r--
added #asFixedPoint:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
     1
"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
     2
 COPYRIGHT (c) 1994 by Claus Gittinger
213
3b56a17534fd *** empty log message ***
claus
parents: 112
diff changeset
     3
	      All Rights Reserved
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
     4
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    11
"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    12
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    13
Number subclass:#LimitedPrecisionReal
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    14
	instanceVariableNames:''
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    15
	classVariableNames:''
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    16
	poolDictionaries:''
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    17
	category:'Magnitude-Numbers'
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    18
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    19
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    20
!LimitedPrecisionReal class methodsFor:'documentation'!
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    21
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    22
copyright
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    23
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    24
 COPYRIGHT (c) 1994 by Claus Gittinger
213
3b56a17534fd *** empty log message ***
claus
parents: 112
diff changeset
    25
	      All Rights Reserved
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    26
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    27
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    28
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    30
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    31
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    32
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    33
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    34
!
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    35
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    36
documentation
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    37
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    38
    Abstract superclass for single and double (and maybe more) 
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    39
    precision real numbers (i.e. Float and Double).
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    40
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    41
    Due to historic reasons, ST/X's Floats are what Doubles are in ST-80.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    42
    This may change soon (implementing LPReal is a first step towards this).
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1201
diff changeset
    43
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1201
diff changeset
    44
    [author:]
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1201
diff changeset
    45
        Claus Gittinger
1893
c66af5c46272 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1882
diff changeset
    46
c66af5c46272 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1882
diff changeset
    47
    [see also:]
c66af5c46272 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1882
diff changeset
    48
        Fraction FixedPoint
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    49
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    50
! !
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    51
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    52
!LimitedPrecisionReal class methodsFor:'instance creation'!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    53
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    54
new:aNumber
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    55
    "catch this message - not allowed for floats/doubles"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    56
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    57
    self error:'Floats/Doubles cannot be created with new:'
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    58
! !
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    59
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    60
!LimitedPrecisionReal methodsFor:'accessing'!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    61
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    62
at:index
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    63
    "redefined to prevent access to individual bytes in a real."
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    64
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    65
    self error:'not allowed for floats/doubles'
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    66
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    67
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    68
at:index put:aValue
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    69
    "redefined to prevent access to individual bytes in a real"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    70
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    71
    self error:'not allowed for floats/doubles'
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    72
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    73
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    74
size
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    75
   "redefined since reals are kludgy (ByteArry)"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    76
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    77
   ^ 0
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    78
! !
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    79
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    80
!LimitedPrecisionReal methodsFor:'arithmetic'!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    81
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    82
* aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    83
    "return the product of the receiver and the argument, aNumber"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    84
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    85
"/ as soon as Float are float & Double are doubles,
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    86
"/ use:
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    87
"/    ^ aNumber productFromDouble:self asDouble
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    88
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    89
    ^ aNumber productFromFloat:self asFloat
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    90
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    91
    "Modified: 17.4.1996 / 12:35:36 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    92
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
    93
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    94
+ aNumber
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    95
    "return the sum of the receiver and the argument, aNumber"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
    96
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    97
"/ as soon as Float are float & Double are doubles,
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    98
"/ use:
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    99
"/    ^ aNumber sumFromDouble:self asDouble
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   100
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   101
    ^ aNumber sumFromFloat:self asFloat
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   102
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   103
    "Modified: 17.4.1996 / 12:35:55 / cg"
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   104
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   105
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   106
- aNumber
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   107
    "return the difference of the receiver and the argument, aNumber"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   108
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   109
"/ as soon as Float are float & Double are doubles,
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   110
"/ use:
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   111
"/    ^ aNumber differenceFromDouble:self asDouble
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   112
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   113
    ^ aNumber differenceFromFloat:self asFloat
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   114
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   115
    "Modified: 17.4.1996 / 12:36:07 / cg"
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   116
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   117
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   118
/ aNumber
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   119
    "return the quotient of the receiver and the argument, aNumber"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   120
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   121
    ((aNumber == 0) or:[aNumber = 0.0]) ifTrue:[
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   122
        ^ DivisionByZeroSignal raise.
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   123
    ].
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   124
"/ as soon as Float are float & Double are doubles,
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   125
"/ use:
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   126
"/    ^ aNumber quotientFromDouble:self asDouble
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   127
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   128
    ^ aNumber quotientFromFloat:self asFloat
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   129
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   130
    "Modified: 17.4.1996 / 12:36:21 / cg"
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   131
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   132
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   133
// aNumber
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   134
    "return the integer quotient of dividing the receiver by aNumber with
1882
f5f8a2f201e5 fixed #//
Claus Gittinger <cg@exept.de>
parents: 1865
diff changeset
   135
     truncation towards negative infinity."
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   136
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   137
    ^ (self / aNumber) floor asInteger
1882
f5f8a2f201e5 fixed #//
Claus Gittinger <cg@exept.de>
parents: 1865
diff changeset
   138
f5f8a2f201e5 fixed #//
Claus Gittinger <cg@exept.de>
parents: 1865
diff changeset
   139
    "Modified: 5.11.1996 / 11:45:37 / cg"
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   140
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   141
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   142
\\ aNumber
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   143
    "return the integer remainder of dividing the receiver by aNumber with
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   144
    truncation towards negative infinity."
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   145
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   146
    ^ (self - ((self / aNumber) floor * aNumber)) floor asInteger
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   147
! !
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   148
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   149
!LimitedPrecisionReal methodsFor:'coercion and converting'!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   150
2141
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   151
asFixedPoint
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   152
    "return the receiver as fixedPoint number.
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   153
     Q: what should the scale be here ?"
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   154
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   155
    ^ self asFraction asFixedPoint
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   156
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   157
    "
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   158
     0.3 asFixedPoint
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   159
     0.5 asFixedPoint
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   160
     (1/5) asFloat asFixedPoint 
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   161
     (1/3) asFloat asFixedPoint 
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   162
     (2/3) asFloat asFixedPoint 
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   163
     (1/8) asFloat asFixedPoint
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   164
     3.14159 asFixedPoint
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   165
    "
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   166
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   167
    "Modified: 10.1.1997 / 19:59:56 / cg"
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   168
!
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   169
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   170
asFixedPoint:scale
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   171
    "return the receiver as fixedPoint number with the given
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   172
     number of post-decimal-digits."
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   173
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   174
    ^ self asFraction asFixedPoint:scale
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   175
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   176
    "
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   177
     0.3 asFixedPoint:3     
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   178
     0.5 asFixedPoint:3     
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   179
     (1/5) asFloat asFixedPoint:1  
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   180
     (1/8) asFloat asFixedPoint:1  
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   181
     3.14159 asFixedPoint:2       
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   182
     3.14159 asFixedPoint:3       
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   183
     (3.14159 asFixedPoint:2) asFixedPoint:5  
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   184
    "
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   185
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   186
    "Modified: 10.1.1997 / 19:59:42 / cg"
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   187
!
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   188
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   189
asFraction
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   190
    "return a corresponding fraction
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   191
     - notice, that 'aFract asFloat asFraction' does not always return
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   192
     a good fraction ... due to rounding errors when converting to float"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   193
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   194
    |fract digits power num denom|
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   195
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   196
    "we (indirectly) use printf which knows the precision of floats"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   197
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   198
    fract := self fractionPart.
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   199
    digits := fract printString copyFrom:3.
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   200
    power := digits size.
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   201
    num := (self - fract) asInteger.
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   202
    denom := (10 raisedToInteger:power).
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   203
    num := num * denom.
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   204
    num := num + (Integer readFromString:digits).
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   205
    ^ (Fraction numerator:num denominator:denom) reduced
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   206
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   207
    "0.3 asFraction"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   208
    "0.5 asFraction"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   209
    "(1/5) asFloat asFraction"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   210
    "(1/8) asFloat asFraction"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   211
    "(1/13) asFloat asFraction -> inexact result due to rounding errors"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   212
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   213
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   214
asInteger
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   215
    "return an integer with same value - might truncate"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   216
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   217
    |l v sign|
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   218
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   219
    "this is stupid code - rounding errors accumulate; fix later"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   220
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   221
    sign := self sign.
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   222
    v := self abs.
85
claus
parents: 55
diff changeset
   223
    (v >= 10.0) ifTrue:[
213
3b56a17534fd *** empty log message ***
claus
parents: 112
diff changeset
   224
	l := (v / 10.0) asInteger * 10
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   225
    ] ifFalse:[
213
3b56a17534fd *** empty log message ***
claus
parents: 112
diff changeset
   226
	l := 0
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   227
    ].
85
claus
parents: 55
diff changeset
   228
    v := v - ((v / 10.0) floor * 10) floor.
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   229
    l := l + v truncated.
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   230
    ^ l * sign
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   231
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   232
    "12345.0 asInteger"
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   233
    "1e15 asInteger"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   234
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   235
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   236
coerce:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   237
    "return aNumber converted into receivers type"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   238
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   239
"/ as soon as Float are float & Double are doubles,
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   240
"/ use:
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   241
"/    ^ aNumber asDouble
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   242
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   243
    ^ aNumber asFloat
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   244
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   245
    "Modified: 17.4.1996 / 12:36:46 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   246
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   247
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   248
generality
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   249
    "return the generality value - see ArithmeticValue>>retry:coercing:"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   250
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   251
    ^ 80
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   252
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   253
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   254
!LimitedPrecisionReal methodsFor:'comparing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   255
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   256
< aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   257
    "return true, if the argument is greater"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   258
1201
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   259
"/ as soon as Float are float & Double are doubles,
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   260
"/ use:
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   261
"/    ^ aNumber lessFromDouble:self asDouble
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   262
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   263
    ^ aNumber lessFromFloat:self asFloat
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   264
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   265
    "Modified: 17.4.1996 / 13:34:50 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   266
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   267
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   268
<= aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   269
    "return true, if the argument is greater or equal"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   270
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   271
    ^ self retry:#<= coercing:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   272
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   273
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   274
= aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   275
    "return true, if the arguments value are equal"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   276
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   277
    ^ self retry:#= coercing:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   278
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   279
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   280
> aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   281
    "return true, if the argument is less"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   282
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   283
    ^ self retry:#> coercing:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   284
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   285
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   286
>= aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   287
    "return true, if the argument is less or equal"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   288
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   289
    ^ self retry:#>= coercing:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   290
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   291
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   292
~= aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   293
    "return true, if the arguments value are not equal"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   294
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   295
    ^ self retry:#~= coercing:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   296
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   297
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   298
!LimitedPrecisionReal methodsFor:'copying'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   299
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   300
deepCopy
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   301
    "return a deep copy of myself
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   302
     - because storing into floats is not recommended/allowed, its ok to return the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   303
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   304
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   305
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   306
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   307
deepCopyUsing:aDictionary
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   308
    "return a deep copy of myself
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   309
     - because storing into floats is not recommended/allowed, its ok to return the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   310
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   311
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   312
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   313
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   314
shallowCopy
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   315
    "return a shallow copy of the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   316
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   317
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   318
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   319
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   320
simpleDeepCopy
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   321
    "return a deep copy of the receiver
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   322
     - because storing into floats is not recommended/allowed, its ok to return the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   323
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   324
    ^ self
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   325
! !
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   326
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   327
!LimitedPrecisionReal methodsFor:'double dispatching'!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   328
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   329
differenceFromFraction:aFraction
213
3b56a17534fd *** empty log message ***
claus
parents: 112
diff changeset
   330
    "sent when a fraction does not know how to subtract the receiver, a float"
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   331
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   332
    |d|
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   333
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   334
    d := aFraction denominator.
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   335
    ^ (aFraction numerator - (self * d)) / d
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   336
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   337
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   338
productFromFraction:aFraction
213
3b56a17534fd *** empty log message ***
claus
parents: 112
diff changeset
   339
    "sent when a fraction does not know how to multiply the receiver, a float"
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   340
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   341
    ^ self * aFraction numerator / aFraction denominator
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   342
!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   343
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   344
quotientFromFraction:aFraction
213
3b56a17534fd *** empty log message ***
claus
parents: 112
diff changeset
   345
    "sent when a fraction does not know how to divide by the receiver, a float"
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   346
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   347
    ^ aFraction numerator / (self * aFraction denominator)
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   348
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   349
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   350
sumFromFraction:aFraction
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   351
    "sent when a fraction does not know how to add the receiver, a float"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   352
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   353
    |d|
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   354
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   355
    d := aFraction denominator.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   356
    ^ (self * d + aFraction numerator) / d
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   357
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   358
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   359
!LimitedPrecisionReal methodsFor:'printing & storing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   360
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   361
printOn:aStream
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   362
    "append a printed representation of the receiver to
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   363
     the argument, aStream"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   364
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   365
    aStream nextPutAll:self printString
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   366
!
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   367
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   368
printString
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   369
    "return a printed representation of the receiver"
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   370
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   371
    ^ self subclassResponsibility
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   372
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   373
    "Created: 17.4.1996 / 12:12:20 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   374
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   375
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   376
!LimitedPrecisionReal methodsFor:'testing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   377
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   378
isReal
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   379
    "return true, if the receiver is some kind of real number;
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   380
     false is returned here - the method is redefined from Object."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   381
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   382
    ^ true
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   383
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   384
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   385
negative
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   386
    "return true if the receiver is less than zero"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   387
1201
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   388
"/ as soon as Float are float & Double are doubles,
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   389
"/ use:
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   390
"/    ^ self asDouble negative
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   391
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   392
    ^ self asFloat negative
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   393
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   394
    "Modified: 17.4.1996 / 13:35:00 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   395
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   396
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   397
positive
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   398
    "return true if the receiver is greater or equal to zero"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   399
1201
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   400
"/ as soon as Float are float & Double are doubles,
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   401
"/ use:
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   402
"/    ^ self asDouble positive
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   403
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   404
    ^ self asFloat positive
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   405
24a5faa7e305 oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents: 1200
diff changeset
   406
    "Modified: 17.4.1996 / 13:35:10 / cg"
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   407
! !
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   408
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   409
!LimitedPrecisionReal methodsFor:'truncation and rounding'!
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   410
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   411
fractionPart
1865
5168897c326f added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   412
    "return a float with value from digits after the decimal point.
5168897c326f added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   413
     (i.e. the receiver minus its truncated value)"
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   414
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   415
    ^ self - self truncated asFloat
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   416
1865
5168897c326f added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   417
    "
5168897c326f added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   418
     1234.56789 fractionPart
5168897c326f added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   419
     1.2345e6 fractionPart  
5168897c326f added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   420
    "
5168897c326f added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   421
5168897c326f added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   422
    "Modified: 4.11.1996 / 20:26:54 / cg"
5168897c326f added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   423
!
5168897c326f added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   424
5168897c326f added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   425
integerPart
5168897c326f added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   426
    "return a float with value from digits before the decimal point
5168897c326f added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   427
     (i.e. the truncated value)"
5168897c326f added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   428
5168897c326f added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   429
    ^ self truncated asFloat
5168897c326f added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   430
5168897c326f added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   431
    "
5168897c326f added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   432
     1234.56789 integerPart 
5168897c326f added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   433
     1.2345e6 integerPart   
5168897c326f added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   434
    "
5168897c326f added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   435
5168897c326f added integerPart for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   436
    "Modified: 4.11.1996 / 20:26:21 / cg"
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   437
! !
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   438
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   439
!LimitedPrecisionReal class methodsFor:'documentation'!
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   440
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
   441
version
2141
bba0027204fd added #asFixedPoint:
Claus Gittinger <cg@exept.de>
parents: 1893
diff changeset
   442
    ^ '$Header: /cvs/stx/stx/libbasic/LimitedPrecisionReal.st,v 1.18 1997-01-10 19:01:23 cg Exp $'
55
4a82f332c3f8 Initial revision
claus
parents:
diff changeset
   443
! !