192
|
1 |
"{ Package: 'exept:regression' }"
|
|
2 |
|
|
3 |
"{ NameSpace: RegressionTests }"
|
|
4 |
|
|
5 |
TestCase subclass:#FloatTest
|
263
|
6 |
instanceVariableNames:''
|
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
|
9 |
category:'tests-Regression'
|
192
|
10 |
!
|
|
11 |
|
|
12 |
|
604
|
13 |
!FloatTest class methodsFor:'others'!
|
|
14 |
|
|
15 |
version_CVS
|
|
16 |
^ '$Header$'
|
|
17 |
! !
|
|
18 |
|
194
|
19 |
!FloatTest methodsFor:'helpers'!
|
|
20 |
|
|
21 |
actualPrecisionOf:aFloatClass
|
|
22 |
"get the actual number of valid bits in the mantissa.
|
|
23 |
This does a real test (i.e. does not believe the compiled-in ifdefs)"
|
|
24 |
|
|
25 |
|one half x count|
|
|
26 |
|
|
27 |
one := aFloatClass unity. "/ 1.0 in this class
|
|
28 |
half := one coerce:0.5.
|
|
29 |
x := one.
|
|
30 |
count := 0.
|
|
31 |
|
|
32 |
[ one + x ~= one] whileTrue:[
|
|
33 |
x := x * half.
|
|
34 |
count := count + 1.
|
|
35 |
].
|
|
36 |
^ count
|
|
37 |
|
|
38 |
"
|
|
39 |
self basicNew actualPrecisionOf:ShortFloat
|
|
40 |
self basicNew actualPrecisionOf:Float
|
|
41 |
self basicNew actualPrecisionOf:LongFloat
|
|
42 |
"
|
|
43 |
! !
|
|
44 |
|
192
|
45 |
!FloatTest methodsFor:'tests'!
|
|
46 |
|
194
|
47 |
test00_Precision
|
|
48 |
"computed precision vs. assumed precision."
|
|
49 |
|
|
50 |
self assert:( Float precision == (self actualPrecisionOf:Float)).
|
|
51 |
self assert:( ShortFloat precision == (self actualPrecisionOf:ShortFloat)).
|
|
52 |
self assert:( LongFloat precision == (self actualPrecisionOf:LongFloat)).
|
|
53 |
|
|
54 |
"
|
|
55 |
self basicNew test00_Precision
|
|
56 |
"
|
|
57 |
!
|
|
58 |
|
192
|
59 |
test01_Nan
|
|
60 |
"NaN in all avaliable formats."
|
|
61 |
|
199
|
62 |
|shouldBeFloatNaN shouldBeLongFloatNaN shouldBeShortFloatNaN|
|
192
|
63 |
|
199
|
64 |
shouldBeFloatNaN := 0.0 uncheckedDivide: 0.0.
|
|
65 |
self assert:( shouldBeFloatNaN isMemberOf:Float ).
|
|
66 |
self assert:( shouldBeFloatNaN isNaN ).
|
|
67 |
self assert:( shouldBeFloatNaN isFinite not ).
|
192
|
68 |
|
199
|
69 |
shouldBeShortFloatNaN := 0.0 asShortFloat uncheckedDivide: 0.0 asShortFloat.
|
|
70 |
self assert:( shouldBeShortFloatNaN isMemberOf:ShortFloat ).
|
|
71 |
self assert:( shouldBeShortFloatNaN isNaN ).
|
|
72 |
self assert:( shouldBeShortFloatNaN isFinite not ).
|
192
|
73 |
|
199
|
74 |
shouldBeLongFloatNaN := 0.0 asLongFloat uncheckedDivide: 0.0 asLongFloat.
|
|
75 |
self assert:( shouldBeLongFloatNaN isMemberOf:LongFloat ).
|
|
76 |
self assert:( shouldBeLongFloatNaN isNaN ).
|
|
77 |
self assert:( shouldBeLongFloatNaN isFinite not ).
|
192
|
78 |
|
199
|
79 |
shouldBeFloatNaN := 0.0 uncheckedDivide: 0.0.
|
|
80 |
self assert:( shouldBeFloatNaN asShortFloat isNaN ).
|
|
81 |
self assert:( shouldBeFloatNaN asLongFloat isNaN ).
|
192
|
82 |
|
199
|
83 |
shouldBeShortFloatNaN := 0.0 asShortFloat uncheckedDivide: 0.0.
|
|
84 |
self assert:( shouldBeShortFloatNaN asFloat isNaN ).
|
|
85 |
self assert:( shouldBeShortFloatNaN asLongFloat isNaN ).
|
192
|
86 |
|
199
|
87 |
shouldBeLongFloatNaN := 0.0 asLongFloat uncheckedDivide: 0.0.
|
|
88 |
self assert:( shouldBeLongFloatNaN asShortFloat isNaN ).
|
|
89 |
self assert:( shouldBeLongFloatNaN asLongFloat isNaN ).
|
|
90 |
|
|
91 |
shouldBeFloatNaN := 0.0 uncheckedDivide: 0.0.
|
|
92 |
self should:[ shouldBeFloatNaN asInteger ] raise:DomainError.
|
192
|
93 |
|
199
|
94 |
"/ mhmh - the following are not true (they silently return NaNs).
|
|
95 |
"/ self should:[ shouldBeFloatNaN + 1 ] raise:DomainError.
|
|
96 |
"/ self should:[ shouldBeFloatNaN + 1.0 ] raise:DomainError.
|
|
97 |
"/ self should:[ shouldBeFloatNaN + 1.0 asShortFloat ] raise:DomainError.
|
|
98 |
"/ self should:[ shouldBeFloatNaN + 1.0 asLongFloat ] raise:DomainError.
|
192
|
99 |
"/
|
199
|
100 |
"/ self should:[ shouldBeFloatNaN - 1 ] raise:DomainError.
|
|
101 |
"/ self should:[ shouldBeFloatNaN - 1.0 ] raise:DomainError.
|
|
102 |
"/ self should:[ shouldBeFloatNaN - 1.0 asShortFloat ] raise:DomainError.
|
|
103 |
"/ self should:[ shouldBeFloatNaN - 1.0 asLongFloat ] raise:DomainError.
|
192
|
104 |
|
|
105 |
"/ but these are:
|
199
|
106 |
self assert:( shouldBeFloatNaN + 1 ) isNaN.
|
|
107 |
self assert:( shouldBeFloatNaN + 1.0 ) isNaN.
|
|
108 |
self assert:( shouldBeFloatNaN + 1.0 asShortFloat ) isNaN.
|
|
109 |
self assert:( shouldBeFloatNaN + 1.0 asLongFloat ) isNaN.
|
|
110 |
|
|
111 |
self assert:( shouldBeFloatNaN - 1 ) isNaN.
|
|
112 |
self assert:( shouldBeFloatNaN - 1.0 ) isNaN.
|
|
113 |
self assert:( shouldBeFloatNaN - 1.0 asShortFloat ) isNaN.
|
|
114 |
self assert:( shouldBeFloatNaN - 1.0 asLongFloat ) isNaN.
|
|
115 |
|
|
116 |
|
|
117 |
shouldBeShortFloatNaN := 0.0 asShortFloat uncheckedDivide: 0.0.
|
|
118 |
self should:[ shouldBeShortFloatNaN asInteger ] raise:DomainError.
|
192
|
119 |
|
199
|
120 |
self assert:( shouldBeShortFloatNaN + 1 ) isNaN.
|
|
121 |
self assert:( shouldBeShortFloatNaN + 1.0 ) isNaN.
|
|
122 |
self assert:( shouldBeShortFloatNaN + 1.0 asShortFloat ) isNaN.
|
|
123 |
self assert:( shouldBeShortFloatNaN + 1.0 asLongFloat ) isNaN.
|
|
124 |
|
|
125 |
self assert:( shouldBeShortFloatNaN - 1 ) isNaN.
|
|
126 |
self assert:( shouldBeShortFloatNaN - 1.0 ) isNaN.
|
|
127 |
self assert:( shouldBeShortFloatNaN - 1.0 asShortFloat ) isNaN.
|
|
128 |
self assert:( shouldBeShortFloatNaN - 1.0 asLongFloat ) isNaN.
|
|
129 |
|
|
130 |
shouldBeLongFloatNaN := 0.0 asLongFloat uncheckedDivide: 0.0.
|
|
131 |
self should:[ shouldBeLongFloatNaN asInteger ] raise:DomainError.
|
|
132 |
|
|
133 |
self assert:( shouldBeLongFloatNaN + 1 ) isNaN.
|
|
134 |
self assert:( shouldBeLongFloatNaN + 1.0 ) isNaN.
|
|
135 |
self assert:( shouldBeLongFloatNaN + 1.0 asShortFloat ) isNaN.
|
|
136 |
self assert:( shouldBeLongFloatNaN + 1.0 asLongFloat ) isNaN.
|
|
137 |
|
|
138 |
self assert:( shouldBeLongFloatNaN - 1 ) isNaN.
|
|
139 |
self assert:( shouldBeLongFloatNaN - 1.0 ) isNaN.
|
|
140 |
self assert:( shouldBeLongFloatNaN - 1.0 asShortFloat ) isNaN.
|
|
141 |
self assert:( shouldBeLongFloatNaN - 1.0 asLongFloat ) isNaN.
|
192
|
142 |
|
|
143 |
"
|
|
144 |
self basicNew test01_Nan
|
|
145 |
"
|
|
146 |
!
|
|
147 |
|
|
148 |
test02_Inf
|
|
149 |
"Infinity in all avaliable formats."
|
|
150 |
|
203
|
151 |
|check posInf negInf|
|
192
|
152 |
|
|
153 |
check :=
|
|
154 |
[:v1 :v2 |
|
|
155 |
|
203
|
156 |
posInf := v1 uncheckedDivide: v2.
|
192
|
157 |
|
203
|
158 |
self assert:( posInf isMemberOf:v1 class ).
|
|
159 |
self assert:( posInf isNaN not ).
|
|
160 |
self assert:( posInf isFinite not ).
|
|
161 |
self assert:( posInf isInfinite ).
|
|
162 |
self assert:( posInf positive ).
|
|
163 |
self assert:( posInf negative not ).
|
|
164 |
self assert:( posInf isNegativeInfinity not).
|
|
165 |
self assert:( posInf isPositiveInfinity ).
|
|
166 |
|
|
167 |
negInf := v1 negated uncheckedDivide: v2.
|
192
|
168 |
|
203
|
169 |
self assert:( negInf isMemberOf:v1 class ).
|
|
170 |
self assert:( negInf isNaN not ).
|
|
171 |
self assert:( negInf isFinite not ).
|
|
172 |
self assert:( negInf isInfinite ).
|
|
173 |
self assert:( negInf positive not).
|
|
174 |
self assert:( negInf negative ).
|
|
175 |
self assert:( negInf isNegativeInfinity ).
|
|
176 |
self assert:( negInf isPositiveInfinity not ).
|
192
|
177 |
|
203
|
178 |
self assert:( negInf + negInf = negInf).
|
|
179 |
self assert:( posInf + posInf = posInf).
|
|
180 |
self assert:( negInf + posInf) isNaN.
|
|
181 |
self assert:( posInf + negInf) isNaN.
|
|
182 |
|
|
183 |
self assert:( negInf - posInf = negInf).
|
|
184 |
self assert:( negInf - negInf) isNaN.
|
|
185 |
self assert:( posInf - negInf = posInf).
|
|
186 |
self assert:( posInf - posInf) isNaN.
|
|
187 |
|
|
188 |
self assert:( posInf + v1) = posInf.
|
|
189 |
self assert:( posInf - v1) = posInf.
|
|
190 |
self assert:( negInf + v1) = negInf.
|
|
191 |
self assert:( negInf - v1) = negInf.
|
192
|
192 |
].
|
|
193 |
|
|
194 |
check value: 1.0 value: 0.0.
|
|
195 |
check value: 1.0 asShortFloat value: 0.0 asShortFloat.
|
|
196 |
check value: 1.0 asLongFloat value: 0.0 asLongFloat.
|
|
197 |
|
|
198 |
"/ these are not guaranteed to work with uncheckedDivide...
|
|
199 |
"/ check value: 1.0 value: 0.0 asShortFloat.
|
|
200 |
"/ check value: 1.0 value: 0.0 asLongFloat.
|
|
201 |
"/
|
|
202 |
"/ check value: 1.0 asShortFloat value: 0.0.
|
|
203 |
"/ check value: 1.0 asShortFloat value: 0.0 asLongFloat.
|
|
204 |
"/
|
|
205 |
"/ check value: 1.0 asLongFloat value: 0.0 asShortFloat.
|
|
206 |
"/ check value: 1.0 asLongFloat value: 0.0.
|
|
207 |
|
|
208 |
"
|
|
209 |
self basicNew test02_Inf
|
|
210 |
"
|
|
211 |
!
|
|
212 |
|
|
213 |
test03_Conversion
|
|
214 |
self assert:( 1.0 asTrueFraction == 1 ).
|
|
215 |
self assert:( 2.0 asTrueFraction == 2 ).
|
|
216 |
self assert:( 4.0 asTrueFraction == 4 ).
|
|
217 |
self assert:( 8.0 asTrueFraction == 8 ).
|
|
218 |
self assert:( 16.0 asTrueFraction == 16 ).
|
|
219 |
self assert:( 1048576.0 asTrueFraction == 1048576 ).
|
|
220 |
self assert:( 0.5 asTrueFraction = (1/2) ).
|
|
221 |
self assert:( 0.25 asTrueFraction = (1/4) ).
|
|
222 |
self assert:( 0.125 asTrueFraction = (1/8) ).
|
|
223 |
|
|
224 |
self assert:( 1.0 asShortFloat asTrueFraction == 1 ).
|
|
225 |
self assert:( 2.0 asShortFloat asTrueFraction == 2 ).
|
|
226 |
self assert:( 4.0 asShortFloat asTrueFraction == 4 ).
|
|
227 |
self assert:( 8.0 asShortFloat asTrueFraction == 8 ).
|
|
228 |
self assert:( 16.0 asShortFloat asTrueFraction == 16 ).
|
|
229 |
self assert:( 1048576.0 asShortFloat asTrueFraction == 1048576 ).
|
|
230 |
self assert:( 0.5 asShortFloat asTrueFraction = (1/2) ).
|
|
231 |
self assert:( 0.25 asShortFloat asTrueFraction = (1/4) ).
|
|
232 |
self assert:( 0.125 asShortFloat asTrueFraction = (1/8) ).
|
|
233 |
|
|
234 |
self assert:( 1.0 asLongFloat asTrueFraction == 1 ).
|
|
235 |
self assert:( 2.0 asLongFloat asTrueFraction == 2 ).
|
|
236 |
self assert:( 4.0 asLongFloat asTrueFraction == 4 ).
|
|
237 |
self assert:( 8.0 asLongFloat asTrueFraction == 8 ).
|
|
238 |
self assert:( 16.0 asLongFloat asTrueFraction == 16 ).
|
|
239 |
self assert:( 1048576.0 asLongFloat asTrueFraction == 1048576 ).
|
|
240 |
self assert:( 0.5 asLongFloat asTrueFraction = (1/2) ).
|
|
241 |
self assert:( 0.25 asLongFloat asTrueFraction = (1/4) ).
|
|
242 |
self assert:( 0.125 asLongFloat asTrueFraction = (1/8) ).
|
|
243 |
|
203
|
244 |
self assert: ((5/9) asFloat - 0.555555555555) abs < 0.0000000001.
|
|
245 |
self assert: ((5/9) asLongFloat - 0.555555555555) abs < 0.0000000001.
|
|
246 |
self assert: ((Fraction basicNew setNumerator:500000000000 denominator:900000000000)
|
|
247 |
asLongFloat - 0.555555555555) abs < 0.000000000001.
|
|
248 |
self assert: ((Fraction basicNew setNumerator:500000000001 denominator:900000000000)
|
|
249 |
asLongFloat - 0.555555555555) abs >= 0.000000000001.
|
|
250 |
|
|
251 |
self assert: (8901234567890123456 asLongFloat asInteger = 8901234567890123456).
|
|
252 |
self assert: (-8901234567890123456 asLongFloat asInteger = -8901234567890123456).
|
|
253 |
|
|
254 |
self assert: (89012345678901234567 asLongFloat = 89012345678901234567).
|
|
255 |
self assert: (-89012345678901234567 asLongFloat = -89012345678901234567).
|
|
256 |
self assert: (89012345678901234567 negated asLongFloat = -89012345678901234567).
|
|
257 |
|
|
258 |
self assert: ((89012345678901234567 / 123456789123456789) asLongFloat - (89012345678901234567 asLongFloat / 123456789123456789 asLongFloat) ) abs < 0.000000000001.
|
|
259 |
self assert: ((-89012345678901234567 / 123456789123456789) asLongFloat - (-89012345678901234567 asLongFloat / 123456789123456789 asLongFloat)) abs < 0.000000000001.
|
|
260 |
|
192
|
261 |
"
|
|
262 |
self basicNew test03_Conversion
|
|
263 |
"
|
|
264 |
!
|
|
265 |
|
|
266 |
test04_Arithmetic
|
|
267 |
self assert:( 1.0 + 1.0 ) class == Float.
|
|
268 |
self assert:( 1.0 + 1.0 asShortFloat) class == Float.
|
|
269 |
self assert:( 1.0 + 1.0 asLongFloat) class == LongFloat.
|
|
270 |
self assert:( 1.0 + 1) class == Float.
|
|
271 |
|
|
272 |
self assert:( 1.0 asShortFloat + 1.0 ) class == Float.
|
|
273 |
self assert:( 1.0 asShortFloat + 1.0 asShortFloat) class == ShortFloat.
|
|
274 |
self assert:( 1.0 asShortFloat + 1.0 asLongFloat) class == LongFloat.
|
|
275 |
self assert:( 1.0 asShortFloat + 1) class == ShortFloat.
|
|
276 |
|
|
277 |
self assert:( 1.0 asLongFloat + 1.0 ) class == LongFloat.
|
|
278 |
self assert:( 1.0 asLongFloat + 1.0 asShortFloat ) class == LongFloat.
|
|
279 |
self assert:( 1.0 asLongFloat + 1.0 asFloat ) class == LongFloat.
|
|
280 |
self assert:( 1.0 asLongFloat + 1 ) class == LongFloat.
|
|
281 |
|
|
282 |
|
|
283 |
self assert:( 1.0 - 1.0 ) class == Float.
|
|
284 |
self assert:( 1.0 - 1.0 asShortFloat) class == Float.
|
|
285 |
self assert:( 1.0 - 1.0 asLongFloat) class == LongFloat.
|
|
286 |
self assert:( 1.0 - 1) class == Float.
|
|
287 |
|
|
288 |
self assert:( 1.0 asShortFloat - 1.0 ) class == Float.
|
|
289 |
self assert:( 1.0 asShortFloat - 1.0 asShortFloat) class == ShortFloat.
|
|
290 |
self assert:( 1.0 asShortFloat - 1.0 asLongFloat) class == LongFloat.
|
|
291 |
self assert:( 1.0 asShortFloat - 1) class == ShortFloat.
|
|
292 |
|
|
293 |
self assert:( 1.0 asLongFloat - 1.0 ) class == LongFloat.
|
|
294 |
self assert:( 1.0 asLongFloat - 1.0 asShortFloat ) class == LongFloat.
|
|
295 |
self assert:( 1.0 asLongFloat - 1.0 asFloat ) class == LongFloat.
|
|
296 |
self assert:( 1.0 asLongFloat - 1 ) class == LongFloat.
|
|
297 |
|
|
298 |
|
|
299 |
self assert:( 1.0 * 1.0 ) class == Float.
|
|
300 |
self assert:( 1.0 * 1.0 asShortFloat) class == Float.
|
|
301 |
self assert:( 1.0 * 1.0 asLongFloat) class == LongFloat.
|
|
302 |
self assert:( 1.0 * 1) class == Float.
|
|
303 |
|
|
304 |
self assert:( 1.0 asShortFloat * 1.0 ) class == Float.
|
|
305 |
self assert:( 1.0 asShortFloat * 1.0 asShortFloat) class == ShortFloat.
|
|
306 |
self assert:( 1.0 asShortFloat * 1.0 asLongFloat) class == LongFloat.
|
|
307 |
self assert:( 1.0 asShortFloat * 1) class == ShortFloat.
|
|
308 |
|
|
309 |
self assert:( 1.0 asLongFloat * 1.0 ) class == LongFloat.
|
|
310 |
self assert:( 1.0 asLongFloat * 1.0 asShortFloat ) class == LongFloat.
|
|
311 |
self assert:( 1.0 asLongFloat * 1.0 asFloat ) class == LongFloat.
|
|
312 |
self assert:( 1.0 asLongFloat * 1 ) class == LongFloat.
|
|
313 |
|
|
314 |
|
|
315 |
self assert:( 1.0 / 1.0 ) class == Float.
|
|
316 |
self assert:( 1.0 / 1.0 asShortFloat) class == Float.
|
|
317 |
self assert:( 1.0 / 1.0 asLongFloat) class == LongFloat.
|
|
318 |
self assert:( 1.0 / 1) class == Float.
|
|
319 |
|
|
320 |
self assert:( 1.0 asShortFloat / 1.0 ) class == Float.
|
|
321 |
self assert:( 1.0 asShortFloat / 1.0 asShortFloat) class == ShortFloat.
|
|
322 |
self assert:( 1.0 asShortFloat / 1.0 asLongFloat) class == LongFloat.
|
|
323 |
self assert:( 1.0 asShortFloat / 1) class == ShortFloat.
|
|
324 |
|
|
325 |
self assert:( 1.0 asLongFloat / 1.0 ) class == LongFloat.
|
|
326 |
self assert:( 1.0 asLongFloat / 1.0 asShortFloat ) class == LongFloat.
|
|
327 |
self assert:( 1.0 asLongFloat / 1.0 asFloat ) class == LongFloat.
|
|
328 |
self assert:( 1.0 asLongFloat / 1 ) class == LongFloat.
|
|
329 |
|
|
330 |
"
|
|
331 |
self basicNew test04_Arithmetic
|
|
332 |
"
|
|
333 |
!
|
|
334 |
|
|
335 |
test05_Comparing
|
203
|
336 |
|check v1 v2 v1b|
|
|
337 |
|
|
338 |
check := [:iv1 :iv2|
|
|
339 |
#(yourself asInteger asFloat asShortFloat asLongFloat asLargeFloat) do:[:conv1 |
|
|
340 |
v1 := (iv1 perform:conv1).
|
192
|
341 |
|
203
|
342 |
self assert:( v1 = nil ) not.
|
|
343 |
self assert:( nil = v1 ) not.
|
|
344 |
self assert:( v1 ~= nil ).
|
|
345 |
self assert:( nil ~= v1 ).
|
|
346 |
|
|
347 |
#(yourself asInteger asFloat asShortFloat asLongFloat asLargeFloat) do:[:conv2 |
|
|
348 |
v1b := (iv1 perform:conv2).
|
|
349 |
|
|
350 |
self assert:( v1 = v1b ).
|
|
351 |
self assert:( v1 <= v1b ).
|
|
352 |
self assert:( v1 >= v1b ).
|
192
|
353 |
|
203
|
354 |
v2 := (iv2 perform:conv2).
|
192
|
355 |
|
203
|
356 |
self assert:( v1 < v2 ).
|
|
357 |
self assert:( v1 <= v2 ).
|
|
358 |
self assert:( v2 >= v1 ).
|
|
359 |
self assert:( v2 > v1 ).
|
|
360 |
]
|
|
361 |
].
|
|
362 |
].
|
|
363 |
|
|
364 |
check value:2 value:3.
|
|
365 |
check value:0 value:1.
|
|
366 |
check value:-1 value:0.
|
|
367 |
check value:-3 value:-2.
|
|
368 |
check value:-3 value:3.
|
|
369 |
|
|
370 |
check value:-30 value:1.
|
|
371 |
check value:-1 value:30.
|
192
|
372 |
|
263
|
373 |
self assert:( 200000000000000000000.0 = 200000000000000000001 ).
|
|
374 |
|
200
|
375 |
self assert:( 200000000000000000000.0 = 200000000000000000000 ).
|
|
376 |
self assert:( 200000000000000000000.0 asLongFloat = 200000000000000000000 ).
|
203
|
377 |
self assert:( 2000000.0 asShortFloat = 2000000 ).
|
200
|
378 |
|
|
379 |
self assert:( 200000000000000000000 = 200000000000000000000.0).
|
|
380 |
self assert:( 200000000000000000000 = 200000000000000000000.0 asLongFloat ).
|
203
|
381 |
self assert:( 2000000 = 2000000.0 asShortFloat ).
|
200
|
382 |
|
|
383 |
|
|
384 |
self assert:( 200000000000000000000.0 < 200000100000000000000 ).
|
202
|
385 |
self assert:( 200000000000000000000.0 asLongFloat < 200000000000100000000 ).
|
200
|
386 |
self assert:( 200000000000000000000.0 asShortFloat < 200001000000000000000 ).
|
|
387 |
|
|
388 |
self assert:( 200000000000000000000 < 200001000000000000000.0).
|
|
389 |
self assert:( 200000000000000000000 < 200001000000000000000.0 asLongFloat ).
|
|
390 |
self assert:( 200000000000000000000 < 200001000000000000000.0 asShortFloat ).
|
|
391 |
|
|
392 |
|
|
393 |
self assert:( 200000000000000000000.0 <= 200000100000000000000 ).
|
|
394 |
self assert:( 200000000000000000000.0 <= 200000000000000000000 ).
|
|
395 |
self assert:( 200000000000000000000.0 asLongFloat <= 200000000000000000001 ).
|
|
396 |
self assert:( 200000000000000000000.0 asLongFloat <= 200000000000000000000 ).
|
203
|
397 |
self assert:( 2000000.0 asShortFloat <= 200000100000000000000 ).
|
|
398 |
self assert:( 2000000.0 asShortFloat <= 2000000 ).
|
200
|
399 |
|
|
400 |
self assert:( 200000000000000000000 <= 200001000000000000000.0).
|
|
401 |
self assert:( 200000000000000000000 <= 200000000000000000000.0).
|
|
402 |
self assert:( 200000000000000000000 <= 200001000000000000000.0 asLongFloat ).
|
|
403 |
self assert:( 200000000000000000000 <= 200000000000000000000.0 asLongFloat ).
|
203
|
404 |
self assert:( 2000000 <= 2000000.0 asShortFloat ).
|
|
405 |
self assert:( 2000000 <= 2000000.0 asShortFloat ).
|
200
|
406 |
|
192
|
407 |
"
|
|
408 |
self basicNew test05_Comparing
|
|
409 |
"
|
|
410 |
!
|
|
411 |
|
|
412 |
test06_MiscMath
|
263
|
413 |
|epsilon|
|
|
414 |
|
|
415 |
epsilon := 0.000001.
|
|
416 |
|
192
|
417 |
#(
|
263
|
418 |
sqrt 0.5 0.707107
|
|
419 |
exp 0.5 1.64872
|
|
420 |
ln 0.5 -0.693147
|
|
421 |
log10 0.5 -0.30103
|
|
422 |
|
|
423 |
sin 0.5 0.479426
|
|
424 |
cos 0.5 0.877583
|
|
425 |
tan 0.5 0.546302
|
|
426 |
arcSin 0.5 0.523599
|
|
427 |
arcCos 0.5 1.0472
|
|
428 |
arcTan 0.5 0.463648
|
|
429 |
sinh 0.5 0.521095
|
|
430 |
cosh 0.5 1.12763
|
|
431 |
tanh 0.5 0.462117
|
|
432 |
arcSinh 0.5 0.481212
|
|
433 |
arcCosh 1.5 1.24983
|
|
434 |
arcTanh 0.5 0.549306
|
|
435 |
|
|
436 |
sin 0.0 0.0
|
|
437 |
cos 0.0 1.0
|
|
438 |
tan 0.0 0.0
|
|
439 |
sinh 0.0 0.0
|
|
440 |
cosh 0.0 1.0
|
|
441 |
tanh 0.0 0.0
|
|
442 |
|
|
443 |
sin 1.0 0.841471
|
|
444 |
cos 1.0 0.540302
|
|
445 |
tan 1.0 1.55741
|
|
446 |
sinh 1.0 1.1752
|
|
447 |
cosh 1.0 1.54308
|
|
448 |
tanh 1.0 0.761594
|
|
449 |
|
|
450 |
sin 3.14159 0.0
|
|
451 |
cos 3.14159 -1.0
|
|
452 |
tan 3.14159 0.0
|
|
453 |
sinh 3.14159 11.5487
|
|
454 |
cosh 3.14159 11.5919
|
|
455 |
tanh 3.14159 0.996272
|
|
456 |
|
|
457 |
|
|
458 |
tan 0.785398 1.0 "pi/4 -> should be 1"
|
|
459 |
arcCos -1.0 3.14159 "should be pi"
|
|
460 |
arcSin 1.0 1.5708 "should be pi/2 (1.5708)"
|
|
461 |
arcTan 1.0 0.785398 "should be pi/4 (.785398)"
|
|
462 |
) inGroupsOf:3 do:[:op :x :expected|
|
|
463 |
|rslt rsltShortFloat rsltLongFloat rsltLargeFloat|
|
|
464 |
|
|
465 |
rslt := x perform:op.
|
|
466 |
rsltShortFloat := x asShortFloat perform:op.
|
|
467 |
rsltLongFloat := x asLongFloat perform:op.
|
|
468 |
"/ rsltLargeFloat := arg asLargeFloat perform:op.
|
|
469 |
|
|
470 |
self assert:(rslt class == Float).
|
|
471 |
self assert:(rsltShortFloat class == Float). "/ ???
|
|
472 |
self assert:(rsltLongFloat class == LongFloat).
|
|
473 |
|
|
474 |
self assert:( rslt - rsltShortFloat ) < epsilon.
|
|
475 |
self assert:( rslt - rsltLongFloat ) < epsilon.
|
|
476 |
"/ self assert:( rslt - rsltLargeFloat ) < epsilon.
|
|
477 |
self assert:( rslt - rslt asShortFloat ) < epsilon.
|
|
478 |
self assert:( rslt - rslt asLongFloat ) < epsilon.
|
|
479 |
"/ self assert:( rslt - rslt asLargeFloat ) < epsilon.
|
|
480 |
].
|
|
481 |
|
|
482 |
self should:[ -2 arcSin ] raise:DomainError.
|
|
483 |
self should:[ -2 arcCos ] raise:DomainError.
|
|
484 |
self should:[ -1 arcTanh ] raise:DomainError.
|
203
|
485 |
|
263
|
486 |
#(
|
|
487 |
0.0
|
|
488 |
0.5
|
|
489 |
1.0
|
|
490 |
2.0
|
|
491 |
1.57079
|
|
492 |
) do:[:x |
|
|
493 |
self assert:( x sin arcSin - x < epsilon).
|
|
494 |
self assert:( x cos arcCos - x < epsilon).
|
|
495 |
self assert:( x tan arcTan - x < epsilon).
|
|
496 |
].
|
203
|
497 |
|
263
|
498 |
#(
|
|
499 |
-1.0
|
|
500 |
-0.5
|
|
501 |
0.0
|
|
502 |
0.5
|
|
503 |
1.0
|
|
504 |
) do:[:x |
|
|
505 |
self assert:( x arcSin sin - x < epsilon).
|
|
506 |
self assert:( x arcCos cos - x < epsilon).
|
|
507 |
self assert:( x arcTan tan - x < epsilon).
|
|
508 |
].
|
203
|
509 |
|
263
|
510 |
#(
|
|
511 |
0.0
|
|
512 |
0.5
|
|
513 |
1.0
|
|
514 |
2.0
|
|
515 |
10
|
|
516 |
) do:[:x |
|
|
517 |
self assert:( x cosh arcCosh - x < epsilon).
|
|
518 |
].
|
|
519 |
#(
|
|
520 |
-10
|
|
521 |
-2
|
|
522 |
-1
|
|
523 |
-0.5
|
|
524 |
0.0
|
|
525 |
0.5
|
|
526 |
1.0
|
|
527 |
2.0
|
|
528 |
10
|
|
529 |
) do:[:x |
|
|
530 |
self assert:( x sinh arcSinh - x < epsilon).
|
|
531 |
self assert:( x tanh arcTanh - x < epsilon).
|
|
532 |
].
|
|
533 |
|
198
|
534 |
|
263
|
535 |
#(
|
|
536 |
-0.99
|
|
537 |
-0.5
|
|
538 |
0.0
|
|
539 |
0.5
|
|
540 |
0.99
|
|
541 |
) do:[:x |
|
|
542 |
self assert:( x arcTanh - (( ( (1+x)/(1-x) ) ln ) / 2 ) ) < epsilon.
|
|
543 |
].
|
|
544 |
|
|
545 |
#(
|
|
546 |
-10
|
|
547 |
-5
|
|
548 |
-2.0
|
|
549 |
-1.0
|
|
550 |
0.0
|
|
551 |
1.0
|
|
552 |
2.0
|
|
553 |
10
|
|
554 |
) do:[:x |
|
|
555 |
self assert:( x arcSinh sinh - x < epsilon).
|
|
556 |
].
|
|
557 |
|
|
558 |
#(
|
|
559 |
1.0
|
|
560 |
2.0
|
|
561 |
10.0
|
|
562 |
) do:[:x |
|
|
563 |
self assert:( x arcCosh cosh - x < epsilon).
|
198
|
564 |
].
|
192
|
565 |
|
|
566 |
"
|
|
567 |
self basicNew test06_MiscMath
|
|
568 |
"
|
|
569 |
!
|
|
570 |
|
|
571 |
test07_Truncation
|
|
572 |
|check|
|
|
573 |
|
|
574 |
check := [:num |
|
|
575 |
self assert:( num fractionPart + num truncated ) = num.
|
|
576 |
self assert:( num fractionPart + num truncated ) class == num class.
|
|
577 |
].
|
|
578 |
|
|
579 |
check value:1.6.
|
|
580 |
check value:-1.6.
|
|
581 |
|
|
582 |
check value:1.6 asShortFloat.
|
|
583 |
check value:-1.6 asShortFloat.
|
|
584 |
|
|
585 |
check value:1.6 asLongFloat.
|
|
586 |
check value:-1.6 asLongFloat.
|
|
587 |
|
|
588 |
|
|
589 |
self assert:( 1.6 ceiling ) = 2.
|
|
590 |
self assert:( 1.6 asShortFloat ceiling ) = 2.
|
|
591 |
self assert:( 1.6 asLongFloat ceiling ) = 2.
|
|
592 |
|
|
593 |
self assert:( 1.6 ceilingAsFloat ) = 2.0.
|
|
594 |
self assert:( 1.6 ceilingAsFloat ) class == Float.
|
|
595 |
self assert:( 1.6 asShortFloat ceilingAsFloat ) = 2.0 asShortFloat.
|
|
596 |
self assert:( 1.6 asShortFloat ceilingAsFloat ) class == ShortFloat.
|
|
597 |
self assert:( 1.6 asLongFloat ceilingAsFloat ) = 2.0 asLongFloat.
|
|
598 |
self assert:( 1.6 asLongFloat ceilingAsFloat ) class == LongFloat.
|
|
599 |
|
|
600 |
|
|
601 |
self assert:( 1.6 floor ) = 1.
|
|
602 |
self assert:( 1.6 asShortFloat floor ) = 1.
|
|
603 |
self assert:( 1.6 asLongFloat floor ) = 1.
|
|
604 |
|
|
605 |
self assert:( 1.6 floorAsFloat ) = 1.0.
|
|
606 |
self assert:( 1.6 floorAsFloat ) class == Float.
|
|
607 |
self assert:( 1.6 asShortFloat floorAsFloat ) = 1.0 asShortFloat.
|
|
608 |
self assert:( 1.6 asShortFloat floorAsFloat ) class == ShortFloat.
|
|
609 |
self assert:( 1.6 asLongFloat floorAsFloat ) = 1.0 asLongFloat.
|
|
610 |
self assert:( 1.6 asLongFloat floorAsFloat ) class == LongFloat.
|
|
611 |
|
|
612 |
|
|
613 |
self assert:( 0.4 rounded ) class == SmallInteger.
|
|
614 |
self assert:( 0.4 rounded = 0 ).
|
|
615 |
self assert:( 0.5 rounded = 1 ).
|
|
616 |
self assert:( 0.6 rounded = 1 ).
|
|
617 |
self assert:( -0.4 rounded = 0 ).
|
|
618 |
self assert:( -0.5 rounded = -1 ).
|
|
619 |
self assert:( -0.6 rounded = -1 ).
|
|
620 |
|
|
621 |
self assert:( 0.4 roundedAsFloat ) class == Float.
|
|
622 |
self assert:( 0.4 roundedAsFloat = 0.0 ).
|
|
623 |
self assert:( 0.5 roundedAsFloat = 1.0 ).
|
|
624 |
self assert:( 0.6 roundedAsFloat = 1.0 ).
|
|
625 |
self assert:( -0.4 roundedAsFloat = 0 ).
|
|
626 |
self assert:( -0.5 roundedAsFloat = -1.0 ).
|
|
627 |
self assert:( -0.6 roundedAsFloat = -1.0 ).
|
|
628 |
|
|
629 |
self assert:( 0.4 asShortFloat rounded ) class == SmallInteger.
|
|
630 |
self assert:( 0.4 asShortFloat rounded = 0 ).
|
|
631 |
self assert:( 0.5 asShortFloat rounded = 1 ).
|
|
632 |
self assert:( 0.6 asShortFloat rounded = 1 ).
|
|
633 |
self assert:( -0.4 asShortFloat rounded = 0 ).
|
|
634 |
self assert:( -0.5 asShortFloat rounded = -1 ).
|
|
635 |
self assert:( -0.6 asShortFloat rounded = -1 ).
|
|
636 |
|
|
637 |
self assert:( 0.4 asShortFloat roundedAsFloat ) class == ShortFloat.
|
|
638 |
self assert:( 0.4 asShortFloat roundedAsFloat = 0.0 ).
|
|
639 |
self assert:( 0.5 asShortFloat roundedAsFloat = 1.0 ).
|
|
640 |
self assert:( 0.6 asShortFloat roundedAsFloat = 1.0 ).
|
|
641 |
self assert:( -0.4 asShortFloat roundedAsFloat = 0 ).
|
|
642 |
self assert:( -0.5 asShortFloat roundedAsFloat = -1.0 ).
|
|
643 |
self assert:( -0.6 asShortFloat roundedAsFloat = -1.0 ).
|
|
644 |
|
|
645 |
self assert:( 0.4 asLongFloat rounded ) class == SmallInteger.
|
|
646 |
self assert:( 0.4 asLongFloat rounded = 0 ).
|
|
647 |
self assert:( 0.5 asLongFloat rounded = 1 ).
|
|
648 |
self assert:( 0.6 asLongFloat rounded = 1 ).
|
|
649 |
self assert:( -0.4 asLongFloat rounded = 0 ).
|
|
650 |
self assert:( -0.5 asLongFloat rounded = -1 ).
|
|
651 |
self assert:( -0.6 asLongFloat rounded = -1 ).
|
|
652 |
|
|
653 |
self assert:( 0.4 asLongFloat roundedAsFloat ) class == LongFloat.
|
|
654 |
self assert:( 0.4 asLongFloat roundedAsFloat = 0.0 ).
|
|
655 |
self assert:( 0.5 asLongFloat roundedAsFloat = 1.0 ).
|
|
656 |
self assert:( 0.6 asLongFloat roundedAsFloat = 1.0 ).
|
|
657 |
self assert:( -0.4 asLongFloat roundedAsFloat = 0 ).
|
|
658 |
self assert:( -0.5 asLongFloat roundedAsFloat = -1.0 ).
|
|
659 |
self assert:( -0.6 asLongFloat roundedAsFloat = -1.0 ).
|
|
660 |
|
|
661 |
self assert:( 0.4 truncated ) class == SmallInteger.
|
|
662 |
self assert:( 0.4 truncated = 0 ).
|
|
663 |
self assert:( 0.5 truncated = 0 ).
|
|
664 |
self assert:( 0.6 truncated = 0 ).
|
|
665 |
self assert:( -0.4 truncated = 0 ).
|
|
666 |
self assert:( -0.5 truncated = 0 ).
|
|
667 |
self assert:( -0.6 truncated = 0 ).
|
|
668 |
|
|
669 |
self assert:( 0.4 truncatedAsFloat ) class == Float.
|
|
670 |
self assert:( 0.4 truncatedAsFloat = 0.0 ).
|
|
671 |
self assert:( 0.5 truncatedAsFloat = 0.0 ).
|
|
672 |
self assert:( 0.6 truncatedAsFloat = 0.0 ).
|
|
673 |
self assert:( -0.4 truncatedAsFloat = 0 ).
|
|
674 |
self assert:( -0.5 truncatedAsFloat = 0.0 ).
|
|
675 |
self assert:( -0.6 truncatedAsFloat = 0.0 ).
|
|
676 |
|
|
677 |
self assert:( 0.4 asShortFloat truncated ) class == SmallInteger.
|
|
678 |
self assert:( 0.4 asShortFloat truncated = 0 ).
|
|
679 |
self assert:( 0.5 asShortFloat truncated = 0 ).
|
|
680 |
self assert:( 0.6 asShortFloat truncated = 0 ).
|
|
681 |
self assert:( -0.4 asShortFloat truncated = 0 ).
|
|
682 |
self assert:( -0.5 asShortFloat truncated = 0 ).
|
|
683 |
self assert:( -0.6 asShortFloat truncated = 0 ).
|
|
684 |
|
|
685 |
self assert:( 0.4 asShortFloat truncatedAsFloat ) class == ShortFloat.
|
|
686 |
self assert:( 0.4 asShortFloat truncatedAsFloat = 0.0 ).
|
|
687 |
self assert:( 0.5 asShortFloat truncatedAsFloat = 0.0 ).
|
|
688 |
self assert:( 0.6 asShortFloat truncatedAsFloat = 0.0 ).
|
|
689 |
self assert:( -0.4 asShortFloat truncatedAsFloat = 0 ).
|
|
690 |
self assert:( -0.5 asShortFloat truncatedAsFloat = 0.0 ).
|
|
691 |
self assert:( -0.6 asShortFloat truncatedAsFloat = 0.0 ).
|
|
692 |
|
|
693 |
self assert:( 0.4 asLongFloat truncated ) class == SmallInteger.
|
|
694 |
self assert:( 0.4 asLongFloat truncated = 0 ).
|
|
695 |
self assert:( 0.5 asLongFloat truncated = 0 ).
|
|
696 |
self assert:( 0.6 asLongFloat truncated = 0 ).
|
|
697 |
self assert:( -0.4 asLongFloat truncated = 0 ).
|
|
698 |
self assert:( -0.5 asLongFloat truncated = 0 ).
|
|
699 |
self assert:( -0.6 asLongFloat truncated = 0 ).
|
|
700 |
|
|
701 |
self assert:( 0.4 asLongFloat truncatedAsFloat ) class == LongFloat.
|
|
702 |
self assert:( 0.4 asLongFloat truncatedAsFloat = 0.0 ).
|
|
703 |
self assert:( 0.5 asLongFloat truncatedAsFloat = 0.0 ).
|
|
704 |
self assert:( 0.6 asLongFloat truncatedAsFloat = 0.0 ).
|
|
705 |
self assert:( -0.4 asLongFloat truncatedAsFloat = 0 ).
|
|
706 |
self assert:( -0.5 asLongFloat truncatedAsFloat = 0.0 ).
|
|
707 |
self assert:( -0.6 asLongFloat truncatedAsFloat = 0.0 ).
|
|
708 |
|
|
709 |
"
|
|
710 |
self basicNew test07_Truncation
|
|
711 |
"
|
197
|
712 |
!
|
|
713 |
|
|
714 |
test08_Representation
|
|
715 |
self assert:( 0.0 exponent = 0 ).
|
|
716 |
self assert:( 1.0 exponent = 1 ).
|
|
717 |
self assert:( 2.0 exponent = 2 ).
|
|
718 |
self assert:( 3.0 exponent = 2 ).
|
|
719 |
self assert:( 4.0 exponent = 3 ).
|
|
720 |
self assert:( 0.5 exponent = 0 ).
|
|
721 |
self assert:( 0.4 exponent = -1 ).
|
|
722 |
self assert:( 0.25 exponent = -1 ).
|
|
723 |
self assert:( 0.125 exponent = -2 ).
|
|
724 |
self assert:( 0.00000011111 exponent = -23 ).
|
|
725 |
|
|
726 |
self assert:( 0.0 asShortFloat exponent = 0 ).
|
|
727 |
self assert:( 1.0 asShortFloat exponent = 1 ).
|
|
728 |
self assert:( 2.0 asShortFloat exponent = 2 ).
|
|
729 |
self assert:( 3.0 asShortFloat exponent = 2 ).
|
|
730 |
self assert:( 4.0 asShortFloat exponent = 3 ).
|
|
731 |
self assert:( 0.5 asShortFloat exponent = 0 ).
|
|
732 |
self assert:( 0.4 asShortFloat exponent = -1 ).
|
|
733 |
self assert:( 0.25 asShortFloat exponent = -1 ).
|
|
734 |
self assert:( 0.125 asShortFloat exponent = -2 ).
|
|
735 |
self assert:( 0.00000011111 asShortFloat exponent = -23 ).
|
|
736 |
|
|
737 |
self assert:( 0.0 asLongFloat exponent = 0 ).
|
|
738 |
self assert:( 1.0 asLongFloat exponent = 1 ).
|
|
739 |
self assert:( 2.0 asLongFloat exponent = 2 ).
|
|
740 |
self assert:( 3.0 asLongFloat exponent = 2 ).
|
|
741 |
self assert:( 4.0 asLongFloat exponent = 3 ).
|
|
742 |
self assert:( 0.5 asLongFloat exponent = 0 ).
|
|
743 |
self assert:( 0.4 asLongFloat exponent = -1 ).
|
|
744 |
self assert:( 0.25 asLongFloat exponent = -1 ).
|
|
745 |
self assert:( 0.125 asLongFloat exponent = -2 ).
|
|
746 |
self assert:( 0.00000011111 asLongFloat exponent = -23 ).
|
|
747 |
|
604
|
748 |
self assert:( LongFloat unity = 1 asLongFloat ).
|
|
749 |
self assert:( ShortFloat unity = 1 asShortFloat ).
|
|
750 |
self assert:( Float unity = 1 asFloat ).
|
|
751 |
|
197
|
752 |
"
|
|
753 |
self basicNew test08_Representation
|
|
754 |
"
|
604
|
755 |
|
|
756 |
"Modified: / 02-08-2011 / 18:34:39 / cg"
|
192
|
757 |
! !
|
|
758 |
|
|
759 |
!FloatTest class methodsFor:'documentation'!
|
|
760 |
|
|
761 |
version
|
|
762 |
^ '$Header$'
|
|
763 |
! !
|