From 271c7d951963de1e1f1c71e751bdc7903022e4bc Mon Sep 17 00:00:00 2001 From: Jon Harper Date: Sat, 25 Feb 2017 14:37:23 +0100 Subject: [PATCH] math.functions, fix round for ratios between -1/2 and -1 it was outputting 1 instead of -1 --- basis/math/functions/functions-tests.factor | 7 +++++++ basis/math/functions/functions.factor | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/basis/math/functions/functions-tests.factor b/basis/math/functions/functions-tests.factor index 0dec2a7345..31eeb4a0e0 100644 --- a/basis/math/functions/functions-tests.factor +++ b/basis/math/functions/functions-tests.factor @@ -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 diff --git a/basis/math/functions/functions.factor b/basis/math/functions/functions.factor index 26c5bbfc50..df994dc7b6 100644 --- a/basis/math/functions/functions.factor +++ b/basis/math/functions/functions.factor @@ -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 ;