1 USING: kernel math math.floats.env math.floats.env.private
2 math.functions math.libm sets tools.test ;
3 IN: math.floats.env.tests
5 : set-default-fp-env ( -- )
6 { } { } +round-nearest+ +denormal-keep+ set-fp-env ;
8 ! In case the tests screw up the FP env because of bugs in math.floats.env
12 [ 1.0 0.0 / drop ] collect-fp-exceptions
13 { +fp-zero-divide+ } set=
17 [ 1.0 3.0 / drop ] collect-fp-exceptions
22 [ 2.0 100,000.0 ^ drop ] collect-fp-exceptions
23 { +fp-inexact+ +fp-overflow+ } set=
27 [ 2.0 -100,000.0 ^ drop ] collect-fp-exceptions
28 { +fp-inexact+ +fp-underflow+ } set=
32 [ -1.0 fsqrt drop ] collect-fp-exceptions
33 { +fp-invalid-operation+ } set=
37 HEX: 3fd5,5555,5555,5555
38 HEX: 3fc9,9999,9999,999a
39 HEX: bfc9,9999,9999,999a
40 HEX: bfd5,5555,5555,5555
43 1.0 3.0 /f double>bits
44 1.0 5.0 /f double>bits
45 -1.0 5.0 /f double>bits
46 -1.0 3.0 /f double>bits
51 HEX: 3fd5,5555,5555,5555
52 HEX: 3fc9,9999,9999,9999
53 HEX: bfc9,9999,9999,999a
54 HEX: bfd5,5555,5555,5556
57 1.0 3.0 /f double>bits
58 1.0 5.0 /f double>bits
59 -1.0 5.0 /f double>bits
60 -1.0 3.0 /f double>bits
65 HEX: 3fd5,5555,5555,5556
66 HEX: 3fc9,9999,9999,999a
67 HEX: bfc9,9999,9999,9999
68 HEX: bfd5,5555,5555,5555
71 1.0 3.0 /f double>bits
72 1.0 5.0 /f double>bits
73 -1.0 5.0 /f double>bits
74 -1.0 3.0 /f double>bits
79 HEX: 3fd5,5555,5555,5555
80 HEX: 3fc9,9999,9999,9999
81 HEX: bfc9,9999,9999,9999
82 HEX: bfd5,5555,5555,5555
85 1.0 3.0 /f double>bits
86 1.0 5.0 /f double>bits
87 -1.0 5.0 /f double>bits
88 -1.0 3.0 /f double>bits
92 ! ensure rounding mode is restored to +round-nearest+
94 HEX: 3fd5,5555,5555,5555
95 HEX: 3fc9,9999,9999,999a
96 HEX: bfc9,9999,9999,999a
97 HEX: bfd5,5555,5555,5555
99 1.0 3.0 /f double>bits
100 1.0 5.0 /f double>bits
101 -1.0 5.0 /f double>bits
102 -1.0 3.0 /f double>bits
105 [ { +fp-zero-divide+ } [ 1.0 0.0 /f ] with-fp-traps ] must-fail
106 [ { +fp-inexact+ } [ 1.0 3.0 /f ] with-fp-traps ] must-fail
107 [ { +fp-invalid-operation+ } [ -1.0 fsqrt ] with-fp-traps ] must-fail
108 [ { +fp-overflow+ } [ 2.0 100,000.0 ^ ] with-fp-traps ] must-fail
109 [ { +fp-underflow+ } [ 2.0 -100,000.0 ^ ] with-fp-traps ] must-fail
111 ! Ensure traps get cleared
112 [ 1/0. ] [ 1.0 0.0 /f ] unit-test
114 ! Ensure state is back to normal
115 [ +round-nearest+ ] [ rounding-mode ] unit-test
116 [ +denormal-keep+ ] [ denormal-mode ] unit-test
117 [ { } ] [ fp-traps ] unit-test
119 ! In case the tests screw up the FP env because of bugs in math.floats.env