author | Claus Gittinger <cg@exept.de> |
Wed, 24 Jul 2002 10:32:32 +0200 | |
changeset 6657 | a0fa5a821176 |
parent 6641 | e5d7486db101 |
child 6890 | 8e74eff54c3d |
permissions | -rw-r--r-- |
55 | 1 |
" |
2 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
213 | 3 |
All Rights Reserved |
55 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
5470
5e56d8cff0c9
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5357
diff
changeset
|
13 |
"{ Package: 'stx:libbasic' }" |
5e56d8cff0c9
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5357
diff
changeset
|
14 |
|
55 | 15 |
Number subclass:#LimitedPrecisionReal |
1200 | 16 |
instanceVariableNames:'' |
17 |
classVariableNames:'' |
|
18 |
poolDictionaries:'' |
|
19 |
category:'Magnitude-Numbers' |
|
55 | 20 |
! |
21 |
||
88 | 22 |
!LimitedPrecisionReal class methodsFor:'documentation'! |
23 |
||
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
213 | 27 |
All Rights Reserved |
55 | 28 |
|
88 | 29 |
This software is furnished under a license and may be used |
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
55 | 37 |
|
88 | 38 |
documentation |
39 |
" |
|
40 |
Abstract superclass for single and double (and maybe more) |
|
41 |
precision real numbers (i.e. Float and Double). |
|
92 | 42 |
|
43 |
Due to historic reasons, ST/X's Floats are what Doubles are in ST-80. |
|
44 |
This may change soon (implementing LPReal is a first step towards this). |
|
1295 | 45 |
|
46 |
[author:] |
|
47 |
Claus Gittinger |
|
1893 | 48 |
|
49 |
[see also:] |
|
50 |
Fraction FixedPoint |
|
88 | 51 |
" |
52 |
! ! |
|
55 | 53 |
|
5989
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
54 |
!LimitedPrecisionReal class methodsFor:'initialization'! |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
55 |
|
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
56 |
initialize |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
57 |
"initialize ANSI compliant float globals" |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
58 |
|
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
59 |
Smalltalk at:#FloatE put:ShortFloat. |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
60 |
Smalltalk at:#FloatD put:Float. |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
61 |
Smalltalk at:#FloatQ put:LongFloat. |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
62 |
|
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
63 |
" |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
64 |
self initialize |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
65 |
" |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
66 |
|
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
67 |
"Created: / 7.9.2001 / 14:02:45 / cg" |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
68 |
"Modified: / 7.9.2001 / 14:02:54 / cg" |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
69 |
! ! |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
70 |
|
55 | 71 |
!LimitedPrecisionReal class methodsFor:'instance creation'! |
72 |
||
73 |
new:aNumber |
|
74 |
"catch this message - not allowed for floats/doubles" |
|
75 |
||
76 |
self error:'Floats/Doubles cannot be created with new:' |
|
77 |
! ! |
|
78 |
||
5989
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
79 |
!LimitedPrecisionReal class methodsFor:'constants & defaults'! |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
80 |
|
6575
b07cd54c4375
Define #decimalPrecision, #epsilon
Stefan Vogel <sv@exept.de>
parents:
6195
diff
changeset
|
81 |
decimalPrecision |
b07cd54c4375
Define #decimalPrecision, #epsilon
Stefan Vogel <sv@exept.de>
parents:
6195
diff
changeset
|
82 |
"return the precision (the number of decimal digits)" |
b07cd54c4375
Define #decimalPrecision, #epsilon
Stefan Vogel <sv@exept.de>
parents:
6195
diff
changeset
|
83 |
|
b07cd54c4375
Define #decimalPrecision, #epsilon
Stefan Vogel <sv@exept.de>
parents:
6195
diff
changeset
|
84 |
^ (self precision / (10.0 log:self radix)) floor |
b07cd54c4375
Define #decimalPrecision, #epsilon
Stefan Vogel <sv@exept.de>
parents:
6195
diff
changeset
|
85 |
|
b07cd54c4375
Define #decimalPrecision, #epsilon
Stefan Vogel <sv@exept.de>
parents:
6195
diff
changeset
|
86 |
" |
b07cd54c4375
Define #decimalPrecision, #epsilon
Stefan Vogel <sv@exept.de>
parents:
6195
diff
changeset
|
87 |
Float decimalPrecision |
b07cd54c4375
Define #decimalPrecision, #epsilon
Stefan Vogel <sv@exept.de>
parents:
6195
diff
changeset
|
88 |
ShortFloat decimalPrecision |
b07cd54c4375
Define #decimalPrecision, #epsilon
Stefan Vogel <sv@exept.de>
parents:
6195
diff
changeset
|
89 |
" |
b07cd54c4375
Define #decimalPrecision, #epsilon
Stefan Vogel <sv@exept.de>
parents:
6195
diff
changeset
|
90 |
! |
b07cd54c4375
Define #decimalPrecision, #epsilon
Stefan Vogel <sv@exept.de>
parents:
6195
diff
changeset
|
91 |
|
5989
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
92 |
e |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
93 |
"return the closest approximation of the irrational number e" |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
94 |
|
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
95 |
self subclassResponsibility |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
96 |
|
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
97 |
"Modified: / 7.9.2001 / 14:05:02 / cg" |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
98 |
! |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
99 |
|
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
100 |
emax |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
101 |
"return the largest exponent" |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
102 |
|
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
103 |
self subclassResponsibility |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
104 |
|
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
105 |
"Created: / 7.9.2001 / 14:05:28 / cg" |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
106 |
! |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
107 |
|
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
108 |
emin |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
109 |
"return the smallest exponent" |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
110 |
|
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
111 |
self subclassResponsibility |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
112 |
|
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
113 |
"Created: / 7.9.2001 / 14:05:35 / cg" |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
114 |
! |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
115 |
|
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
116 |
epsilon |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
117 |
"return the maximum relative spacing" |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
118 |
|
6575
b07cd54c4375
Define #decimalPrecision, #epsilon
Stefan Vogel <sv@exept.de>
parents:
6195
diff
changeset
|
119 |
^ self radix asFloat raisedTo:(1 - self precision) |
b07cd54c4375
Define #decimalPrecision, #epsilon
Stefan Vogel <sv@exept.de>
parents:
6195
diff
changeset
|
120 |
|
b07cd54c4375
Define #decimalPrecision, #epsilon
Stefan Vogel <sv@exept.de>
parents:
6195
diff
changeset
|
121 |
" |
b07cd54c4375
Define #decimalPrecision, #epsilon
Stefan Vogel <sv@exept.de>
parents:
6195
diff
changeset
|
122 |
ShortFloat epsilon |
b07cd54c4375
Define #decimalPrecision, #epsilon
Stefan Vogel <sv@exept.de>
parents:
6195
diff
changeset
|
123 |
Float epsilon |
b07cd54c4375
Define #decimalPrecision, #epsilon
Stefan Vogel <sv@exept.de>
parents:
6195
diff
changeset
|
124 |
LongFloat epsilon |
b07cd54c4375
Define #decimalPrecision, #epsilon
Stefan Vogel <sv@exept.de>
parents:
6195
diff
changeset
|
125 |
" |
b07cd54c4375
Define #decimalPrecision, #epsilon
Stefan Vogel <sv@exept.de>
parents:
6195
diff
changeset
|
126 |
|
5989
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
127 |
|
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
128 |
"Created: / 7.9.2001 / 14:06:41 / cg" |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
129 |
! |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
130 |
|
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
131 |
fmax |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
132 |
"return the largest value allowed" |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
133 |
|
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
134 |
self subclassResponsibility |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
135 |
|
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
136 |
"Created: / 7.9.2001 / 14:06:56 / cg" |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
137 |
! |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
138 |
|
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
139 |
fmin |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
140 |
"return the minimum value allowed" |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
141 |
|
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
142 |
self subclassResponsibility |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
143 |
|
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
144 |
"Created: / 7.9.2001 / 14:07:06 / cg" |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
145 |
! |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
146 |
|
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
147 |
pi |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
148 |
"return the closest approximation of the irrational number e" |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
149 |
|
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
150 |
self subclassResponsibility |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
151 |
|
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
152 |
"Created: / 7.9.2001 / 14:07:35 / cg" |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
153 |
! |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
154 |
|
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
155 |
precision |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
156 |
"return the precision (the number of radix digits)" |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
157 |
|
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
158 |
self subclassResponsibility |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
159 |
|
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
160 |
"Created: / 7.9.2001 / 14:07:58 / cg" |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
161 |
! |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
162 |
|
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
163 |
radix |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
164 |
"return the radix (base)" |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
165 |
|
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
166 |
self subclassResponsibility |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
167 |
|
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
168 |
"Created: / 7.9.2001 / 14:08:20 / cg" |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
169 |
! ! |
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
170 |
|
55 | 171 |
!LimitedPrecisionReal methodsFor:'accessing'! |
172 |
||
173 |
at:index |
|
174 |
"redefined to prevent access to individual bytes in a real." |
|
175 |
||
176 |
self error:'not allowed for floats/doubles' |
|
177 |
! |
|
178 |
||
179 |
at:index put:aValue |
|
180 |
"redefined to prevent access to individual bytes in a real" |
|
181 |
||
182 |
self error:'not allowed for floats/doubles' |
|
183 |
! ! |
|
184 |
||
185 |
!LimitedPrecisionReal methodsFor:'arithmetic'! |
|
186 |
||
701 | 187 |
* aNumber |
188 |
"return the product of the receiver and the argument, aNumber" |
|
189 |
||
1200 | 190 |
"/ as soon as Float are float & Double are doubles, |
191 |
"/ use: |
|
192 |
"/ ^ aNumber productFromDouble:self asDouble |
|
193 |
||
194 |
^ aNumber productFromFloat:self asFloat |
|
195 |
||
196 |
"Modified: 17.4.1996 / 12:35:36 / cg" |
|
701 | 197 |
! |
198 |
||
55 | 199 |
+ aNumber |
200 |
"return the sum of the receiver and the argument, aNumber" |
|
201 |
||
1200 | 202 |
"/ as soon as Float are float & Double are doubles, |
203 |
"/ use: |
|
204 |
"/ ^ aNumber sumFromDouble:self asDouble |
|
205 |
||
206 |
^ aNumber sumFromFloat:self asFloat |
|
207 |
||
208 |
"Modified: 17.4.1996 / 12:35:55 / cg" |
|
55 | 209 |
! |
210 |
||
211 |
- aNumber |
|
212 |
"return the difference of the receiver and the argument, aNumber" |
|
213 |
||
1200 | 214 |
"/ as soon as Float are float & Double are doubles, |
215 |
"/ use: |
|
216 |
"/ ^ aNumber differenceFromDouble:self asDouble |
|
217 |
||
218 |
^ aNumber differenceFromFloat:self asFloat |
|
219 |
||
220 |
"Modified: 17.4.1996 / 12:36:07 / cg" |
|
55 | 221 |
! |
222 |
||
223 |
/ aNumber |
|
224 |
"return the quotient of the receiver and the argument, aNumber" |
|
225 |
||
226 |
((aNumber == 0) or:[aNumber = 0.0]) ifTrue:[ |
|
5954 | 227 |
^ DivisionByZeroSignal raiseRequestWith:thisContext. |
55 | 228 |
]. |
1200 | 229 |
"/ as soon as Float are float & Double are doubles, |
230 |
"/ use: |
|
231 |
"/ ^ aNumber quotientFromDouble:self asDouble |
|
232 |
||
233 |
^ aNumber quotientFromFloat:self asFloat |
|
234 |
||
4455
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
3898
diff
changeset
|
235 |
"Modified: / 17.4.1996 / 12:36:21 / cg" |
2d31d0d986be
Raise DivisionByZeroSignal proceedable (as in ST-80)!
Stefan Vogel <sv@exept.de>
parents:
3898
diff
changeset
|
236 |
"Modified: / 26.7.1999 / 10:46:11 / stefan" |
55 | 237 |
! |
238 |
||
239 |
// aNumber |
|
240 |
"return the integer quotient of dividing the receiver by aNumber with |
|
1882 | 241 |
truncation towards negative infinity." |
55 | 242 |
|
243 |
^ (self / aNumber) floor asInteger |
|
1882 | 244 |
|
245 |
"Modified: 5.11.1996 / 11:45:37 / cg" |
|
55 | 246 |
! ! |
247 |
||
5238 | 248 |
!LimitedPrecisionReal methodsFor:'coercing & converting'! |
55 | 249 |
|
2141 | 250 |
asFixedPoint |
251 |
"return the receiver as fixedPoint number. |
|
252 |
Q: what should the scale be here ?" |
|
253 |
||
254 |
^ self asFraction asFixedPoint |
|
255 |
||
256 |
" |
|
257 |
0.3 asFixedPoint |
|
258 |
0.5 asFixedPoint |
|
259 |
(1/5) asFloat asFixedPoint |
|
260 |
(1/3) asFloat asFixedPoint |
|
261 |
(2/3) asFloat asFixedPoint |
|
262 |
(1/8) asFloat asFixedPoint |
|
263 |
3.14159 asFixedPoint |
|
3060 | 264 |
0.0000001 asFraction |
265 |
0.0000001 asFixedPoint |
|
2141 | 266 |
" |
267 |
||
3060 | 268 |
"Modified: / 25.10.1997 / 15:36:54 / cg" |
2141 | 269 |
! |
270 |
||
271 |
asFixedPoint:scale |
|
272 |
"return the receiver as fixedPoint number with the given |
|
273 |
number of post-decimal-digits." |
|
274 |
||
275 |
^ self asFraction asFixedPoint:scale |
|
276 |
||
277 |
" |
|
3732 | 278 |
0.3 asFixedPoint:4 |
2141 | 279 |
0.3 asFixedPoint:3 |
3732 | 280 |
0.3 asFixedPoint:2 |
281 |
0.3 asFixedPoint:1 |
|
282 |
0.3 asFixedPoint:0 |
|
283 |
||
2141 | 284 |
0.5 asFixedPoint:3 |
285 |
(1/5) asFloat asFixedPoint:1 |
|
286 |
(1/8) asFloat asFixedPoint:1 |
|
6641 | 287 |
1.0 asFixedPoint:2 |
2141 | 288 |
3.14159 asFixedPoint:2 |
289 |
3.14159 asFixedPoint:3 |
|
290 |
(3.14159 asFixedPoint:2) asFixedPoint:5 |
|
291 |
" |
|
292 |
||
3732 | 293 |
"Modified: / 5.8.1998 / 13:29:51 / cg" |
2141 | 294 |
! |
295 |
||
55 | 296 |
asFraction |
5883 | 297 |
"Answer a rational number (Integer or Fraction) representing the receiver. |
298 |
This conversion uses the continued fraction method to approximate |
|
299 |
a floating point number." |
|
300 |
||
301 |
|num1 denom1 num2 denom2 int frac newD temp limit| |
|
55 | 302 |
|
5883 | 303 |
limit := (self class unity * 10) raisedTo:self defaultNumberOfDigits. |
304 |
num1 := self truncated. |
|
305 |
denom1 := 1. "The first of two alternating denominators" |
|
306 |
num2 := 1. "The second numerator" |
|
307 |
denom2 := 0. "The second denominator--will update" |
|
308 |
int := num1. "The integer part of self" |
|
309 |
frac := self fractionPart. |
|
310 |
[frac = 0] whileFalse:[ |
|
311 |
newD := 1.0 / frac. |
|
312 |
int := newD truncated. |
|
313 |
frac := newD fractionPart. "save the fractional part for next time" |
|
314 |
temp := num2. "old numerator and save it" |
|
315 |
num2 := num1. |
|
316 |
num1 := num1 * int + temp. "Update first numerator" |
|
317 |
temp := denom2. "old denominator and save it" |
|
318 |
denom2 := denom1. |
|
319 |
denom1 := int * denom1 + temp. "Update first denominator" |
|
320 |
limit < denom1 ifTrue:[ |
|
321 |
"Is ratio past float precision? If so, pick which of the two ratios to use" |
|
322 |
num2 = 0.0 ifTrue:[ |
|
323 |
"Is second denominator 0?" |
|
324 |
^ Fraction numerator:num1 denominator:denom1 |
|
325 |
]. |
|
326 |
^ Fraction numerator:num2 denominator:denom2 |
|
327 |
] |
|
3060 | 328 |
]. |
329 |
||
5883 | 330 |
"If fractional part is zero, return the first ratio" |
331 |
denom1 = 1 ifTrue:[ |
|
332 |
"Am i really an Integer?" |
|
333 |
^ num1 "Yes, return Integer result" |
|
3060 | 334 |
]. |
5883 | 335 |
"Otherwise return Fraction result" |
336 |
^ Fraction numerator:num1 denominator:denom1 |
|
55 | 337 |
|
3060 | 338 |
" |
5883 | 339 |
1.1 asFraction |
340 |
1.2 asFraction |
|
341 |
0.3 asFraction |
|
3060 | 342 |
0.5 asFraction |
343 |
(1/5) asFloat asFraction |
|
5883 | 344 |
(1/8) asFloat asFraction |
345 |
(1/13) asFloat asFraction |
|
346 |
3.14159 asFraction |
|
347 |
3.14159 asFraction asFloat |
|
348 |
1.3 asFraction |
|
349 |
1.0 asFraction |
|
3060 | 350 |
" |
2793 | 351 |
|
3060 | 352 |
"Modified: / 25.10.1997 / 16:41:19 / cg" |
55 | 353 |
! |
354 |
||
355 |
asInteger |
|
356 |
"return an integer with same value - might truncate" |
|
357 |
||
3185 | 358 |
|max maxF| |
55 | 359 |
|
2388 | 360 |
self isNaN ifTrue:[ |
3395
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3225
diff
changeset
|
361 |
^ self class |
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3225
diff
changeset
|
362 |
raise:#domainErrorSignal |
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3225
diff
changeset
|
363 |
receiver:self |
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3225
diff
changeset
|
364 |
selector:#asInteger |
6195 | 365 |
arguments:#() |
3395
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3225
diff
changeset
|
366 |
errorString:'receiver is NaN in #asInteger' |
02f47135d80f
pass messageSend as parameter to domainError exception
Claus Gittinger <cg@exept.de>
parents:
3225
diff
changeset
|
367 |
|
2388 | 368 |
]. |
369 |
||
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4455
diff
changeset
|
370 |
self abs < 2e16 ifTrue:[ |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4455
diff
changeset
|
371 |
"/ NOTICE: this must be redefined in float |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4455
diff
changeset
|
372 |
"/ subclasses to handle the smallinteger range; |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4455
diff
changeset
|
373 |
"/ i.e. this may only be invoked for reals |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4455
diff
changeset
|
374 |
"/ which are NOT within the smallInt range. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4455
diff
changeset
|
375 |
"/ otherwise, endless recursion is the consequence. |
3426 | 376 |
|
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4455
diff
changeset
|
377 |
max := SmallInteger maxVal // 2 + 1. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4455
diff
changeset
|
378 |
maxF := max asFloat. |
3426 | 379 |
|
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4455
diff
changeset
|
380 |
^ (self quo:maxF) * max + (self rem:maxF) truncated |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4455
diff
changeset
|
381 |
]. |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4455
diff
changeset
|
382 |
^ self asTrueFraction |
55 | 383 |
|
3137 | 384 |
" |
4615
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4455
diff
changeset
|
385 |
12345.0 asInteger |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4455
diff
changeset
|
386 |
1e15 asInteger |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4455
diff
changeset
|
387 |
1e33 asInteger asFloat |
e480d1e6090f
largFloat -> largeInt conversion fixed.
Claus Gittinger <cg@exept.de>
parents:
4455
diff
changeset
|
388 |
1e303 asInteger asFloat |
3137 | 389 |
" |
2388 | 390 |
|
6195 | 391 |
"Modified: / 16.11.2001 / 14:15:33 / cg" |
701 | 392 |
! |
393 |
||
5883 | 394 |
asRational |
395 |
"Answer a Rational number--Integer or Fraction--representing the receiver. |
|
396 |
Same as asFraction fro st-80 compatibility." |
|
397 |
||
398 |
^ self asFraction |
|
399 |
||
400 |
" |
|
401 |
1.1 asRational |
|
402 |
1.2 asRational |
|
403 |
0.3 asRational |
|
404 |
0.5 asRational |
|
405 |
(1/5) asFloat asRational |
|
406 |
(1/8) asFloat asRational |
|
407 |
(1/13) asFloat asRational |
|
408 |
3.14159 asRational |
|
409 |
3.14159 asRational asFloat |
|
410 |
1.3 asRational |
|
411 |
1.0 asRational |
|
412 |
" |
|
413 |
! |
|
414 |
||
701 | 415 |
coerce:aNumber |
416 |
"return aNumber converted into receivers type" |
|
417 |
||
1200 | 418 |
"/ as soon as Float are float & Double are doubles, |
419 |
"/ use: |
|
420 |
"/ ^ aNumber asDouble |
|
421 |
||
422 |
^ aNumber asFloat |
|
423 |
||
424 |
"Modified: 17.4.1996 / 12:36:46 / cg" |
|
701 | 425 |
! |
426 |
||
3898 | 427 |
fractionalPart |
428 |
"This has been renamed to #fractionPart for ST80 compatibility. |
|
429 |
||
430 |
extract the after-decimal fraction part. |
|
431 |
the floats value is |
|
432 |
float truncated + float fractionalPart" |
|
433 |
||
5868 | 434 |
<resource:#obsolete> |
435 |
||
3898 | 436 |
self obsoleteMethodWarning:'please use #fractionPart'. |
437 |
^ self fractionPart |
|
438 |
||
439 |
"Modified: / 28.10.1998 / 17:10:12 / cg" |
|
440 |
"Created: / 28.10.1998 / 17:10:32 / cg" |
|
441 |
! |
|
442 |
||
701 | 443 |
generality |
444 |
"return the generality value - see ArithmeticValue>>retry:coercing:" |
|
445 |
||
446 |
^ 80 |
|
447 |
! ! |
|
448 |
||
449 |
!LimitedPrecisionReal methodsFor:'comparing'! |
|
450 |
||
451 |
< aNumber |
|
452 |
"return true, if the argument is greater" |
|
453 |
||
1201
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
454 |
"/ 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
|
455 |
"/ use: |
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
456 |
"/ ^ aNumber lessFromDouble:self asDouble |
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
457 |
|
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
458 |
^ aNumber lessFromFloat:self asFloat |
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
459 |
|
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
460 |
"Modified: 17.4.1996 / 13:34:50 / cg" |
701 | 461 |
! |
462 |
||
463 |
<= aNumber |
|
464 |
"return true, if the argument is greater or equal" |
|
465 |
||
466 |
^ self retry:#<= coercing:aNumber |
|
467 |
! |
|
468 |
||
469 |
= aNumber |
|
470 |
"return true, if the arguments value are equal" |
|
471 |
||
472 |
^ self retry:#= coercing:aNumber |
|
473 |
! |
|
474 |
||
475 |
> aNumber |
|
476 |
"return true, if the argument is less" |
|
477 |
||
478 |
^ self retry:#> coercing:aNumber |
|
479 |
! |
|
480 |
||
481 |
>= aNumber |
|
482 |
"return true, if the argument is less or equal" |
|
483 |
||
484 |
^ self retry:#>= coercing:aNumber |
|
485 |
! |
|
486 |
||
487 |
~= aNumber |
|
488 |
"return true, if the arguments value are not equal" |
|
489 |
||
490 |
^ self retry:#~= coercing:aNumber |
|
491 |
! ! |
|
492 |
||
493 |
!LimitedPrecisionReal methodsFor:'copying'! |
|
494 |
||
495 |
deepCopy |
|
496 |
"return a deep copy of myself |
|
497 |
- because storing into floats is not recommended/allowed, its ok to return the receiver" |
|
498 |
||
499 |
^ self |
|
500 |
! |
|
501 |
||
502 |
deepCopyUsing:aDictionary |
|
503 |
"return a deep copy of myself |
|
504 |
- because storing into floats is not recommended/allowed, its ok to return the receiver" |
|
505 |
||
506 |
^ self |
|
507 |
! |
|
508 |
||
509 |
shallowCopy |
|
510 |
"return a shallow copy of the receiver" |
|
511 |
||
512 |
^ self |
|
513 |
! |
|
514 |
||
515 |
simpleDeepCopy |
|
516 |
"return a deep copy of the receiver |
|
517 |
- because storing into floats is not recommended/allowed, its ok to return the receiver" |
|
518 |
||
519 |
^ self |
|
55 | 520 |
! ! |
521 |
||
522 |
!LimitedPrecisionReal methodsFor:'double dispatching'! |
|
523 |
||
524 |
differenceFromFraction:aFraction |
|
213 | 525 |
"sent when a fraction does not know how to subtract the receiver, a float" |
55 | 526 |
|
527 |
|d| |
|
528 |
||
529 |
d := aFraction denominator. |
|
530 |
^ (aFraction numerator - (self * d)) / d |
|
531 |
! |
|
532 |
||
533 |
productFromFraction:aFraction |
|
213 | 534 |
"sent when a fraction does not know how to multiply the receiver, a float" |
55 | 535 |
|
536 |
^ self * aFraction numerator / aFraction denominator |
|
537 |
! |
|
538 |
||
539 |
quotientFromFraction:aFraction |
|
213 | 540 |
"sent when a fraction does not know how to divide by the receiver, a float" |
55 | 541 |
|
542 |
^ aFraction numerator / (self * aFraction denominator) |
|
701 | 543 |
! |
544 |
||
545 |
sumFromFraction:aFraction |
|
546 |
"sent when a fraction does not know how to add the receiver, a float" |
|
547 |
||
548 |
|d| |
|
549 |
||
550 |
d := aFraction denominator. |
|
551 |
^ (self * d + aFraction numerator) / d |
|
552 |
! ! |
|
553 |
||
5470
5e56d8cff0c9
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5357
diff
changeset
|
554 |
!LimitedPrecisionReal methodsFor:'encoding'! |
5e56d8cff0c9
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5357
diff
changeset
|
555 |
|
5e56d8cff0c9
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5357
diff
changeset
|
556 |
encodeOn:anEncoder with:aParameter |
5e56d8cff0c9
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5357
diff
changeset
|
557 |
|
5e56d8cff0c9
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5357
diff
changeset
|
558 |
anEncoder encodeFloat:self with:aParameter |
5e56d8cff0c9
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5357
diff
changeset
|
559 |
|
5e56d8cff0c9
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5357
diff
changeset
|
560 |
|
5e56d8cff0c9
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5357
diff
changeset
|
561 |
! ! |
5e56d8cff0c9
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5357
diff
changeset
|
562 |
|
701 | 563 |
!LimitedPrecisionReal methodsFor:'printing & storing'! |
564 |
||
565 |
printOn:aStream |
|
566 |
"append a printed representation of the receiver to |
|
3194
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
567 |
the argument, aStream. |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
568 |
|
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
569 |
LimitedPrecisonReal and its subclasses use #printString instead of |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
570 |
#printOn: as basic print mechanism." |
701 | 571 |
|
572 |
aStream nextPutAll:self printString |
|
3194
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
573 |
|
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
574 |
"Modified: / 20.1.1998 / 14:10:46 / stefan" |
1200 | 575 |
! |
576 |
||
577 |
printString |
|
3194
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
578 |
"return a printed representation of the receiver |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
579 |
LimitedPrecisonReal and its subclasses use #printString instead of |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
580 |
#printOn: as basic print mechanism." |
1200 | 581 |
|
582 |
^ self subclassResponsibility |
|
583 |
||
3194
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
584 |
"Created: / 17.4.1996 / 12:12:20 / cg" |
16073834a825
Add comment about #printOn: and #printString
Stefan Vogel <sv@exept.de>
parents:
3185
diff
changeset
|
585 |
"Modified: / 20.1.1998 / 14:10:47 / stefan" |
701 | 586 |
! ! |
587 |
||
5557 | 588 |
!LimitedPrecisionReal methodsFor:'queries'! |
589 |
||
5883 | 590 |
defaultNumberOfDigits |
591 |
self subclassResponsibility |
|
592 |
! |
|
593 |
||
5557 | 594 |
size |
595 |
"redefined since reals are kludgy (ByteArry)" |
|
596 |
||
597 |
^ 0 |
|
598 |
! ! |
|
5470
5e56d8cff0c9
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5357
diff
changeset
|
599 |
|
701 | 600 |
!LimitedPrecisionReal methodsFor:'testing'! |
601 |
||
3148
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
602 |
isFinite |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
603 |
^ self subclassResponsibility |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
604 |
|
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
605 |
"Created: / 7.1.1998 / 12:02:06 / stefan" |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
606 |
! |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
607 |
|
6185 | 608 |
isFloat |
609 |
"return true, if the receiver is some kind of floating point number; |
|
610 |
false is returned here. |
|
611 |
Same as #isLimitedPrecisionReal, but a better name ;-)" |
|
612 |
||
613 |
^ true |
|
614 |
||
615 |
"Created: / 14.11.2001 / 14:57:55 / cg" |
|
616 |
! |
|
617 |
||
3148
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
618 |
isInfinite |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
619 |
"return true, if the receiver is an infinite float (Inf). |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
620 |
These are not created by ST/X float operations (they raise an exception); |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
621 |
however, inline C-code could produce them ..." |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
622 |
|
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
623 |
^ (self isFinite or:[self isNaN]) not. |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
624 |
|
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
625 |
" |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
626 |
1.0 isInfinite |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
627 |
(0.0 uncheckedDivide: 0.0) isInfinite |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
628 |
(1.0 uncheckedDivide: 0.0) isInfinite |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
629 |
" |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
630 |
|
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
631 |
"Modified: / 7.1.1998 / 12:01:30 / stefan" |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
632 |
! |
1434542209e7
New #finite, define #isInfinite using #finite.
Stefan Vogel <sv@exept.de>
parents:
3137
diff
changeset
|
633 |
|
6086
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
5989
diff
changeset
|
634 |
isLimitedPrecisionReal |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
5989
diff
changeset
|
635 |
"return true, if the receiver is some kind of limited precision real (i.e. floating point) number; |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
5989
diff
changeset
|
636 |
true is returned here - the method is redefined from Object." |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
5989
diff
changeset
|
637 |
|
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
5989
diff
changeset
|
638 |
^ true |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
5989
diff
changeset
|
639 |
! |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
5989
diff
changeset
|
640 |
|
2388 | 641 |
isNaN |
642 |
^ self subclassResponsibility |
|
643 |
||
644 |
"Modified: 12.2.1997 / 16:45:27 / cg" |
|
645 |
! |
|
646 |
||
701 | 647 |
negative |
648 |
"return true if the receiver is less than zero" |
|
649 |
||
1201
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
650 |
"/ 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
|
651 |
"/ use: |
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
652 |
"/ ^ self asDouble negative |
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
653 |
|
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
654 |
^ self asFloat negative |
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
655 |
|
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
656 |
"Modified: 17.4.1996 / 13:35:00 / cg" |
701 | 657 |
! |
658 |
||
5357 | 659 |
numberOfBits |
660 |
"return the size (in bits) of the real; |
|
661 |
typically, this is 64 for Floats and 32 for ShortFloats, |
|
662 |
but who knows ..." |
|
663 |
||
664 |
self subclassResponsibility |
|
665 |
! |
|
666 |
||
701 | 667 |
positive |
668 |
"return true if the receiver is greater or equal to zero" |
|
669 |
||
1201
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
670 |
"/ 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
|
671 |
"/ use: |
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
672 |
"/ ^ self asDouble positive |
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
673 |
|
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
674 |
^ self asFloat positive |
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
675 |
|
24a5faa7e305
oops - asDouble is not yet there
Claus Gittinger <cg@exept.de>
parents:
1200
diff
changeset
|
676 |
"Modified: 17.4.1996 / 13:35:10 / cg" |
55 | 677 |
! ! |
678 |
||
701 | 679 |
!LimitedPrecisionReal class methodsFor:'documentation'! |
55 | 680 |
|
701 | 681 |
version |
6641 | 682 |
^ '$Header: /cvs/stx/stx/libbasic/LimitedPrecisionReal.st,v 1.45 2002-07-16 13:22:02 cg Exp $' |
55 | 683 |
! ! |
5989
8e3ff880f561
ANSI preparations (incomplete)
Claus Gittinger <cg@exept.de>
parents:
5954
diff
changeset
|
684 |
LimitedPrecisionReal initialize! |