author | Claus Gittinger <cg@exept.de> |
Tue, 25 Feb 2020 17:19:49 +0100 | |
changeset 2586 | 7dc7be5a6f3d |
parent 2501 | 6ac1abaea8bc |
permissions | -rw-r--r-- |
1447 | 1 |
"{ Package: 'stx:goodies/regression' }" |
192 | 2 |
|
3 |
"{ NameSpace: RegressionTests }" |
|
4 |
||
5 |
TestCase subclass:#FloatTest |
|
263 | 6 |
instanceVariableNames:'' |
7 |
classVariableNames:'' |
|
8 |
poolDictionaries:'' |
|
1067 | 9 |
category:'tests-Regression-Numbers' |
192 | 10 |
! |
11 |
||
12 |
||
1969 | 13 |
!FloatTest class methodsFor:'helpers'! |
194 | 14 |
|
15 |
actualPrecisionOf:aFloatClass |
|
16 |
"get the actual number of valid bits in the mantissa. |
|
17 |
This does a real test (i.e. does not believe the compiled-in ifdefs)" |
|
18 |
||
1969 | 19 |
|one x count| |
20 |
||
194 | 21 |
one := aFloatClass unity. "/ 1.0 in this class |
1447 | 22 |
x := one. |
194 | 23 |
count := 0. |
1447 | 24 |
|
662 | 25 |
[one + x > one] whileTrue:[ |
1969 | 26 |
x := x / 2. |
27 |
count := count + 1. |
|
194 | 28 |
]. |
29 |
^ count |
|
30 |
||
31 |
" |
|
1969 | 32 |
self actualPrecisionOf:ShortFloat |
33 |
self actualPrecisionOf:Float |
|
34 |
self actualPrecisionOf:LongFloat |
|
194 | 35 |
" |
36 |
! ! |
|
37 |
||
192 | 38 |
!FloatTest methodsFor:'tests'! |
39 |
||
194 | 40 |
test00_Precision |
41 |
"computed precision vs. assumed precision." |
|
42 |
||
665 | 43 |
|a b| |
44 |
||
1969 | 45 |
self assert:( (a := Float precision) = (b := self class actualPrecisionOf:Float)) |
46 |
description:('Float precision: %1 ~~ actual: %2' bindWith:a with:b). |
|
47 |
self assert:( (a := ShortFloat precision) = (b := self class actualPrecisionOf:ShortFloat)) |
|
48 |
description:('ShortFloat precision: %1 ~~ actual: %2' bindWith:a with:b). |
|
49 |
self assert:( (a := LongFloat precision) = (b := self class actualPrecisionOf:LongFloat)) |
|
50 |
description:('LongFloat precision: %1 ~~ actual: %2' bindWith:a with:b). |
|
194 | 51 |
|
2420 | 52 |
"/ verify IEEE values |
53 |
self assert:(Float emin == -1022). |
|
54 |
self assert:(Float emax == 1023). |
|
55 |
self assert:(Float eBias == 1023). |
|
2430 | 56 |
"/ self assert:(Float fmin = (2.0 raisedTo:-1023)). "/ 2.2250738585072E-308). |
57 |
"/ self assert:(Float fmax == (2.0 raisedTo:1022)). |
|
2420 | 58 |
|
59 |
self assert:(ShortFloat emin == -126). |
|
60 |
self assert:(ShortFloat emax == 127). |
|
61 |
self assert:(ShortFloat eBias == 127). |
|
62 |
||
63 |
self assert:(HalfFloat emin == -14). |
|
64 |
self assert:(HalfFloat emax == 15). |
|
65 |
self assert:(HalfFloat eBias == 15). |
|
66 |
||
67 |
self assert:(LongFloat emin == -16382). |
|
68 |
self assert:(LongFloat emax == 16383). |
|
69 |
self assert:(LongFloat eBias == 16383). |
|
70 |
||
71 |
self assert:(QuadFloat emin == -16382). |
|
72 |
self assert:(QuadFloat emax == 16383). |
|
73 |
self assert:(QuadFloat eBias == 16383). |
|
74 |
||
75 |
self assert:(OctaFloat emin == -262142). |
|
76 |
self assert:(OctaFloat emax == 262143). |
|
77 |
self assert:(OctaFloat eBias == 262143). |
|
78 |
||
79 |
self assert:(QDouble emin == Float emin). |
|
80 |
self assert:(QDouble emax == Float emax). |
|
81 |
self assert:(QDouble eBias == Float eBias). |
|
82 |
||
194 | 83 |
" |
84 |
self basicNew test00_Precision |
|
85 |
" |
|
665 | 86 |
|
87 |
"Modified: / 03-05-2012 / 18:47:21 / cg" |
|
194 | 88 |
! |
89 |
||
192 | 90 |
test01_Nan |
91 |
"NaN in all avaliable formats." |
|
92 |
||
199 | 93 |
|shouldBeFloatNaN shouldBeLongFloatNaN shouldBeShortFloatNaN| |
192 | 94 |
|
199 | 95 |
shouldBeFloatNaN := 0.0 uncheckedDivide: 0.0. |
96 |
self assert:( shouldBeFloatNaN isMemberOf:Float ). |
|
97 |
self assert:( shouldBeFloatNaN isNaN ). |
|
98 |
self assert:( shouldBeFloatNaN isFinite not ). |
|
192 | 99 |
|
199 | 100 |
shouldBeShortFloatNaN := 0.0 asShortFloat uncheckedDivide: 0.0 asShortFloat. |
101 |
self assert:( shouldBeShortFloatNaN isMemberOf:ShortFloat ). |
|
102 |
self assert:( shouldBeShortFloatNaN isNaN ). |
|
103 |
self assert:( shouldBeShortFloatNaN isFinite not ). |
|
192 | 104 |
|
199 | 105 |
shouldBeLongFloatNaN := 0.0 asLongFloat uncheckedDivide: 0.0 asLongFloat. |
106 |
self assert:( shouldBeLongFloatNaN isMemberOf:LongFloat ). |
|
107 |
self assert:( shouldBeLongFloatNaN isNaN ). |
|
108 |
self assert:( shouldBeLongFloatNaN isFinite not ). |
|
192 | 109 |
|
199 | 110 |
shouldBeFloatNaN := 0.0 uncheckedDivide: 0.0. |
111 |
self assert:( shouldBeFloatNaN asShortFloat isNaN ). |
|
112 |
self assert:( shouldBeFloatNaN asLongFloat isNaN ). |
|
192 | 113 |
|
199 | 114 |
shouldBeShortFloatNaN := 0.0 asShortFloat uncheckedDivide: 0.0. |
115 |
self assert:( shouldBeShortFloatNaN asFloat isNaN ). |
|
116 |
self assert:( shouldBeShortFloatNaN asLongFloat isNaN ). |
|
192 | 117 |
|
199 | 118 |
shouldBeLongFloatNaN := 0.0 asLongFloat uncheckedDivide: 0.0. |
119 |
self assert:( shouldBeLongFloatNaN asShortFloat isNaN ). |
|
120 |
self assert:( shouldBeLongFloatNaN asLongFloat isNaN ). |
|
121 |
||
122 |
shouldBeFloatNaN := 0.0 uncheckedDivide: 0.0. |
|
123 |
self should:[ shouldBeFloatNaN asInteger ] raise:DomainError. |
|
192 | 124 |
|
199 | 125 |
"/ mhmh - the following are not true (they silently return NaNs). |
126 |
"/ self should:[ shouldBeFloatNaN + 1 ] raise:DomainError. |
|
127 |
"/ self should:[ shouldBeFloatNaN + 1.0 ] raise:DomainError. |
|
128 |
"/ self should:[ shouldBeFloatNaN + 1.0 asShortFloat ] raise:DomainError. |
|
129 |
"/ self should:[ shouldBeFloatNaN + 1.0 asLongFloat ] raise:DomainError. |
|
192 | 130 |
"/ |
199 | 131 |
"/ self should:[ shouldBeFloatNaN - 1 ] raise:DomainError. |
132 |
"/ self should:[ shouldBeFloatNaN - 1.0 ] raise:DomainError. |
|
133 |
"/ self should:[ shouldBeFloatNaN - 1.0 asShortFloat ] raise:DomainError. |
|
134 |
"/ self should:[ shouldBeFloatNaN - 1.0 asLongFloat ] raise:DomainError. |
|
192 | 135 |
|
136 |
"/ but these are: |
|
199 | 137 |
self assert:( shouldBeFloatNaN + 1 ) isNaN. |
138 |
self assert:( shouldBeFloatNaN + 1.0 ) isNaN. |
|
139 |
self assert:( shouldBeFloatNaN + 1.0 asShortFloat ) isNaN. |
|
140 |
self assert:( shouldBeFloatNaN + 1.0 asLongFloat ) isNaN. |
|
141 |
||
142 |
self assert:( shouldBeFloatNaN - 1 ) isNaN. |
|
143 |
self assert:( shouldBeFloatNaN - 1.0 ) isNaN. |
|
144 |
self assert:( shouldBeFloatNaN - 1.0 asShortFloat ) isNaN. |
|
145 |
self assert:( shouldBeFloatNaN - 1.0 asLongFloat ) isNaN. |
|
146 |
||
147 |
||
148 |
shouldBeShortFloatNaN := 0.0 asShortFloat uncheckedDivide: 0.0. |
|
149 |
self should:[ shouldBeShortFloatNaN asInteger ] raise:DomainError. |
|
192 | 150 |
|
199 | 151 |
self assert:( shouldBeShortFloatNaN + 1 ) isNaN. |
152 |
self assert:( shouldBeShortFloatNaN + 1.0 ) isNaN. |
|
153 |
self assert:( shouldBeShortFloatNaN + 1.0 asShortFloat ) isNaN. |
|
154 |
self assert:( shouldBeShortFloatNaN + 1.0 asLongFloat ) isNaN. |
|
155 |
||
156 |
self assert:( shouldBeShortFloatNaN - 1 ) isNaN. |
|
157 |
self assert:( shouldBeShortFloatNaN - 1.0 ) isNaN. |
|
158 |
self assert:( shouldBeShortFloatNaN - 1.0 asShortFloat ) isNaN. |
|
159 |
self assert:( shouldBeShortFloatNaN - 1.0 asLongFloat ) isNaN. |
|
160 |
||
161 |
shouldBeLongFloatNaN := 0.0 asLongFloat uncheckedDivide: 0.0. |
|
162 |
self should:[ shouldBeLongFloatNaN asInteger ] raise:DomainError. |
|
163 |
||
164 |
self assert:( shouldBeLongFloatNaN + 1 ) isNaN. |
|
165 |
self assert:( shouldBeLongFloatNaN + 1.0 ) isNaN. |
|
166 |
self assert:( shouldBeLongFloatNaN + 1.0 asShortFloat ) isNaN. |
|
167 |
self assert:( shouldBeLongFloatNaN + 1.0 asLongFloat ) isNaN. |
|
168 |
||
169 |
self assert:( shouldBeLongFloatNaN - 1 ) isNaN. |
|
170 |
self assert:( shouldBeLongFloatNaN - 1.0 ) isNaN. |
|
171 |
self assert:( shouldBeLongFloatNaN - 1.0 asShortFloat ) isNaN. |
|
172 |
self assert:( shouldBeLongFloatNaN - 1.0 asLongFloat ) isNaN. |
|
192 | 173 |
|
1621 | 174 |
shouldBeFloatNaN := Float NaN. |
175 |
self assert:( shouldBeFloatNaN isMemberOf:Float ). |
|
176 |
self assert:( shouldBeFloatNaN isNaN ). |
|
177 |
self assert:( shouldBeFloatNaN isFinite not ). |
|
178 |
||
179 |
shouldBeShortFloatNaN := ShortFloat NaN. |
|
180 |
self assert:( shouldBeShortFloatNaN isMemberOf:ShortFloat ). |
|
181 |
self assert:( shouldBeShortFloatNaN isNaN ). |
|
182 |
self assert:( shouldBeShortFloatNaN isFinite not ). |
|
183 |
||
184 |
shouldBeLongFloatNaN := LongFloat NaN. |
|
185 |
self assert:( shouldBeLongFloatNaN isMemberOf:LongFloat ). |
|
186 |
self assert:( shouldBeLongFloatNaN isNaN ). |
|
187 |
self assert:( shouldBeLongFloatNaN isFinite not ). |
|
188 |
||
192 | 189 |
" |
190 |
self basicNew test01_Nan |
|
191 |
" |
|
1621 | 192 |
|
193 |
"Modified: / 20-06-2017 / 14:00:08 / cg" |
|
192 | 194 |
! |
195 |
||
196 |
test02_Inf |
|
197 |
"Infinity in all avaliable formats." |
|
198 |
||
203 | 199 |
|check posInf negInf| |
192 | 200 |
|
1447 | 201 |
check := |
1621 | 202 |
[:v1 :v2 | |
192 | 203 |
|
1621 | 204 |
posInf := v1 uncheckedDivide: v2. |
192 | 205 |
|
1621 | 206 |
self assert:( posInf isMemberOf:v1 class ). |
207 |
self assert:( posInf isNaN not ). |
|
208 |
self assert:( posInf isFinite not ). |
|
209 |
self assert:( posInf isInfinite ). |
|
210 |
self assert:( posInf positive ). |
|
211 |
self assert:( posInf negative not ). |
|
212 |
self assert:( posInf isNegativeInfinity not). |
|
213 |
self assert:( posInf isPositiveInfinity ). |
|
203 | 214 |
|
1621 | 215 |
negInf := v1 negated uncheckedDivide: v2. |
192 | 216 |
|
1621 | 217 |
self assert:( negInf isMemberOf:v1 class ). |
218 |
self assert:( negInf isNaN not ). |
|
219 |
self assert:( negInf isFinite not ). |
|
220 |
self assert:( negInf isInfinite ). |
|
221 |
self assert:( negInf positive not). |
|
222 |
self assert:( negInf negative ). |
|
223 |
self assert:( negInf isNegativeInfinity ). |
|
224 |
self assert:( negInf isPositiveInfinity not ). |
|
192 | 225 |
|
1621 | 226 |
self assert:( negInf + negInf = negInf). |
227 |
self assert:( posInf + posInf = posInf). |
|
228 |
self assert:( negInf + posInf) isNaN. |
|
229 |
self assert:( posInf + negInf) isNaN. |
|
203 | 230 |
|
1621 | 231 |
self assert:( negInf - posInf = negInf). |
232 |
self assert:( negInf - negInf) isNaN. |
|
233 |
self assert:( posInf - negInf = posInf). |
|
234 |
self assert:( posInf - posInf) isNaN. |
|
203 | 235 |
|
1621 | 236 |
self assert:( posInf + v1) = posInf. |
237 |
self assert:( posInf - v1) = posInf. |
|
238 |
self assert:( negInf + v1) = negInf. |
|
239 |
self assert:( negInf - v1) = negInf. |
|
240 |
]. |
|
192 | 241 |
|
242 |
check value: 1.0 value: 0.0. |
|
243 |
check value: 1.0 asShortFloat value: 0.0 asShortFloat. |
|
244 |
check value: 1.0 asLongFloat value: 0.0 asLongFloat. |
|
245 |
||
246 |
"/ these are not guaranteed to work with uncheckedDivide... |
|
247 |
"/ check value: 1.0 value: 0.0 asShortFloat. |
|
248 |
"/ check value: 1.0 value: 0.0 asLongFloat. |
|
249 |
"/ |
|
250 |
"/ check value: 1.0 asShortFloat value: 0.0. |
|
251 |
"/ check value: 1.0 asShortFloat value: 0.0 asLongFloat. |
|
252 |
"/ |
|
253 |
"/ check value: 1.0 asLongFloat value: 0.0 asShortFloat. |
|
254 |
"/ check value: 1.0 asLongFloat value: 0.0. |
|
255 |
||
1621 | 256 |
{ Float . ShortFloat . LongFloat } |
257 |
do:[:cls | |
|
258 |
posInf := cls infinity. |
|
259 |
self assert:( posInf isInfinite ). |
|
260 |
self assert:( posInf isFinite not ). |
|
261 |
self assert:( posInf > 0 ). |
|
262 |
self assert:( posInf >= 0 ). |
|
263 |
self assert:( posInf < 0 ) not. |
|
264 |
self assert:( posInf <= 0 ) not. |
|
265 |
||
266 |
negInf := cls negativeInfinity. |
|
267 |
self assert:( negInf isInfinite ). |
|
268 |
self assert:( negInf isFinite not ). |
|
269 |
self assert:( negInf < 0 ). |
|
270 |
self assert:( negInf <= 0 ). |
|
271 |
self assert:( negInf > 0 ) not. |
|
272 |
self assert:( negInf >= 0 ) not. |
|
2309 | 273 |
|
274 |
self assert:(posInf isNaN not). |
|
275 |
self assert:(posInf isFinite not). |
|
276 |
self assert:(posInf isInfinite). |
|
277 |
||
278 |
self assert:(negInf isNaN not). |
|
279 |
self assert:(negInf isFinite not). |
|
280 |
self assert:(negInf isInfinite). |
|
281 |
||
282 |
self assert:(posInf negated = negInf). |
|
283 |
self assert:(negInf negated = posInf). |
|
284 |
||
1621 | 285 |
]. |
286 |
||
192 | 287 |
" |
288 |
self basicNew test02_Inf |
|
289 |
" |
|
1621 | 290 |
|
291 |
"Modified: / 20-06-2017 / 14:03:08 / cg" |
|
2309 | 292 |
"Modified: / 10-06-2019 / 23:45:05 / Claus Gittinger" |
192 | 293 |
! |
294 |
||
295 |
test03_Conversion |
|
296 |
self assert:( 1.0 asTrueFraction == 1 ). |
|
297 |
self assert:( 2.0 asTrueFraction == 2 ). |
|
298 |
self assert:( 4.0 asTrueFraction == 4 ). |
|
299 |
self assert:( 8.0 asTrueFraction == 8 ). |
|
300 |
self assert:( 16.0 asTrueFraction == 16 ). |
|
301 |
self assert:( 1048576.0 asTrueFraction == 1048576 ). |
|
302 |
self assert:( 0.5 asTrueFraction = (1/2) ). |
|
303 |
self assert:( 0.25 asTrueFraction = (1/4) ). |
|
304 |
self assert:( 0.125 asTrueFraction = (1/8) ). |
|
305 |
||
306 |
self assert:( 1.0 asShortFloat asTrueFraction == 1 ). |
|
307 |
self assert:( 2.0 asShortFloat asTrueFraction == 2 ). |
|
308 |
self assert:( 4.0 asShortFloat asTrueFraction == 4 ). |
|
309 |
self assert:( 8.0 asShortFloat asTrueFraction == 8 ). |
|
310 |
self assert:( 16.0 asShortFloat asTrueFraction == 16 ). |
|
311 |
self assert:( 1048576.0 asShortFloat asTrueFraction == 1048576 ). |
|
312 |
self assert:( 0.5 asShortFloat asTrueFraction = (1/2) ). |
|
313 |
self assert:( 0.25 asShortFloat asTrueFraction = (1/4) ). |
|
314 |
self assert:( 0.125 asShortFloat asTrueFraction = (1/8) ). |
|
315 |
||
316 |
self assert:( 1.0 asLongFloat asTrueFraction == 1 ). |
|
317 |
self assert:( 2.0 asLongFloat asTrueFraction == 2 ). |
|
318 |
self assert:( 4.0 asLongFloat asTrueFraction == 4 ). |
|
319 |
self assert:( 8.0 asLongFloat asTrueFraction == 8 ). |
|
320 |
self assert:( 16.0 asLongFloat asTrueFraction == 16 ). |
|
321 |
self assert:( 1048576.0 asLongFloat asTrueFraction == 1048576 ). |
|
322 |
self assert:( 0.5 asLongFloat asTrueFraction = (1/2) ). |
|
323 |
self assert:( 0.25 asLongFloat asTrueFraction = (1/4) ). |
|
324 |
self assert:( 0.125 asLongFloat asTrueFraction = (1/8) ). |
|
325 |
||
203 | 326 |
self assert: ((5/9) asFloat - 0.555555555555) abs < 0.0000000001. |
327 |
self assert: ((5/9) asLongFloat - 0.555555555555) abs < 0.0000000001. |
|
328 |
self assert: ((Fraction basicNew setNumerator:500000000000 denominator:900000000000) |
|
1447 | 329 |
asLongFloat - 0.555555555555) abs < 0.000000000001. |
203 | 330 |
self assert: ((Fraction basicNew setNumerator:500000000001 denominator:900000000000) |
1447 | 331 |
asLongFloat - 0.555555555555) abs >= 0.000000000001. |
203 | 332 |
|
621 | 333 |
"/ under windows, a longFloat has only 10bytes with 64 bits precision |
334 |
OperatingSystem isMSWINDOWSlike ifFalse:[ |
|
1447 | 335 |
self assert: (8901234567890123456 asLongFloat asInteger = 8901234567890123456). |
336 |
self assert: (-8901234567890123456 asLongFloat asInteger = -8901234567890123456). |
|
621 | 337 |
]. |
1447 | 338 |
self assert: (89012345678901234567 asLongFloat = 89012345678901234567). |
203 | 339 |
self assert: (-89012345678901234567 asLongFloat = -89012345678901234567). |
340 |
self assert: (89012345678901234567 negated asLongFloat = -89012345678901234567). |
|
341 |
||
342 |
self assert: ((89012345678901234567 / 123456789123456789) asLongFloat - (89012345678901234567 asLongFloat / 123456789123456789 asLongFloat) ) abs < 0.000000000001. |
|
343 |
self assert: ((-89012345678901234567 / 123456789123456789) asLongFloat - (-89012345678901234567 asLongFloat / 123456789123456789 asLongFloat)) abs < 0.000000000001. |
|
344 |
||
192 | 345 |
" |
346 |
self basicNew test03_Conversion |
|
347 |
" |
|
621 | 348 |
|
349 |
"Modified: / 09-08-2011 / 21:01:57 / cg" |
|
192 | 350 |
! |
351 |
||
352 |
test04_Arithmetic |
|
353 |
self assert:( 1.0 + 1.0 ) class == Float. |
|
354 |
self assert:( 1.0 + 1.0 asShortFloat) class == Float. |
|
355 |
self assert:( 1.0 + 1.0 asLongFloat) class == LongFloat. |
|
356 |
self assert:( 1.0 + 1) class == Float. |
|
357 |
||
358 |
self assert:( 1.0 asShortFloat + 1.0 ) class == Float. |
|
359 |
self assert:( 1.0 asShortFloat + 1.0 asShortFloat) class == ShortFloat. |
|
360 |
self assert:( 1.0 asShortFloat + 1.0 asLongFloat) class == LongFloat. |
|
361 |
self assert:( 1.0 asShortFloat + 1) class == ShortFloat. |
|
362 |
||
363 |
self assert:( 1.0 asLongFloat + 1.0 ) class == LongFloat. |
|
364 |
self assert:( 1.0 asLongFloat + 1.0 asShortFloat ) class == LongFloat. |
|
365 |
self assert:( 1.0 asLongFloat + 1.0 asFloat ) class == LongFloat. |
|
366 |
self assert:( 1.0 asLongFloat + 1 ) class == LongFloat. |
|
367 |
||
368 |
||
369 |
self assert:( 1.0 - 1.0 ) class == Float. |
|
370 |
self assert:( 1.0 - 1.0 asShortFloat) class == Float. |
|
371 |
self assert:( 1.0 - 1.0 asLongFloat) class == LongFloat. |
|
372 |
self assert:( 1.0 - 1) class == Float. |
|
373 |
||
374 |
self assert:( 1.0 asShortFloat - 1.0 ) class == Float. |
|
375 |
self assert:( 1.0 asShortFloat - 1.0 asShortFloat) class == ShortFloat. |
|
376 |
self assert:( 1.0 asShortFloat - 1.0 asLongFloat) class == LongFloat. |
|
377 |
self assert:( 1.0 asShortFloat - 1) class == ShortFloat. |
|
378 |
||
379 |
self assert:( 1.0 asLongFloat - 1.0 ) class == LongFloat. |
|
380 |
self assert:( 1.0 asLongFloat - 1.0 asShortFloat ) class == LongFloat. |
|
381 |
self assert:( 1.0 asLongFloat - 1.0 asFloat ) class == LongFloat. |
|
382 |
self assert:( 1.0 asLongFloat - 1 ) class == LongFloat. |
|
383 |
||
384 |
||
385 |
self assert:( 1.0 * 1.0 ) class == Float. |
|
386 |
self assert:( 1.0 * 1.0 asShortFloat) class == Float. |
|
387 |
self assert:( 1.0 * 1.0 asLongFloat) class == LongFloat. |
|
388 |
self assert:( 1.0 * 1) class == Float. |
|
389 |
||
390 |
self assert:( 1.0 asShortFloat * 1.0 ) class == Float. |
|
391 |
self assert:( 1.0 asShortFloat * 1.0 asShortFloat) class == ShortFloat. |
|
392 |
self assert:( 1.0 asShortFloat * 1.0 asLongFloat) class == LongFloat. |
|
393 |
self assert:( 1.0 asShortFloat * 1) class == ShortFloat. |
|
394 |
||
395 |
self assert:( 1.0 asLongFloat * 1.0 ) class == LongFloat. |
|
396 |
self assert:( 1.0 asLongFloat * 1.0 asShortFloat ) class == LongFloat. |
|
397 |
self assert:( 1.0 asLongFloat * 1.0 asFloat ) class == LongFloat. |
|
398 |
self assert:( 1.0 asLongFloat * 1 ) class == LongFloat. |
|
399 |
||
400 |
||
401 |
self assert:( 1.0 / 1.0 ) class == Float. |
|
402 |
self assert:( 1.0 / 1.0 asShortFloat) class == Float. |
|
403 |
self assert:( 1.0 / 1.0 asLongFloat) class == LongFloat. |
|
404 |
self assert:( 1.0 / 1) class == Float. |
|
405 |
||
406 |
self assert:( 1.0 asShortFloat / 1.0 ) class == Float. |
|
407 |
self assert:( 1.0 asShortFloat / 1.0 asShortFloat) class == ShortFloat. |
|
408 |
self assert:( 1.0 asShortFloat / 1.0 asLongFloat) class == LongFloat. |
|
409 |
self assert:( 1.0 asShortFloat / 1) class == ShortFloat. |
|
410 |
||
411 |
self assert:( 1.0 asLongFloat / 1.0 ) class == LongFloat. |
|
412 |
self assert:( 1.0 asLongFloat / 1.0 asShortFloat ) class == LongFloat. |
|
413 |
self assert:( 1.0 asLongFloat / 1.0 asFloat ) class == LongFloat. |
|
414 |
self assert:( 1.0 asLongFloat / 1 ) class == LongFloat. |
|
415 |
||
1391 | 416 |
self assert:( 1.0 / 2.0 ) class == Float. |
417 |
self assert:( 1.0 / 2.0 asShortFloat) class == Float. |
|
418 |
self assert:( 1.0 / 2.0 asLongFloat) class == LongFloat. |
|
419 |
self assert:( 1.0 / 2) class == Float. |
|
420 |
||
421 |
self assert:( 1.0 asShortFloat / 2.0 ) class == Float. |
|
422 |
self assert:( 1.0 asShortFloat / 2.0 asShortFloat) class == ShortFloat. |
|
423 |
self assert:( 1.0 asShortFloat / 2.0 asLongFloat) class == LongFloat. |
|
424 |
self assert:( 1.0 asShortFloat / 2) class == ShortFloat. |
|
425 |
||
426 |
self assert:( 1.0 asLongFloat / 2.0 ) class == LongFloat. |
|
427 |
self assert:( 1.0 asLongFloat / 2.0 asShortFloat ) class == LongFloat. |
|
428 |
self assert:( 1.0 asLongFloat / 2.0 asFloat ) class == LongFloat. |
|
429 |
self assert:( 1.0 asLongFloat / 2 ) class == LongFloat. |
|
430 |
||
755
b1269691d037
class: RegressionTests::FloatTest
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
431 |
self assert:( 5.0 rem: 2.0 ) class == Float. |
b1269691d037
class: RegressionTests::FloatTest
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
432 |
self assert:( 5.0 rem: 2.0 asShortFloat) class == Float. |
b1269691d037
class: RegressionTests::FloatTest
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
433 |
self assert:( 5.0 rem: 2.0 asLongFloat) class == LongFloat. |
b1269691d037
class: RegressionTests::FloatTest
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
434 |
self assert:( 5.0 rem: 2) class == Float. |
b1269691d037
class: RegressionTests::FloatTest
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
435 |
|
b1269691d037
class: RegressionTests::FloatTest
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
436 |
self assert:( 5.0 asShortFloat rem: 2.0 ) class == Float. |
b1269691d037
class: RegressionTests::FloatTest
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
437 |
self assert:( 5.0 asShortFloat rem: 2.0 asShortFloat) class == ShortFloat. |
b1269691d037
class: RegressionTests::FloatTest
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
438 |
self assert:( 5.0 asShortFloat rem: 2.0 asLongFloat) class == LongFloat. |
b1269691d037
class: RegressionTests::FloatTest
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
439 |
self assert:( 5.0 asShortFloat rem: 2) class == ShortFloat. |
b1269691d037
class: RegressionTests::FloatTest
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
440 |
|
b1269691d037
class: RegressionTests::FloatTest
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
441 |
self assert:( 5.0 asLongFloat rem: 2.0 ) class == LongFloat. |
b1269691d037
class: RegressionTests::FloatTest
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
442 |
self assert:( 5.0 asLongFloat rem: 2.0 asShortFloat ) class == LongFloat. |
b1269691d037
class: RegressionTests::FloatTest
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
443 |
self assert:( 5.0 asLongFloat rem: 2.0 asFloat ) class == LongFloat. |
b1269691d037
class: RegressionTests::FloatTest
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
444 |
self assert:( 5.0 asLongFloat rem: 2 ) class == LongFloat. |
b1269691d037
class: RegressionTests::FloatTest
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
445 |
|
192 | 446 |
" |
447 |
self basicNew test04_Arithmetic |
|
448 |
" |
|
449 |
! |
|
450 |
||
451 |
test05_Comparing |
|
1878 | 452 |
|convArray check v1 v2 v1b| |
203 | 453 |
|
2463 | 454 |
"/ negative zero |
2460 | 455 |
self assert:( 0.0 = -0.0). |
456 |
self assert:( 0.0 asShortFloat = -0.0 asShortFloat). |
|
457 |
self assert:( 0.0 asLongFloat = -0.0 asLongFloat). |
|
458 |
||
2463 | 459 |
self assert:( 0.0 negated = -0.0). |
460 |
self assert:( 0.0 asShortFloat negated = -0.0 asShortFloat). |
|
461 |
self assert:( 0.0 asLongFloat negated = -0.0 asLongFloat). |
|
462 |
||
463 |
self assert:( 0.0 negated = 0.0). |
|
464 |
self assert:( 0.0 asShortFloat negated = 0.0 asShortFloat). |
|
465 |
self assert:( 0.0 asLongFloat negated = 0.0 asLongFloat). |
|
466 |
||
467 |
self assert:( 0.0 positive). |
|
468 |
self assert:( 0.0 asShortFloat positive). |
|
469 |
self assert:( 0.0 asLongFloat positive). |
|
470 |
||
471 |
self assert:( 0.0 strictlyPositive not). |
|
472 |
self assert:( 0.0 asShortFloat strictlyPositive not). |
|
473 |
self assert:( 0.0 asLongFloat strictlyPositive not). |
|
474 |
||
475 |
self assert:( 0.0 negative not). |
|
476 |
self assert:( 0.0 asShortFloat negative not). |
|
477 |
self assert:( 0.0 asLongFloat negative not). |
|
478 |
||
479 |
self assert:( -0.0 positive). |
|
480 |
self assert:( -0.0 asShortFloat positive). |
|
481 |
self assert:( -0.0 asLongFloat positive). |
|
482 |
||
483 |
self assert:( -0.0 strictlyPositive not). |
|
484 |
self assert:( -0.0 asShortFloat strictlyPositive not). |
|
485 |
self assert:( -0.0 asLongFloat strictlyPositive not). |
|
486 |
||
487 |
self assert:( -0.0 negative not). |
|
488 |
self assert:( -0.0 asShortFloat negative not). |
|
489 |
self assert:( -0.0 asLongFloat negative not). |
|
490 |
||
491 |
self assert:( -0.0 sign == 0). |
|
492 |
self assert:( -0.0 asShortFloat sign == 0). |
|
493 |
self assert:( -0.0 asLongFloat sign == 0). |
|
494 |
||
495 |
self assert:( 0.0 sign == 0). |
|
496 |
self assert:( 0.0 asShortFloat sign == 0). |
|
497 |
self assert:( 0.0 asLongFloat sign == 0). |
|
498 |
||
499 |
self assert:( (-0.0 + -0.0 ) negative not). |
|
500 |
self assert:( (-0.0 asShortFloat + -0.0 asShortFloat) negative not). |
|
501 |
self assert:( (-0.0 asLongFloat + -0.0 asLongFloat) negative not). |
|
502 |
||
503 |
self assert:( (-0.0 * -0.0 ) negative not). |
|
504 |
self assert:( (-0.0 asShortFloat * -0.0 asShortFloat) negative not). |
|
505 |
self assert:( (-0.0 asLongFloat * -0.0 asLongFloat) negative not). |
|
506 |
||
507 |
self assert:( (-0.0 * 0.0 ) negative not). |
|
508 |
self assert:( (-0.0 asShortFloat * 0.0 asShortFloat) negative not). |
|
509 |
self assert:( (-0.0 asLongFloat * 0.0 asLongFloat) negative not). |
|
510 |
||
511 |
self assert:( (0.0 * -0.0 ) negative not). |
|
512 |
self assert:( (0.0 asShortFloat * -0.0 asShortFloat) negative not). |
|
513 |
self assert:( (0.0 asLongFloat * -0.0 asLongFloat) negative not). |
|
514 |
||
515 |
self assert:( (1.0 * -0.0 ) negative not). |
|
516 |
self assert:( (1.0 asShortFloat * -0.0 asShortFloat) negative not). |
|
517 |
self assert:( (1.0 asLongFloat * -0.0 asLongFloat) negative not). |
|
518 |
||
519 |
self assert:( (-0.0 * 1.0 ) negative not). |
|
520 |
self assert:( (-0.0 asShortFloat * 1.0 asShortFloat) negative not). |
|
521 |
self assert:( (-0.0 asLongFloat * 1.0 asLongFloat) negative not). |
|
522 |
||
1861 | 523 |
convArray := OrderedCollection new. |
524 |
convArray addAll:#(yourself asInteger asFloat asShortFloat asLongFloat). |
|
525 |
||
526 |
(Smalltalk at:#LargeFloat) notNil ifTrue:[ |
|
2444 | 527 |
convArray add:#asLargeFloat. |
528 |
]. |
|
529 |
(Smalltalk at:#QDouble) notNil ifTrue:[ |
|
530 |
convArray add:#asQDouble. |
|
1861 | 531 |
]. |
532 |
||
203 | 533 |
check := [:iv1 :iv2| |
1861 | 534 |
convArray do:[:conv1 | |
1819 | 535 |
v1 := (iv1 perform:conv1). |
192 | 536 |
|
1819 | 537 |
self assert:( v1 = nil ) not. |
538 |
self assert:( nil = v1 ) not. |
|
539 |
self assert:( v1 ~= nil ). |
|
540 |
self assert:( nil ~= v1 ). |
|
203 | 541 |
|
1861 | 542 |
convArray do:[:conv2 | |
1819 | 543 |
v1b := (iv1 perform:conv2). |
203 | 544 |
|
1819 | 545 |
self assert:( v1 = v1b ). |
546 |
self assert:( v1 <= v1b ). |
|
547 |
self assert:( v1 >= v1b ). |
|
192 | 548 |
|
1819 | 549 |
v2 := (iv2 perform:conv2). |
192 | 550 |
|
1819 | 551 |
self assert:( v1 < v2 ). |
552 |
self assert:( v1 <= v2 ). |
|
553 |
self assert:( v2 >= v1 ). |
|
554 |
self assert:( v2 > v1 ). |
|
555 |
] |
|
556 |
]. |
|
203 | 557 |
]. |
558 |
||
559 |
check value:2 value:3. |
|
560 |
check value:0 value:1. |
|
561 |
check value:-1 value:0. |
|
562 |
check value:-3 value:-2. |
|
563 |
check value:-3 value:3. |
|
564 |
||
565 |
check value:-30 value:1. |
|
566 |
check value:-1 value:30. |
|
192 | 567 |
|
2228 | 568 |
"/ showing that float precision is limited... |
569 |
||
1820 | 570 |
"/ test fails when stc code, jit code works |
2228 | 571 |
false "(Helper |
1878 | 572 |
isStcCompiledMethod:#'test05_Comparing' |
2228 | 573 |
in:self)" ifTrue:[ |
1878 | 574 |
"/ stc-compiled code handles not slightly differently |
575 |
"/ listed compares will fail |
|
576 |
'FloatTest >> test05_Comparing: test with 200000000000000000000 or similiar are skipped due would fail when stc code' infoPrintCR. |
|
577 |
] ifFalse:[ |
|
2228 | 578 |
self assert:( 200000000000000000000.0 = 200000000000000000001.0 ). |
579 |
||
1878 | 580 |
self assert:( 200000000000000000000.0 = 200000000000000000001 ). |
581 |
self assert:( 200000000000000000000.0 = 200000000000000000000 ). |
|
582 |
self assert:( 200000000000000000000.0 asLongFloat = 200000000000000000000 ). |
|
1820 | 583 |
|
1878 | 584 |
self assert:( 200000000000000000000 = 200000000000000000000.0). |
585 |
self assert:( 200000000000000000000 = 200000000000000000000.0 asLongFloat ). |
|
1820 | 586 |
|
1878 | 587 |
self assert:( 200000000000000000000.0 < 200000100000000000000 ). |
588 |
self assert:( 200000000000000000000.0 asLongFloat < 200000000000100000000 ). |
|
589 |
self assert:( 200000000000000000000.0 asShortFloat < 200001000000000000000 ). |
|
263 | 590 |
|
1878 | 591 |
self assert:( 200000000000000000000 < 200001000000000000000.0). |
592 |
self assert:( 200000000000000000000 < 200001000000000000000.0 asLongFloat ). |
|
593 |
self assert:( 200000000000000000000 < 200001000000000000000.0 asShortFloat ). |
|
1820 | 594 |
|
1878 | 595 |
self assert:( 200000000000000000000.0 <= 200000100000000000000 ). |
596 |
self assert:( 200000000000000000000.0 <= 200000000000000000000 ). |
|
597 |
self assert:( 200000000000000000000.0 asLongFloat <= 200000000000000000001 ). |
|
598 |
self assert:( 200000000000000000000.0 asLongFloat <= 200000000000000000000 ). |
|
1820 | 599 |
|
1878 | 600 |
self assert:( 200000000000000000000 <= 200001000000000000000.0). |
601 |
self assert:( 200000000000000000000 <= 200000000000000000000.0). |
|
602 |
self assert:( 200000000000000000000 <= 200001000000000000000.0 asLongFloat ). |
|
603 |
self assert:( 200000000000000000000 <= 200000000000000000000.0 asLongFloat ). |
|
604 |
]. |
|
1820 | 605 |
|
203 | 606 |
self assert:( 2000000.0 asShortFloat = 2000000 ). |
607 |
self assert:( 2000000 = 2000000.0 asShortFloat ). |
|
200 | 608 |
|
203 | 609 |
self assert:( 2000000.0 asShortFloat <= 200000100000000000000 ). |
610 |
self assert:( 2000000.0 asShortFloat <= 2000000 ). |
|
200 | 611 |
|
203 | 612 |
self assert:( 2000000 <= 2000000.0 asShortFloat ). |
613 |
self assert:( 2000000 <= 2000000.0 asShortFloat ). |
|
200 | 614 |
|
192 | 615 |
" |
616 |
self basicNew test05_Comparing |
|
617 |
" |
|
2228 | 618 |
|
619 |
"Modified: / 06-05-2019 / 14:11:42 / Claus Gittinger" |
|
192 | 620 |
! |
621 |
||
622 |
test06_MiscMath |
|
263 | 623 |
|epsilon| |
624 |
||
625 |
epsilon := 0.000001. |
|
626 |
||
192 | 627 |
#( |
1624 | 628 |
sqrt 0.5 0.707107 |
629 |
sqrt 4 2.0 |
|
630 |
exp 0.5 1.64872 |
|
631 |
ln 0.5 -0.693147 |
|
632 |
log10 0.5 -0.30103 |
|
263 | 633 |
|
1624 | 634 |
sin 0.5 0.479426 |
635 |
cos 0.5 0.877583 |
|
636 |
tan 0.5 0.546302 |
|
637 |
arcSin 0.5 0.523599 |
|
638 |
arcCos 0.5 1.0472 |
|
639 |
arcTan 0.5 0.463648 |
|
640 |
sinh 0.5 0.521095 |
|
641 |
cosh 0.5 1.12763 |
|
642 |
tanh 0.5 0.462117 |
|
643 |
arcSinh 0.5 0.481212 |
|
644 |
arcCosh 1.5 1.24983 |
|
645 |
arcTanh 0.5 0.549306 |
|
263 | 646 |
|
1624 | 647 |
sin 0.0 0.0 |
648 |
cos 0.0 1.0 |
|
649 |
tan 0.0 0.0 |
|
650 |
sinh 0.0 0.0 |
|
651 |
cosh 0.0 1.0 |
|
652 |
tanh 0.0 0.0 |
|
263 | 653 |
|
1624 | 654 |
sin 1.0 0.841471 |
655 |
cos 1.0 0.540302 |
|
656 |
tan 1.0 1.55741 |
|
657 |
sinh 1.0 1.1752 |
|
658 |
cosh 1.0 1.54308 |
|
659 |
tanh 1.0 0.761594 |
|
263 | 660 |
|
1624 | 661 |
sin 3.14159 0.0 |
662 |
cos 3.14159 -1.0 |
|
663 |
tan 3.14159 0.0 |
|
664 |
sinh 3.14159 11.5487 |
|
665 |
cosh 3.14159 11.5919 |
|
666 |
tanh 3.14159 0.996272 |
|
263 | 667 |
|
668 |
||
1624 | 669 |
tan 0.785398 1.0 "pi/4 -> should be 1" |
670 |
arcCos -1.0 3.14159 "should be pi" |
|
671 |
arcSin 1.0 1.5708 "should be pi/2 (1.5708)" |
|
672 |
arcTan 1.0 0.785398 "should be pi/4 (.785398)" |
|
263 | 673 |
) inGroupsOf:3 do:[:op :x :expected| |
2433 | 674 |
|rslt rsltShortFloat rsltLongFloat rsltLargeFloat rsltQDouble| |
263 | 675 |
|
1624 | 676 |
rslt := x perform:op. |
677 |
rsltShortFloat := x asShortFloat perform:op. |
|
678 |
rsltLongFloat := x asLongFloat perform:op. |
|
263 | 679 |
"/ rsltLargeFloat := arg asLargeFloat perform:op. |
2433 | 680 |
"/ rsltQDouble := x asQDouble perform:op. |
263 | 681 |
|
1624 | 682 |
self assert:(rslt class == Float). |
683 |
"/ self assert:(rsltShortFloat class == Float). "/ ??? not a good test; some return a float |
|
684 |
self assert:(rsltLongFloat class == LongFloat). |
|
2433 | 685 |
"/ self assert:(rsltQDouble class == QDouble). |
263 | 686 |
|
1624 | 687 |
self assert:( rslt - rsltShortFloat ) < epsilon. |
688 |
self assert:( rslt - rsltLongFloat ) < epsilon. |
|
2433 | 689 |
"/ self assert:( rslt - rsltQDouble ) < epsilon. |
263 | 690 |
"/ self assert:( rslt - rsltLargeFloat ) < epsilon. |
1624 | 691 |
self assert:( rslt - rslt asShortFloat ) < epsilon. |
692 |
self assert:( rslt - rslt asLongFloat ) < epsilon. |
|
2433 | 693 |
"/ self assert:( rslt - rsltQDouble asFloat) < epsilon. |
263 | 694 |
"/ self assert:( rslt - rslt asLargeFloat ) < epsilon. |
695 |
]. |
|
696 |
||
697 |
self should:[ -2 arcSin ] raise:DomainError. |
|
698 |
self should:[ -2 arcCos ] raise:DomainError. |
|
699 |
self should:[ -1 arcTanh ] raise:DomainError. |
|
203 | 700 |
|
263 | 701 |
#( |
1624 | 702 |
0.0 |
703 |
0.5 |
|
704 |
1.0 |
|
705 |
2.0 |
|
706 |
1.57079 |
|
263 | 707 |
) do:[:x | |
1624 | 708 |
self assert:( x sin arcSin - x < epsilon). |
709 |
self assert:( x cos arcCos - x < epsilon). |
|
710 |
self assert:( x tan arcTan - x < epsilon). |
|
263 | 711 |
]. |
203 | 712 |
|
263 | 713 |
#( |
1624 | 714 |
-1.0 |
715 |
-0.5 |
|
716 |
0.0 |
|
717 |
0.5 |
|
718 |
1.0 |
|
263 | 719 |
) do:[:x | |
1624 | 720 |
self assert:( x arcSin sin - x < epsilon). |
721 |
self assert:( x arcCos cos - x < epsilon). |
|
722 |
self assert:( x arcTan tan - x < epsilon). |
|
263 | 723 |
]. |
203 | 724 |
|
263 | 725 |
#( |
1624 | 726 |
0.0 |
727 |
0.5 |
|
728 |
1.0 |
|
729 |
2.0 |
|
730 |
10 |
|
263 | 731 |
) do:[:x | |
1624 | 732 |
self assert:( x cosh arcCosh - x < epsilon). |
263 | 733 |
]. |
734 |
#( |
|
1624 | 735 |
-10 |
736 |
-2 |
|
737 |
-1 |
|
738 |
-0.5 |
|
739 |
0.0 |
|
740 |
0.5 |
|
741 |
1.0 |
|
742 |
2.0 |
|
743 |
10 |
|
263 | 744 |
) do:[:x | |
1624 | 745 |
self assert:( x sinh arcSinh - x < epsilon). |
746 |
self assert:( x tanh arcTanh - x < epsilon). |
|
263 | 747 |
]. |
748 |
||
198 | 749 |
|
263 | 750 |
#( |
1624 | 751 |
-0.99 |
752 |
-0.5 |
|
753 |
0.0 |
|
754 |
0.5 |
|
755 |
0.99 |
|
263 | 756 |
) do:[:x | |
1624 | 757 |
self assert:( x arcTanh - (( ( (1+x)/(1-x) ) ln ) / 2 ) ) < epsilon. |
263 | 758 |
]. |
759 |
||
760 |
#( |
|
1624 | 761 |
-10 |
762 |
-5 |
|
763 |
-2.0 |
|
764 |
-1.0 |
|
765 |
0.0 |
|
766 |
1.0 |
|
767 |
2.0 |
|
768 |
10 |
|
263 | 769 |
) do:[:x | |
1624 | 770 |
self assert:( x arcSinh sinh - x < epsilon). |
263 | 771 |
]. |
772 |
||
773 |
#( |
|
1624 | 774 |
1.0 |
775 |
2.0 |
|
776 |
10.0 |
|
263 | 777 |
) do:[:x | |
1624 | 778 |
self assert:( x arcCosh cosh - x < epsilon). |
198 | 779 |
]. |
192 | 780 |
|
1624 | 781 |
self assert:(2.0 raisedTo:2) = 4.0. |
782 |
self assert:(2 raisedTo:2.0) = 4.0. |
|
783 |
self assert:(2.0 raisedTo:2.0) = 4.0. |
|
784 |
||
192 | 785 |
" |
786 |
self basicNew test06_MiscMath |
|
787 |
" |
|
1321 | 788 |
|
1624 | 789 |
"Modified: / 02-07-2017 / 00:51:05 / cg" |
192 | 790 |
! |
791 |
||
792 |
test07_Truncation |
|
793 |
|check| |
|
794 |
||
795 |
check := [:num | |
|
1915 | 796 |
self assert:( num fractionPart + num truncated ) = num. |
797 |
self assert:( num fractionPart + num truncated ) class == num class. |
|
192 | 798 |
]. |
799 |
||
800 |
check value:1.6. |
|
801 |
check value:-1.6. |
|
802 |
||
803 |
check value:1.6 asShortFloat. |
|
804 |
check value:-1.6 asShortFloat. |
|
805 |
||
806 |
check value:1.6 asLongFloat. |
|
807 |
check value:-1.6 asLongFloat. |
|
808 |
||
809 |
||
810 |
self assert:( 1.6 ceiling ) = 2. |
|
811 |
self assert:( 1.6 asShortFloat ceiling ) = 2. |
|
812 |
self assert:( 1.6 asLongFloat ceiling ) = 2. |
|
813 |
||
814 |
self assert:( 1.6 ceilingAsFloat ) = 2.0. |
|
815 |
self assert:( 1.6 ceilingAsFloat ) class == Float. |
|
816 |
self assert:( 1.6 asShortFloat ceilingAsFloat ) = 2.0 asShortFloat. |
|
817 |
self assert:( 1.6 asShortFloat ceilingAsFloat ) class == ShortFloat. |
|
818 |
self assert:( 1.6 asLongFloat ceilingAsFloat ) = 2.0 asLongFloat. |
|
819 |
self assert:( 1.6 asLongFloat ceilingAsFloat ) class == LongFloat. |
|
820 |
||
821 |
||
822 |
self assert:( 1.6 floor ) = 1. |
|
823 |
self assert:( 1.6 asShortFloat floor ) = 1. |
|
824 |
self assert:( 1.6 asLongFloat floor ) = 1. |
|
825 |
||
826 |
self assert:( 1.6 floorAsFloat ) = 1.0. |
|
827 |
self assert:( 1.6 floorAsFloat ) class == Float. |
|
828 |
self assert:( 1.6 asShortFloat floorAsFloat ) = 1.0 asShortFloat. |
|
829 |
self assert:( 1.6 asShortFloat floorAsFloat ) class == ShortFloat. |
|
830 |
self assert:( 1.6 asLongFloat floorAsFloat ) = 1.0 asLongFloat. |
|
831 |
self assert:( 1.6 asLongFloat floorAsFloat ) class == LongFloat. |
|
832 |
||
1915 | 833 |
self assert:( -1.6 floor ) = -2. |
834 |
self assert:( -1.6 asShortFloat floor ) = -2. |
|
835 |
self assert:( -1.6 asLongFloat floor ) = -2. |
|
836 |
||
837 |
self assert:( -1.6 floorAsFloat ) = -2.0. |
|
838 |
self assert:( -1.6 floorAsFloat ) class == Float. |
|
839 |
self assert:( -1.6 asShortFloat floorAsFloat ) = -2.0 asShortFloat. |
|
840 |
self assert:( -1.6 asShortFloat floorAsFloat ) class == ShortFloat. |
|
841 |
self assert:( -1.6 asLongFloat floorAsFloat ) = -2.0 asLongFloat. |
|
842 |
self assert:( -1.6 asLongFloat floorAsFloat ) class == LongFloat. |
|
843 |
||
192 | 844 |
|
1447 | 845 |
self assert:( 0.4 rounded ) class == SmallInteger. |
846 |
self assert:( 0.4 rounded = 0 ). |
|
847 |
self assert:( 0.5 rounded = 1 ). |
|
848 |
self assert:( 0.6 rounded = 1 ). |
|
849 |
self assert:( -0.4 rounded = 0 ). |
|
850 |
self assert:( -0.5 rounded = -1 ). |
|
851 |
self assert:( -0.6 rounded = -1 ). |
|
192 | 852 |
|
1447 | 853 |
self assert:( 0.4 roundedAsFloat ) class == Float. |
854 |
self assert:( 0.4 roundedAsFloat = 0.0 ). |
|
855 |
self assert:( 0.5 roundedAsFloat = 1.0 ). |
|
856 |
self assert:( 0.6 roundedAsFloat = 1.0 ). |
|
857 |
self assert:( -0.4 roundedAsFloat = 0 ). |
|
858 |
self assert:( -0.5 roundedAsFloat = -1.0 ). |
|
859 |
self assert:( -0.6 roundedAsFloat = -1.0 ). |
|
192 | 860 |
|
1447 | 861 |
self assert:( 0.4 asShortFloat rounded ) class == SmallInteger. |
862 |
self assert:( 0.4 asShortFloat rounded = 0 ). |
|
863 |
self assert:( 0.5 asShortFloat rounded = 1 ). |
|
864 |
self assert:( 0.6 asShortFloat rounded = 1 ). |
|
865 |
self assert:( -0.4 asShortFloat rounded = 0 ). |
|
866 |
self assert:( -0.5 asShortFloat rounded = -1 ). |
|
867 |
self assert:( -0.6 asShortFloat rounded = -1 ). |
|
192 | 868 |
|
1447 | 869 |
self assert:( 0.4 asShortFloat roundedAsFloat ) class == ShortFloat. |
870 |
self assert:( 0.4 asShortFloat roundedAsFloat = 0.0 ). |
|
871 |
self assert:( 0.5 asShortFloat roundedAsFloat = 1.0 ). |
|
872 |
self assert:( 0.6 asShortFloat roundedAsFloat = 1.0 ). |
|
873 |
self assert:( -0.4 asShortFloat roundedAsFloat = 0 ). |
|
874 |
self assert:( -0.5 asShortFloat roundedAsFloat = -1.0 ). |
|
875 |
self assert:( -0.6 asShortFloat roundedAsFloat = -1.0 ). |
|
192 | 876 |
|
1447 | 877 |
self assert:( 0.4 asLongFloat rounded ) class == SmallInteger. |
878 |
self assert:( 0.4 asLongFloat rounded = 0 ). |
|
879 |
self assert:( 0.5 asLongFloat rounded = 1 ). |
|
880 |
self assert:( 0.6 asLongFloat rounded = 1 ). |
|
881 |
self assert:( -0.4 asLongFloat rounded = 0 ). |
|
882 |
self assert:( -0.5 asLongFloat rounded = -1 ). |
|
883 |
self assert:( -0.6 asLongFloat rounded = -1 ). |
|
192 | 884 |
|
1447 | 885 |
self assert:( 0.4 asLongFloat roundedAsFloat ) class == LongFloat. |
886 |
self assert:( 0.4 asLongFloat roundedAsFloat = 0.0 ). |
|
887 |
self assert:( 0.5 asLongFloat roundedAsFloat = 1.0 ). |
|
888 |
self assert:( 0.6 asLongFloat roundedAsFloat = 1.0 ). |
|
889 |
self assert:( -0.4 asLongFloat roundedAsFloat = 0 ). |
|
890 |
self assert:( -0.5 asLongFloat roundedAsFloat = -1.0 ). |
|
891 |
self assert:( -0.6 asLongFloat roundedAsFloat = -1.0 ). |
|
192 | 892 |
|
1447 | 893 |
self assert:( 0.4 truncated ) class == SmallInteger. |
894 |
self assert:( 0.4 truncated = 0 ). |
|
895 |
self assert:( 0.5 truncated = 0 ). |
|
896 |
self assert:( 0.6 truncated = 0 ). |
|
897 |
self assert:( -0.4 truncated = 0 ). |
|
898 |
self assert:( -0.5 truncated = 0 ). |
|
899 |
self assert:( -0.6 truncated = 0 ). |
|
192 | 900 |
|
1447 | 901 |
self assert:( 0.4 truncatedAsFloat ) class == Float. |
902 |
self assert:( 0.4 truncatedAsFloat = 0.0 ). |
|
903 |
self assert:( 0.5 truncatedAsFloat = 0.0 ). |
|
904 |
self assert:( 0.6 truncatedAsFloat = 0.0 ). |
|
905 |
self assert:( -0.4 truncatedAsFloat = 0 ). |
|
906 |
self assert:( -0.5 truncatedAsFloat = 0.0 ). |
|
907 |
self assert:( -0.6 truncatedAsFloat = 0.0 ). |
|
192 | 908 |
|
1447 | 909 |
self assert:( 0.4 asShortFloat truncated ) class == SmallInteger. |
910 |
self assert:( 0.4 asShortFloat truncated = 0 ). |
|
911 |
self assert:( 0.5 asShortFloat truncated = 0 ). |
|
912 |
self assert:( 0.6 asShortFloat truncated = 0 ). |
|
913 |
self assert:( -0.4 asShortFloat truncated = 0 ). |
|
914 |
self assert:( -0.5 asShortFloat truncated = 0 ). |
|
915 |
self assert:( -0.6 asShortFloat truncated = 0 ). |
|
192 | 916 |
|
1447 | 917 |
self assert:( 0.4 asShortFloat truncatedAsFloat ) class == ShortFloat. |
918 |
self assert:( 0.4 asShortFloat truncatedAsFloat = 0.0 ). |
|
919 |
self assert:( 0.5 asShortFloat truncatedAsFloat = 0.0 ). |
|
920 |
self assert:( 0.6 asShortFloat truncatedAsFloat = 0.0 ). |
|
921 |
self assert:( -0.4 asShortFloat truncatedAsFloat = 0 ). |
|
922 |
self assert:( -0.5 asShortFloat truncatedAsFloat = 0.0 ). |
|
923 |
self assert:( -0.6 asShortFloat truncatedAsFloat = 0.0 ). |
|
192 | 924 |
|
1447 | 925 |
self assert:( 0.4 asLongFloat truncated ) class == SmallInteger. |
926 |
self assert:( 0.4 asLongFloat truncated = 0 ). |
|
927 |
self assert:( 0.5 asLongFloat truncated = 0 ). |
|
928 |
self assert:( 0.6 asLongFloat truncated = 0 ). |
|
929 |
self assert:( -0.4 asLongFloat truncated = 0 ). |
|
930 |
self assert:( -0.5 asLongFloat truncated = 0 ). |
|
931 |
self assert:( -0.6 asLongFloat truncated = 0 ). |
|
192 | 932 |
|
1447 | 933 |
self assert:( 0.4 asLongFloat truncatedAsFloat ) class == LongFloat. |
934 |
self assert:( 0.4 asLongFloat truncatedAsFloat = 0.0 ). |
|
935 |
self assert:( 0.5 asLongFloat truncatedAsFloat = 0.0 ). |
|
936 |
self assert:( 0.6 asLongFloat truncatedAsFloat = 0.0 ). |
|
937 |
self assert:( -0.4 asLongFloat truncatedAsFloat = 0 ). |
|
938 |
self assert:( -0.5 asLongFloat truncatedAsFloat = 0.0 ). |
|
939 |
self assert:( -0.6 asLongFloat truncatedAsFloat = 0.0 ). |
|
192 | 940 |
|
941 |
" |
|
942 |
self basicNew test07_Truncation |
|
943 |
" |
|
197 | 944 |
! |
945 |
||
946 |
test08_Representation |
|
2425 | 947 |
|noQuadFloats noOctaFloats| |
948 |
||
949 |
noQuadFloats := UnimplementedFunctionalityError catch:[1.0 asQuadFloat]. |
|
950 |
noOctaFloats := UnimplementedFunctionalityError catch:[1.0 asOctaFloat]. |
|
951 |
||
1391 | 952 |
self assert: (Float unity class == Float). |
953 |
self assert: (ShortFloat unity class == ShortFloat). |
|
954 |
self assert: (LongFloat unity class == LongFloat). |
|
955 |
||
956 |
self assert: (Float unity = 1.0). |
|
957 |
self assert: (ShortFloat unity = 1.0). |
|
958 |
self assert: (LongFloat unity = 1.0). |
|
959 |
||
960 |
self assert: (Float zero class == Float). |
|
961 |
self assert: (ShortFloat zero class == ShortFloat). |
|
962 |
self assert: (LongFloat zero class == LongFloat). |
|
963 |
||
964 |
self assert: (Float zero = 0.0). |
|
965 |
self assert: (ShortFloat zero = 0.0). |
|
966 |
self assert: (LongFloat zero = 0.0). |
|
967 |
||
968 |
self assert:( LongFloat unity = 1 asLongFloat ). |
|
969 |
self assert:( ShortFloat unity = 1 asShortFloat ). |
|
970 |
self assert:( Float unity = 1 asFloat ). |
|
971 |
||
2449 | 972 |
self assert:( 1.0 asShortFloat exponentBits = 127 ). |
973 |
self assert:( 1.0 exponentBits = 1023 ). |
|
974 |
||
197 | 975 |
self assert:( 0.0 exponent = 0 ). |
976 |
self assert:( 1.0 exponent = 1 ). |
|
977 |
self assert:( 2.0 exponent = 2 ). |
|
978 |
self assert:( 3.0 exponent = 2 ). |
|
979 |
self assert:( 4.0 exponent = 3 ). |
|
980 |
self assert:( 0.5 exponent = 0 ). |
|
981 |
self assert:( 0.4 exponent = -1 ). |
|
982 |
self assert:( 0.25 exponent = -1 ). |
|
983 |
self assert:( 0.125 exponent = -2 ). |
|
984 |
self assert:( 0.00000011111 exponent = -23 ). |
|
985 |
||
1447 | 986 |
self assert:( 0.0 asShortFloat exponent = 0 ). |
197 | 987 |
self assert:( 1.0 asShortFloat exponent = 1 ). |
988 |
self assert:( 2.0 asShortFloat exponent = 2 ). |
|
989 |
self assert:( 3.0 asShortFloat exponent = 2 ). |
|
990 |
self assert:( 4.0 asShortFloat exponent = 3 ). |
|
991 |
self assert:( 0.5 asShortFloat exponent = 0 ). |
|
992 |
self assert:( 0.4 asShortFloat exponent = -1 ). |
|
993 |
self assert:( 0.25 asShortFloat exponent = -1 ). |
|
994 |
self assert:( 0.125 asShortFloat exponent = -2 ). |
|
995 |
self assert:( 0.00000011111 asShortFloat exponent = -23 ). |
|
996 |
||
1447 | 997 |
self assert:( 0.0 asLongFloat exponent = 0 ). |
197 | 998 |
self assert:( 1.0 asLongFloat exponent = 1 ). |
999 |
self assert:( 2.0 asLongFloat exponent = 2 ). |
|
1000 |
self assert:( 3.0 asLongFloat exponent = 2 ). |
|
1001 |
self assert:( 4.0 asLongFloat exponent = 3 ). |
|
1002 |
self assert:( 0.5 asLongFloat exponent = 0 ). |
|
1003 |
self assert:( 0.4 asLongFloat exponent = -1 ). |
|
1004 |
self assert:( 0.25 asLongFloat exponent = -1 ). |
|
1005 |
self assert:( 0.125 asLongFloat exponent = -2 ). |
|
1006 |
self assert:( 0.00000011111 asLongFloat exponent = -23 ). |
|
1007 |
||
2421 | 1008 |
#( 1.0 1 |
1009 |
2.0 2 |
|
1010 |
3.0 3 |
|
1011 |
4.0 4 |
|
1012 |
12345.0 12345 |
|
1013 |
0.0 0 |
|
1014 |
-1.0 -1 |
|
1015 |
-2.0 -2 |
|
1016 |
-3.0 -3 |
|
1017 |
-4.0 -4 |
|
1018 |
-12345.0 -12345 |
|
1019 |
) pairWiseDo:[:f :i | |
|
1020 |
self assert:( f exponent = i exponent ). |
|
1021 |
self assert:( f mantissa = i mantissa ). |
|
1022 |
self assert:( f mantissa * (2 raisedTo:f exponent))= f. |
|
1023 |
self assert:( i mantissa * (2 raisedTo:i exponent)) = i. |
|
1024 |
||
1025 |
self assert:( f exponent = f asShortFloat exponent ). |
|
1026 |
self assert:( f exponent = f asLongFloat exponent ). |
|
1027 |
self assert:( f exponent = f asQDouble exponent ). |
|
2422 | 1028 |
self assert:( f asShortFloat mantissa * (2 raisedTo:f asShortFloat exponent))= f. |
1029 |
self assert:( f asLongFloat mantissa * (2 raisedTo:f asLongFloat exponent))= f. |
|
1030 |
self assert:( f asQDouble mantissa * (2 raisedTo:f asQDouble exponent))= f. |
|
2425 | 1031 |
|
1032 |
noQuadFloats ifFalse:[ |
|
1033 |
self assert:( f exponent = f asQuadFloat exponent ). |
|
1034 |
self assert:( f asQuadFloat mantissa * (2 raisedTo:f asQuadFloat exponent))= f. |
|
1035 |
]. |
|
1036 |
noOctaFloats ifFalse:[ |
|
1037 |
self assert:( f exponent = f asOctaFloat exponent ). |
|
1038 |
self assert:( f asOctaFloat mantissa * (2 raisedTo:f asOctaFloat exponent))= f. |
|
1039 |
]. |
|
2421 | 1040 |
]. |
197 | 1041 |
" |
1042 |
self basicNew test08_Representation |
|
1043 |
" |
|
604 | 1044 |
|
1045 |
"Modified: / 02-08-2011 / 18:34:39 / cg" |
|
1626 | 1046 |
! |
1047 |
||
1048 |
test09_ComplexRoots |
|
1049 |
|rslt| |
|
1050 |
||
1051 |
self should:[ -4 sqrt ] raise:ImaginaryResultError. |
|
1052 |
||
1053 |
rslt := Complex trapImaginary:[ -4 sqrt ]. |
|
1054 |
self assert:(rslt = 2 i). |
|
1055 |
||
1056 |
rslt := nil. |
|
1057 |
Complex trapImaginary:[ rslt := -4 sqrt ]. |
|
1058 |
self assert:(rslt = 2 i). |
|
1059 |
||
1060 |
self shouldnt:[ rslt := -8 cbrt ] raise:ImaginaryResultError. |
|
1061 |
self assert:(rslt = -2). |
|
1062 |
||
1063 |
" |
|
1064 |
self basicNew test09_ComplexRoots |
|
1065 |
" |
|
1066 |
||
1067 |
"Created: / 03-07-2017 / 13:51:54 / cg" |
|
2437 | 1068 |
! |
1069 |
||
2498 | 1070 |
testAssociationWithFloats |
1071 |
"ensure the association creation by -> |
|
1072 |
works with integers" |
|
1073 |
||
1074 |
self assert:(0.0->0.0) = (Association key:0 value:0). |
|
1075 |
self assert:(0.0->1.0) = (Association key:0 value:1). |
|
1076 |
self assert:(0.0 ->0.0) = (Association key:0 value:0). |
|
1077 |
self assert:(0.0 ->1.0) = (Association key:0 value:1). |
|
1078 |
||
1079 |
self assert:(1.0->0.0) = (Association key:1 value:0). |
|
1080 |
self assert:(1.0->1.0) = (Association key:1 value:1). |
|
1081 |
self assert:(1.0 ->0.0) = (Association key:1 value:0). |
|
1082 |
self assert:(1.0 ->1.0) = (Association key:1 value:1). |
|
1083 |
||
2501 | 1084 |
"/ undef behavior |
1085 |
"/ self assert:(0.0->-0.0) = (Association key:0 value:0). |
|
1086 |
"/ self assert:(0.0->-1.0) = (Association key:0 value:-1). |
|
1087 |
"/ self assert:(0.0 ->-0.0) = (Association key:0 value:0). |
|
1088 |
"/ self assert:(0.0 ->-1.0) = (Association key:0 value:-1). |
|
1089 |
"/ |
|
1090 |
"/ self assert:(1.0->-0.0) = (Association key:1 value:0). |
|
1091 |
"/ self assert:(1.0->-1.0) = (Association key:1 value:-1). |
|
1092 |
"/ self assert:(1.0 ->-0.0) = (Association key:1 value:0). |
|
1093 |
"/ self assert:(1.0 ->-1.0) = (Association key:1 value:-1). |
|
2498 | 1094 |
|
1095 |
self assert:(-0.0->0.0) = (Association key:0 value:0). |
|
1096 |
self assert:(-0.0->1.0) = (Association key:0 value:1). |
|
1097 |
self assert:(-0.0 ->0.0) = (Association key:0 value:0). |
|
1098 |
self assert:(-0.0 ->1.0) = (Association key:0 value:1). |
|
1099 |
||
1100 |
self assert:(-1.0->0.0) = (Association key:-1 value:0). |
|
1101 |
self assert:(-1.0->1.0) = (Association key:-1 value:1). |
|
1102 |
self assert:(-1.0 ->0.0) = (Association key:-1 value:0). |
|
1103 |
self assert:(-1.0 ->1.0) = (Association key:-1 value:1). |
|
1104 |
||
2501 | 1105 |
"/ undef behavior |
1106 |
"/ self assert:(-0.0->-0.0) = (Association key:0 value:0). |
|
1107 |
"/ self assert:(-0.0->-1.0) = (Association key:0 value:-1). |
|
1108 |
"/ self assert:(-0.0 ->-0.0) = (Association key:0 value:0). |
|
1109 |
"/ self assert:(-0.0 ->-1.0) = (Association key:0 value:-1). |
|
1110 |
"/ |
|
1111 |
"/ self assert:(-1.0->-0.0) = (Association key:-1 value:0). |
|
1112 |
"/ self assert:(-1.0->-1.0) = (Association key:-1 value:-1). |
|
1113 |
"/ self assert:(-1.0 ->-0.0) = (Association key:-1 value:0). |
|
1114 |
"/ self assert:(-1.0 ->-1.0) = (Association key:-1 value:-1). |
|
2498 | 1115 |
|
1116 |
self assert:(0.0-> 0.0) = (Association key:0 value:0). |
|
1117 |
self assert:(0.0-> 1.0) = (Association key:0 value:1). |
|
1118 |
self assert:(0.0 -> 0.0) = (Association key:0 value:0). |
|
1119 |
self assert:(0.0 -> 1.0) = (Association key:0 value:1). |
|
1120 |
||
1121 |
self assert:(1.0-> 0.0) = (Association key:1 value:0). |
|
1122 |
self assert:(1.0-> 1.0) = (Association key:1 value:1). |
|
1123 |
self assert:(1.0 -> 0.0) = (Association key:1 value:0). |
|
1124 |
self assert:(1.0 -> 1.0) = (Association key:1 value:1). |
|
1125 |
||
1126 |
self assert:(0.0-> -0.0) = (Association key:0 value:0). |
|
1127 |
self assert:(0.0-> -1.0) = (Association key:0 value:-1). |
|
1128 |
self assert:(0.0 -> -0.0) = (Association key:0 value:0). |
|
1129 |
self assert:(0.0 -> -1.0) = (Association key:0 value:-1). |
|
1130 |
||
1131 |
self assert:(1.0-> -0.0) = (Association key:1 value:0). |
|
1132 |
self assert:(1.0-> -1.0) = (Association key:1 value:-1). |
|
1133 |
self assert:(1.0 -> -0.0) = (Association key:1 value:0). |
|
1134 |
self assert:(1.0 -> -1.0) = (Association key:1 value:-1). |
|
1135 |
||
1136 |
self assert:(-0.0-> 0.0) = (Association key:0 value:0). |
|
1137 |
self assert:(-0.0-> 1.0) = (Association key:0 value:1). |
|
1138 |
self assert:(-0.0 -> 0.0) = (Association key:0 value:0). |
|
1139 |
self assert:(-0.0 -> 1.0) = (Association key:0 value:1). |
|
1140 |
||
1141 |
self assert:(-1.0-> 0.0) = (Association key:-1 value:0). |
|
1142 |
self assert:(-1.0-> 1.0) = (Association key:-1 value:1). |
|
1143 |
self assert:(-1.0 -> 0.0) = (Association key:-1 value:0). |
|
1144 |
self assert:(-1.0 -> 1.0) = (Association key:-1 value:1). |
|
1145 |
||
1146 |
self assert:(-0.0-> -0.0) = (Association key:0 value:0). |
|
1147 |
self assert:(-0.0-> -1.0) = (Association key:0 value:-1). |
|
1148 |
self assert:(-0.0 -> -0.0) = (Association key:0 value:0). |
|
1149 |
self assert:(-0.0 -> -1.0) = (Association key:0 value:-1). |
|
1150 |
||
1151 |
self assert:(-1.0-> -0.0) = (Association key:-1 value:0). |
|
1152 |
self assert:(-1.0-> -1.0) = (Association key:-1 value:-1). |
|
1153 |
self assert:(-1.0 -> -0.0) = (Association key:-1 value:0). |
|
1154 |
self assert:(-1.0 -> -1.0) = (Association key:-1 value:-1). |
|
1155 |
||
1156 |
" |
|
1157 |
self basicNew testAssociationWithFloats |
|
1158 |
" |
|
1159 |
||
1160 |
"Created: / 18-12-2019 / 15:26:55 / Stefan Reise" |
|
1161 |
! |
|
1162 |
||
2438 | 1163 |
test_11a_pi |
1164 |
"/ Machin's Formula for Pi pi / 4 = 4 arctan(1/5) - arctan(1/239) |
|
2437 | 1165 |
|
1166 |
| at1_5 at1_239 pi_4 pi err| |
|
1167 |
||
1168 |
at1_5 := (1.0 / 5) arcTan. |
|
1169 |
at1_239 := (1.0 / 239) arcTan. |
|
1170 |
pi_4 := (at1_5 * 4) - at1_239. |
|
1171 |
pi := pi_4 * 4. |
|
1172 |
err := Float pi - pi. |
|
1173 |
self assert:(err < (8 * Float epsilon)). |
|
2438 | 1174 |
! |
1175 |
||
1176 |
test_11b_pi |
|
1177 |
"/ Salamin-Brent Quadratic Formula for Pi |
|
1178 |
||
1179 |
| max_iter a b s m a_new b_new p_old pi err| |
|
1180 |
||
1181 |
max_iter := 6. |
|
1182 |
||
1183 |
a := 1.0 asFloat. |
|
1184 |
b := 0.5 asFloat sqrt. |
|
1185 |
s := 0.5 asFloat. |
|
1186 |
m := 1.0 asFloat. |
|
1187 |
||
1188 |
pi := 2.0 asFloat * a squared / s. |
|
1189 |
1 to:max_iter do:[:i | |
|
1190 |
m := m * 2. |
|
1191 |
a_new := 0.5 * (a+b). |
|
1192 |
b_new := a * b. |
|
1193 |
s := s - (m * (a_new squared - b_new)). |
|
1194 |
a := a_new. |
|
1195 |
b := b_new sqrt. |
|
1196 |
p_old := pi. |
|
1197 |
pi := 2 * a squared / s. |
|
1198 |
]. |
|
1199 |
||
1200 |
err := Float pi - pi. |
|
1201 |
self assert:(err < (8 * Float epsilon)). |
|
1202 |
! |
|
1203 |
||
1204 |
test_12_e |
|
1205 |
"/ Taylor for e |
|
1206 |
||
1207 |
| e t n i err| |
|
1208 |
||
1209 |
e := 2.0. |
|
1210 |
t := 1.0. |
|
1211 |
n := 1.0. |
|
1212 |
i := 0. |
|
1213 |
||
1214 |
[t > Float epsilon] whileTrue:[ |
|
1215 |
i := i + 1. |
|
1216 |
n := n + 1.0. |
|
1217 |
t := t / n. |
|
1218 |
e := e + t. |
|
1219 |
]. |
|
1220 |
||
1221 |
err := Float e - e. |
|
1222 |
self assert:(err < (8 * Float epsilon)). |
|
192 | 1223 |
! ! |
1224 |
||
1225 |
!FloatTest class methodsFor:'documentation'! |
|
1226 |
||
1227 |
version |
|
1228 |
^ '$Header$' |
|
756
0fcddf68c5a4
class: RegressionTests::FloatTest
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
1229 |
! |
0fcddf68c5a4
class: RegressionTests::FloatTest
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
1230 |
|
0fcddf68c5a4
class: RegressionTests::FloatTest
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
1231 |
version_CVS |
0fcddf68c5a4
class: RegressionTests::FloatTest
Claus Gittinger <cg@exept.de>
parents:
755
diff
changeset
|
1232 |
^ '$Header$' |
192 | 1233 |
! ! |
755
b1269691d037
class: RegressionTests::FloatTest
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1234 |