]> gitweb.factorcode.org Git - factor.git/blob - basis/math/floating-point/floating-point-tests.factor
Switch to https urls
[factor.git] / basis / math / floating-point / floating-point-tests.factor
1 ! Copyright (C) 2008 Doug Coleman.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: tools.test math.floating-point kernel
4 math.constants fry sequences math random ;
5 IN: math.floating-point.tests
6
7 { t } [ pi >double< >double pi = ] unit-test
8 { t } [ -1.0 >double< >double -1.0 = ] unit-test
9
10 { t } [ 1/0. infinity? ] unit-test
11 { t } [ -1/0. infinity? ] unit-test
12 { f } [ 0/0. infinity? ] unit-test
13 { f } [ 10. infinity? ] unit-test
14 { f } [ -10. infinity? ] unit-test
15 { f } [ 0. infinity? ] unit-test
16
17 { 0 } [ 0.0 double>ratio ] unit-test
18 { 1 } [ 1.0 double>ratio ] unit-test
19 { 1/2 } [ 0.5 double>ratio ] unit-test
20 { 3/4 } [ 0.75 double>ratio ] unit-test
21 { 12+1/2 } [ 12.5 double>ratio ] unit-test
22 { -12-1/2 } [ -12.5 double>ratio ] unit-test
23 { 3+39854788871587/281474976710656 } [ pi double>ratio ] unit-test
24
25 : roundtrip ( n -- )
26     [ '[ _ ] ] keep '[ _ double>ratio >float ] unit-test ;
27
28 { 1 12 123 1234 } [ bits>double roundtrip ] each
29
30 100 [ -10.0 10.0 uniform-random-float roundtrip ] times