math.functions, fix round for ratios between -1/2 and -1

it was outputting 1 instead of -1
modern-harvey2
Jon Harper 2017-02-25 14:37:23 +01:00 committed by John Benediktsson
parent acf14a7bd1
commit 271c7d9519
2 changed files with 8 additions and 1 deletions

View File

@ -173,6 +173,13 @@ CONSTANT: log10-factorial-1000 0x1.40f3593ed6f8ep11
{ 5.0 } [ 4.5 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

View File

@ -355,7 +355,7 @@ GENERIC: round ( x -- y )
M: integer round ; inline
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 ;