1 USING: kernel math math.floats.env math.floats.env.private
2 math.functions math.libm sequences 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+ swap member?
17 [ 1.0 3.0 / drop ] collect-fp-exceptions
18 +fp-inexact+ swap member?
22 [ 1.0e250 1.0e100 * drop ] collect-fp-exceptions
23 +fp-overflow+ swap member?
27 [ 1.0e-250 1.0e-100 * drop ] collect-fp-exceptions
28 +fp-underflow+ swap member?
32 [ 2.0 100,000.0 ^ drop ] collect-fp-exceptions
33 +fp-overflow+ swap member?
37 [ 2.0 -100,000.0 ^ drop ] collect-fp-exceptions
38 +fp-underflow+ swap member?
42 [ 0.0 0.0 /f drop ] collect-fp-exceptions
43 +fp-invalid-operation+ swap member?
47 [ -1.0 fsqrt drop ] collect-fp-exceptions
48 +fp-invalid-operation+ swap member?
52 HEX: 3fd5,5555,5555,5555
53 HEX: 3fc9,9999,9999,999a
54 HEX: bfc9,9999,9999,999a
55 HEX: bfd5,5555,5555,5555
58 1.0 3.0 /f double>bits
59 1.0 5.0 /f double>bits
60 -1.0 5.0 /f double>bits
61 -1.0 3.0 /f double>bits
66 HEX: 3fd5,5555,5555,5555
67 HEX: 3fc9,9999,9999,9999
68 HEX: bfc9,9999,9999,999a
69 HEX: bfd5,5555,5555,5556
72 1.0 3.0 /f double>bits
73 1.0 5.0 /f double>bits
74 -1.0 5.0 /f double>bits
75 -1.0 3.0 /f double>bits
80 HEX: 3fd5,5555,5555,5556
81 HEX: 3fc9,9999,9999,999a
82 HEX: bfc9,9999,9999,9999
83 HEX: bfd5,5555,5555,5555
86 1.0 3.0 /f double>bits
87 1.0 5.0 /f double>bits
88 -1.0 5.0 /f double>bits
89 -1.0 3.0 /f double>bits
94 HEX: 3fd5,5555,5555,5555
95 HEX: 3fc9,9999,9999,9999
96 HEX: bfc9,9999,9999,9999
97 HEX: bfd5,5555,5555,5555
100 1.0 3.0 /f double>bits
101 1.0 5.0 /f double>bits
102 -1.0 5.0 /f double>bits
103 -1.0 3.0 /f double>bits
107 ! ensure rounding mode is restored to +round-nearest+
109 HEX: 3fd5,5555,5555,5555
110 HEX: 3fc9,9999,9999,999a
111 HEX: bfc9,9999,9999,999a
112 HEX: bfd5,5555,5555,5555
114 1.0 3.0 /f double>bits
115 1.0 5.0 /f double>bits
116 -1.0 5.0 /f double>bits
117 -1.0 3.0 /f double>bits
120 [ { +fp-zero-divide+ } [ 1.0 0.0 /f ] with-fp-traps ] must-fail
121 [ { +fp-inexact+ } [ 1.0 3.0 /f ] with-fp-traps ] must-fail
122 [ { +fp-invalid-operation+ } [ -1.0 fsqrt ] with-fp-traps ] must-fail
123 [ { +fp-overflow+ } [ 2.0 100,000.0 ^ ] with-fp-traps ] must-fail
124 [ { +fp-underflow+ } [ 2.0 -100,000.0 ^ ] with-fp-traps ] must-fail
126 ! Ensure traps get cleared
127 [ 1/0. ] [ 1.0 0.0 /f ] unit-test
129 ! Ensure state is back to normal
130 [ +round-nearest+ ] [ rounding-mode ] unit-test
131 [ +denormal-keep+ ] [ denormal-mode ] unit-test
132 [ { } ] [ fp-traps ] unit-test
134 ! In case the tests screw up the FP env because of bugs in math.floats.env