]> gitweb.factorcode.org Git - factor.git/blob - basis/math/floats/half/half-tests.factor
classes.struct: moving to new/boa instead of <struct>/<struct-boa>
[factor.git] / basis / math / floats / half / half-tests.factor
1 USING: accessors alien.c-types alien.data classes.struct kernel
2 math math.floats.half math.order sequences specialized-arrays
3 tools.test ;
4 SPECIALIZED-ARRAY: half
5 IN: math.floats.half.tests
6
7 { 0x0000 } [  0.0  half>bits ] unit-test
8 { 0x8000 } [ -0.0  half>bits ] unit-test
9 { 0x3e00 } [  1.5  half>bits ] unit-test
10 { 0xbe00 } [ -1.5  half>bits ] unit-test
11 { 0x7c00 } [  1/0. half>bits ] unit-test
12 { 0xfc00 } [ -1/0. half>bits ] unit-test
13 { 0x7eaa } [ NAN: aaaaaaaaaaaaa half>bits ] unit-test
14
15 ! too-big floats overflow to infinity
16 { 0x7c00 } [   65536.0 half>bits ] unit-test
17 { 0xfc00 } [  -65536.0 half>bits ] unit-test
18 { 0x7c00 } [  131072.0 half>bits ] unit-test
19 { 0xfc00 } [ -131072.0 half>bits ] unit-test
20
21 ! too-small floats flush to zero
22 { 0x0000 } [  1.0e-9 half>bits ] unit-test
23 { 0x8000 } [ -1.0e-9 half>bits ] unit-test
24
25 {  0.0  } [ 0x0000 bits>half ] unit-test
26 { -0.0  } [ 0x8000 bits>half ] unit-test
27 {  1.5  } [ 0x3e00 bits>half ] unit-test
28 { -1.5  } [ 0xbe00 bits>half ] unit-test
29 {  1/0. } [ 0x7c00 bits>half ] unit-test
30 { -1/0. } [ 0xfc00 bits>half ] unit-test
31 {  3.0  } [ 0x4200 bits>half ] unit-test
32 {    t  } [ 0x7e00 bits>half fp-nan? ] unit-test
33
34 STRUCT: halves
35     { tom half }
36     { dick half }
37     { harry half }
38     { harry-jr half } ;
39
40 { 8 } [ halves heap-size ] unit-test
41
42 { 3.0 } [
43     halves new
44         3.0 >>dick
45     dick>>
46 ] unit-test
47
48 { half-array{ 1.0 2.0 3.0 1/0. -1/0. } }
49 [ { 1.0 2.0 3.0 1/0. -1/0. } half >c-array ] unit-test
50
51 { 0x1.0p-24 } [ 1 bits>half ] unit-test
52
53 { t } [
54     65536 <iota>
55     [ 0x7c01 0x7dff between? ] reject
56     [ 0xfc01 0xfdff between? ] reject
57     [ dup bits>half half>bits = ] all?
58 ] unit-test