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