]> gitweb.factorcode.org Git - factor.git/commitdiff
math.extras: simplify round-to-decimal
authorJohn Benediktsson <mrjbq7@gmail.com>
Fri, 1 Sep 2023 18:54:10 +0000 (11:54 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Fri, 1 Sep 2023 18:54:10 +0000 (11:54 -0700)
extra/math/extras/extras-tests.factor
extra/math/extras/extras.factor

index b42e7ab30635657ddf3044825be8b897fe9f594c..9addb2d590c3fd781a6ce319355705460a83b7ab 100644 (file)
@@ -99,8 +99,8 @@ tools.test ;
 { 3 } [ { 1 2 3 1 2 3 1 2 3 3 } majority ] unit-test
 { CHAR: C } [ "AAACCBBCCCBCC" majority ] unit-test
 
-{ 0.0 } [ 0 2 round-to-decimal ] unit-test
-{ 1.0 } [ 1 2 round-to-decimal ] unit-test
+{ 0.0 } [ 0.0 2 round-to-decimal ] unit-test
+{ 1.0 } [ 1.0 2 round-to-decimal ] unit-test
 { 1.23 } [ 1.2349 2 round-to-decimal ] unit-test
 { 1.24 } [ 1.2350 2 round-to-decimal ] unit-test
 { 1.24 } [ 1.2351 2 round-to-decimal ] unit-test
index 3232b991fb5cfc9cde6abe93cec1d5c0b14461c5..ed037547e9fcec29dca7f4a754f00568fde59c31 100644 (file)
@@ -257,7 +257,7 @@ PRIVATE>
     compression-lengths + / ;
 
 : round-to-decimal ( x n -- y )
-    10^ [ * 0.5 over 0 > [ + ] [ - ] if truncate ] [ / ] bi ;
+    10^ [ * round ] [ / ] bi ;
 
 : round-to-step ( x step -- y )
     [ [ / round ] [ * ] bi ] unless-zero ;