add infinity? and nan? to math.floating-point
parent
7d2ca36fad
commit
b11caac25f
|
@ -1,7 +1,17 @@
|
||||||
! Copyright (C) 2008 Doug Coleman.
|
! Copyright (C) 2008 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: tools.test math.floating-point math.constants kernel ;
|
USING: tools.test math.floating-point math.constants kernel
|
||||||
|
math.constants fry sequences kernel math ;
|
||||||
IN: math.floating-point.tests
|
IN: math.floating-point.tests
|
||||||
|
|
||||||
[ t ] [ pi >double< >double pi = ] unit-test
|
[ t ] [ pi >double< >double pi = ] unit-test
|
||||||
[ t ] [ -1.0 >double< >double -1.0 = ] unit-test
|
[ t ] [ -1.0 >double< >double -1.0 = ] unit-test
|
||||||
|
|
||||||
|
[ t ] [ 1/0. infinity? ] unit-test
|
||||||
|
[ t ] [ -1/0. infinity? ] unit-test
|
||||||
|
[ f ] [ 0/0. infinity? ] unit-test
|
||||||
|
[ f ] [ 10. infinity? ] unit-test
|
||||||
|
[ f ] [ -10. infinity? ] unit-test
|
||||||
|
[ f ] [ 0. infinity? ] unit-test
|
||||||
|
|
||||||
|
[ t ] [ 0/0. nan? ] unit-test
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
! Copyright (C) 2008 Doug Coleman.
|
! Copyright (C) 2008 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: kernel math sequences prettyprint math.parser io
|
USING: kernel math sequences prettyprint math.parser io
|
||||||
math.functions math.bitwise ;
|
math.functions math.bitwise combinators.short-circuit ;
|
||||||
IN: math.floating-point
|
IN: math.floating-point
|
||||||
|
|
||||||
: (double-sign) ( bits -- n ) -63 shift ; inline
|
: (double-sign) ( bits -- n ) -63 shift ; inline
|
||||||
|
@ -37,3 +37,17 @@ IN: math.floating-point
|
||||||
(double-mantissa-bits) >bin 52 CHAR: 0 pad-left
|
(double-mantissa-bits) >bin 52 CHAR: 0 pad-left
|
||||||
11 [ bl ] times print
|
11 [ bl ] times print
|
||||||
] tri ;
|
] tri ;
|
||||||
|
|
||||||
|
: nan? ( double -- ? )
|
||||||
|
double>bits
|
||||||
|
{
|
||||||
|
[ (double-exponent-bits) 11 on-bits = ]
|
||||||
|
[ (double-mantissa-bits) 0 > ]
|
||||||
|
} 1&& ;
|
||||||
|
|
||||||
|
: infinity? ( double -- ? )
|
||||||
|
double>bits
|
||||||
|
{
|
||||||
|
[ (double-exponent-bits) 11 on-bits = ]
|
||||||
|
[ (double-mantissa-bits) 0 = ]
|
||||||
|
} 1&& ;
|
||||||
|
|
Loading…
Reference in New Issue