use bignum/f to get accurate division of fixnums >= 2^53 on 64-bit platforms
parent
07254fa823
commit
a7011fe087
|
@ -3,8 +3,8 @@
|
||||||
USING: accessors arrays assocs byte-arrays byte-vectors classes
|
USING: accessors arrays assocs byte-arrays byte-vectors classes
|
||||||
combinators definitions effects fry generic generic.single
|
combinators definitions effects fry generic generic.single
|
||||||
generic.standard hashtables io.binary io.streams.string kernel
|
generic.standard hashtables io.binary io.streams.string kernel
|
||||||
kernel.private math math.parser math.parser.private namespaces
|
kernel.private math math.integers.private math.parser math.parser.private
|
||||||
parser sbufs sequences splitting splitting.private strings
|
namespaces parser sbufs sequences splitting splitting.private strings
|
||||||
vectors words ;
|
vectors words ;
|
||||||
IN: hints
|
IN: hints
|
||||||
|
|
||||||
|
@ -141,3 +141,4 @@ M\ hashtable set-at { { object fixnum object } { object word object } } "special
|
||||||
|
|
||||||
\ string>integer { string fixnum } "specializer" set-word-prop
|
\ string>integer { string fixnum } "specializer" set-word-prop
|
||||||
|
|
||||||
|
\ bignum/f { { bignum bignum } { bignum fixnum } { fixnum bignum } { fixnum fixnum } } "specializer" set-word-prop
|
||||||
|
|
|
@ -226,3 +226,6 @@ unit-test
|
||||||
[ >float / ] [ /f ] 2bi 0.1 ~
|
[ >float / ] [ /f ] 2bi 0.1 ~
|
||||||
] all?
|
] all?
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
! Ensure that /f is accurate for fixnums > 2^53 on 64-bit platforms
|
||||||
|
[ HEX: 1.758bec11492f9p-54 ] [ 1 12345678901234567 /f ] unit-test
|
||||||
|
|
|
@ -33,7 +33,16 @@ M: fixnum + fixnum+ ; inline
|
||||||
M: fixnum - fixnum- ; inline
|
M: fixnum - fixnum- ; inline
|
||||||
M: fixnum * fixnum* ; inline
|
M: fixnum * fixnum* ; inline
|
||||||
M: fixnum /i fixnum/i ; inline
|
M: fixnum /i fixnum/i ; inline
|
||||||
M: fixnum /f [ >float ] dip >float float/f ; inline
|
|
||||||
|
DEFER: bignum/f
|
||||||
|
CONSTANT: bignum/f-threshold HEX: 20,0000,0000,0000
|
||||||
|
|
||||||
|
: fixnum/f ( m n -- m/n )
|
||||||
|
[ >float ] bi@ float/f ; inline
|
||||||
|
|
||||||
|
M: fixnum /f
|
||||||
|
2dup [ bignum/f-threshold >= ] either?
|
||||||
|
[ bignum/f ] [ fixnum/f ] if ; inline
|
||||||
|
|
||||||
M: fixnum mod fixnum-mod ; inline
|
M: fixnum mod fixnum-mod ; inline
|
||||||
|
|
||||||
|
@ -144,5 +153,8 @@ M: bignum (log2) bignum-log2 ; inline
|
||||||
] if-zero
|
] if-zero
|
||||||
] if ; inline
|
] if ; inline
|
||||||
|
|
||||||
M: bignum /f ( m n -- f )
|
: bignum/f ( m n -- f )
|
||||||
[ [ abs ] bi@ /f-abs ] [ [ 0 < ] bi@ xor ] 2bi [ neg ] when ;
|
[ [ abs ] bi@ /f-abs ] [ [ 0 < ] bi@ xor ] 2bi [ neg ] when ;
|
||||||
|
|
||||||
|
M: bignum /f ( m n -- f )
|
||||||
|
bignum/f ;
|
||||||
|
|
Loading…
Reference in New Issue