14 |
14 |
15 actualPrecisionOf:aFloatClass |
15 actualPrecisionOf:aFloatClass |
16 "get the actual number of valid bits in the mantissa. |
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)" |
17 This does a real test (i.e. does not believe the compiled-in ifdefs)" |
18 |
18 |
19 |one x count| |
19 |one x count two| |
20 |
20 |
21 one := aFloatClass unity. "/ 1.0 in this class |
21 one := aFloatClass unity. "/ 1.0 in this class |
|
22 two := one coerce:2.0. |
22 x := one. |
23 x := one. |
23 count := 0. |
24 count := 0. |
24 |
25 |
25 [one + x > one] whileTrue:[ |
26 [one + x > one] whileTrue:[ |
26 x := x / 2. |
27 x := x / two. |
27 count := count + 1. |
28 count := count + 1. |
28 ]. |
29 ]. |
29 ^ count |
30 ^ count |
30 |
31 |
31 " |
32 " |
39 |
40 |
40 test00_Precision |
41 test00_Precision |
41 "computed precision vs. assumed precision." |
42 "computed precision vs. assumed precision." |
42 |
43 |
43 |a b| |
44 |a b| |
44 |
|
45 self assert: (Float unity class == Float). |
|
46 self assert: (ShortFloat unity class == ShortFloat). |
|
47 self assert: (LongFloat unity class == LongFloat). |
|
48 |
|
49 self assert: (Float unity = 1.0). |
|
50 self assert: (ShortFloat unity = 1.0). |
|
51 self assert: (LongFloat unity = 1.0). |
|
52 |
|
53 self assert: (Float zero class == Float). |
|
54 self assert: (ShortFloat zero class == ShortFloat). |
|
55 self assert: (LongFloat zero class == LongFloat). |
|
56 |
|
57 self assert: (Float zero = 0.0). |
|
58 self assert: (ShortFloat zero = 0.0). |
|
59 self assert: (LongFloat zero = 0.0). |
|
60 |
45 |
61 self assert:( (a := Float precision) = (b := self actualPrecisionOf:Float)) |
46 self assert:( (a := Float precision) = (b := self actualPrecisionOf:Float)) |
62 description:('Float precision: %1 ~~ actual: %2' bindWith:a with:b). |
47 description:('Float precision: %1 ~~ actual: %2' bindWith:a with:b). |
63 self assert:( (a := ShortFloat precision) = (b := self actualPrecisionOf:ShortFloat)) |
48 self assert:( (a := ShortFloat precision) = (b := self actualPrecisionOf:ShortFloat)) |
64 description:('ShortFloat precision: %1 ~~ actual: %2' bindWith:a with:b). |
49 description:('ShortFloat precision: %1 ~~ actual: %2' bindWith:a with:b). |
344 |
329 |
345 self assert:( 1.0 asLongFloat / 1.0 ) class == LongFloat. |
330 self assert:( 1.0 asLongFloat / 1.0 ) class == LongFloat. |
346 self assert:( 1.0 asLongFloat / 1.0 asShortFloat ) class == LongFloat. |
331 self assert:( 1.0 asLongFloat / 1.0 asShortFloat ) class == LongFloat. |
347 self assert:( 1.0 asLongFloat / 1.0 asFloat ) class == LongFloat. |
332 self assert:( 1.0 asLongFloat / 1.0 asFloat ) class == LongFloat. |
348 self assert:( 1.0 asLongFloat / 1 ) class == LongFloat. |
333 self assert:( 1.0 asLongFloat / 1 ) class == LongFloat. |
|
334 |
|
335 self assert:( 1.0 / 2.0 ) class == Float. |
|
336 self assert:( 1.0 / 2.0 asShortFloat) class == Float. |
|
337 self assert:( 1.0 / 2.0 asLongFloat) class == LongFloat. |
|
338 self assert:( 1.0 / 2) class == Float. |
|
339 |
|
340 self assert:( 1.0 asShortFloat / 2.0 ) class == Float. |
|
341 self assert:( 1.0 asShortFloat / 2.0 asShortFloat) class == ShortFloat. |
|
342 self assert:( 1.0 asShortFloat / 2.0 asLongFloat) class == LongFloat. |
|
343 self assert:( 1.0 asShortFloat / 2) class == ShortFloat. |
|
344 |
|
345 self assert:( 1.0 asLongFloat / 2.0 ) class == LongFloat. |
|
346 self assert:( 1.0 asLongFloat / 2.0 asShortFloat ) class == LongFloat. |
|
347 self assert:( 1.0 asLongFloat / 2.0 asFloat ) class == LongFloat. |
|
348 self assert:( 1.0 asLongFloat / 2 ) class == LongFloat. |
349 |
349 |
350 self assert:( 5.0 rem: 2.0 ) class == Float. |
350 self assert:( 5.0 rem: 2.0 ) class == Float. |
351 self assert:( 5.0 rem: 2.0 asShortFloat) class == Float. |
351 self assert:( 5.0 rem: 2.0 asShortFloat) class == Float. |
352 self assert:( 5.0 rem: 2.0 asLongFloat) class == LongFloat. |
352 self assert:( 5.0 rem: 2.0 asLongFloat) class == LongFloat. |
353 self assert:( 5.0 rem: 2) class == Float. |
353 self assert:( 5.0 rem: 2) class == Float. |
747 self basicNew test07_Truncation |
747 self basicNew test07_Truncation |
748 " |
748 " |
749 ! |
749 ! |
750 |
750 |
751 test08_Representation |
751 test08_Representation |
|
752 self assert: (Float unity class == Float). |
|
753 self assert: (ShortFloat unity class == ShortFloat). |
|
754 self assert: (LongFloat unity class == LongFloat). |
|
755 |
|
756 self assert: (Float unity = 1.0). |
|
757 self assert: (ShortFloat unity = 1.0). |
|
758 self assert: (LongFloat unity = 1.0). |
|
759 |
|
760 self assert: (Float zero class == Float). |
|
761 self assert: (ShortFloat zero class == ShortFloat). |
|
762 self assert: (LongFloat zero class == LongFloat). |
|
763 |
|
764 self assert: (Float zero = 0.0). |
|
765 self assert: (ShortFloat zero = 0.0). |
|
766 self assert: (LongFloat zero = 0.0). |
|
767 |
|
768 self assert:( LongFloat unity = 1 asLongFloat ). |
|
769 self assert:( ShortFloat unity = 1 asShortFloat ). |
|
770 self assert:( Float unity = 1 asFloat ). |
|
771 |
752 self assert:( 0.0 exponent = 0 ). |
772 self assert:( 0.0 exponent = 0 ). |
753 self assert:( 1.0 exponent = 1 ). |
773 self assert:( 1.0 exponent = 1 ). |
754 self assert:( 2.0 exponent = 2 ). |
774 self assert:( 2.0 exponent = 2 ). |
755 self assert:( 3.0 exponent = 2 ). |
775 self assert:( 3.0 exponent = 2 ). |
756 self assert:( 4.0 exponent = 3 ). |
776 self assert:( 4.0 exponent = 3 ). |
780 self assert:( 0.4 asLongFloat exponent = -1 ). |
800 self assert:( 0.4 asLongFloat exponent = -1 ). |
781 self assert:( 0.25 asLongFloat exponent = -1 ). |
801 self assert:( 0.25 asLongFloat exponent = -1 ). |
782 self assert:( 0.125 asLongFloat exponent = -2 ). |
802 self assert:( 0.125 asLongFloat exponent = -2 ). |
783 self assert:( 0.00000011111 asLongFloat exponent = -23 ). |
803 self assert:( 0.00000011111 asLongFloat exponent = -23 ). |
784 |
804 |
785 self assert:( LongFloat unity = 1 asLongFloat ). |
|
786 self assert:( ShortFloat unity = 1 asShortFloat ). |
|
787 self assert:( Float unity = 1 asFloat ). |
|
788 |
|
789 " |
805 " |
790 self basicNew test08_Representation |
806 self basicNew test08_Representation |
791 " |
807 " |
792 |
808 |
793 "Modified: / 02-08-2011 / 18:34:39 / cg" |
809 "Modified: / 02-08-2011 / 18:34:39 / cg" |