math.functions, fix round for ratios between -1/2 and -1
it was outputting 1 instead of -1modern-harvey2
parent
acf14a7bd1
commit
271c7d9519
|
@ -173,6 +173,13 @@ CONSTANT: log10-factorial-1000 0x1.40f3593ed6f8ep11
|
||||||
{ 5.0 } [ 4.5 round ] unit-test
|
{ 5.0 } [ 4.5 round ] unit-test
|
||||||
{ 4.0 } [ 4.4 round ] unit-test
|
{ 4.0 } [ 4.4 round ] unit-test
|
||||||
|
|
||||||
|
{ -1 } [ -3/5 round ] unit-test
|
||||||
|
{ -1 } [ -1/2 round ] unit-test
|
||||||
|
{ 0 } [ -2/5 round ] unit-test
|
||||||
|
{ 0 } [ 2/5 round ] unit-test
|
||||||
|
{ 1 } [ 1/2 round ] unit-test
|
||||||
|
{ 1 } [ 3/5 round ] unit-test
|
||||||
|
|
||||||
{ 6 59967 } [ 3837888 factor-2s ] unit-test
|
{ 6 59967 } [ 3837888 factor-2s ] unit-test
|
||||||
{ 6 -59967 } [ -3837888 factor-2s ] unit-test
|
{ 6 -59967 } [ -3837888 factor-2s ] unit-test
|
||||||
|
|
||||||
|
|
|
@ -355,7 +355,7 @@ GENERIC: round ( x -- y )
|
||||||
M: integer round ; inline
|
M: integer round ; inline
|
||||||
|
|
||||||
M: ratio round
|
M: ratio round
|
||||||
>fraction [ /mod abs 2 * ] keep >= [ dup 0 < -1 1 ? + ] when ;
|
>fraction [ /mod dup abs 2 * ] keep >= [ 0 < -1 1 ? + ] [ drop ] if ;
|
||||||
|
|
||||||
M: float round dup sgn 2 /f + truncate ;
|
M: float round dup sgn 2 /f + truncate ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue