From e36ba8b90da10ef8351353a7d10b006e3af58b65 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Wed, 20 Mar 2013 17:42:47 -0700 Subject: [PATCH] math.floats: Fix the output of /mod and add some unit tests. Fixes #803. --- core/math/floats/floats-tests.factor | 9 +++++++++ core/math/floats/floats.factor | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/core/math/floats/floats-tests.factor b/core/math/floats/floats-tests.factor index ae72aba67f..d8d4e03b0f 100644 --- a/core/math/floats/floats-tests.factor +++ b/core/math/floats/floats-tests.factor @@ -93,3 +93,12 @@ unit-test [ 5.0 ] [ 3 5.0 max ] unit-test [ 3 ] [ 3 5.0 min ] unit-test + +{ 39 0x1.999999999998ap-4 } [ 4.0 .1 /mod ] unit-test +{ 38 0x1.9999999999984p-4 } [ 3.9 .1 /mod ] unit-test +{ 39 0x1.999999999998ap-4 } [ 4.0 -.1 /mod ] unit-test +{ 38 0x1.9999999999984p-4 } [ 3.9 -.1 /mod ] unit-test +{ 39 -0x1.999999999998ap-4 } [ -4.0 -.1 /mod ] unit-test +{ 38 -0x1.9999999999984p-4 } [ -3.9 -.1 /mod ] unit-test +{ 39 -0x1.999999999998ap-4 } [ -4.0 .1 /mod ] unit-test +{ 38 -0x1.9999999999984p-4 } [ -3.9 .1 /mod ] unit-test diff --git a/core/math/floats/floats.factor b/core/math/floats/floats.factor index 3fa9be4cad..58f40d2ffc 100644 --- a/core/math/floats/floats.factor +++ b/core/math/floats/floats.factor @@ -38,7 +38,7 @@ M: float /i float/f >integer ; inline M: real abs dup 0 < [ neg ] when ; inline -M: real /mod [ /i ] [ mod ] 2bi ; inline +M: real /mod dupd mod [ [ - ] [ /i ] bi ] keep ; inline M: float fp-special? double>bits -52 shift 0x7ff [ bitand ] keep = ; inline