math.functions: speed up round (thanks Loryn Jenkins!)
parent
891f6fef36
commit
4c941e8996
|
@ -203,6 +203,11 @@ CONSTANT: log10-factorial-1000 0x1.40f3593ed6f8ep11
|
|||
[ -4.0 ] [ -4.0 floor ] unit-test
|
||||
[ -4.0 ] [ -4.0 ceiling ] unit-test
|
||||
|
||||
[ -5 ] [ -9/2 round ] unit-test
|
||||
[ -4 ] [ -22/5 round ] unit-test
|
||||
[ 5 ] [ 9/2 round ] unit-test
|
||||
[ 4 ] [ 22/5 round ] unit-test
|
||||
|
||||
[ -5.0 ] [ -4.5 round ] unit-test
|
||||
[ -4.0 ] [ -4.4 round ] unit-test
|
||||
[ 5.0 ] [ 4.5 round ] unit-test
|
||||
|
|
|
@ -362,7 +362,14 @@ M: real atan >float atan ; inline
|
|||
|
||||
: truncate ( x -- y ) dup 1 mod - ; inline
|
||||
|
||||
: round ( x -- y ) dup sgn 2 / + truncate ; inline
|
||||
GENERIC: round ( x -- y )
|
||||
|
||||
M: integer round ; inline
|
||||
|
||||
M: ratio round
|
||||
>fraction [ /mod abs 2 * ] keep >= [ dup 0 < -1 1 ? + ] when ;
|
||||
|
||||
M: float round dup sgn 2 /f + truncate ;
|
||||
|
||||
: floor ( x -- y )
|
||||
dup 1 mod
|
||||
|
|
Loading…
Reference in New Issue