math.extras: adding round-to-step.

db4
John Benediktsson 2013-04-01 17:04:07 -07:00
parent dca20550ac
commit fdc43d0574
2 changed files with 9 additions and 0 deletions

View File

@ -120,3 +120,9 @@ IN: math.extras.test
12345.6789012 12345.67890123 12345.678901235
}
} [ 12345.67890123456 -6 9 [a,b] [ round-to-decimal ] with map ] unit-test
{ 0 } [ 0 5 round-to-step ] unit-test
{ 0 } [ 1 5 round-to-step ] unit-test
{ 5 } [ 3 5 round-to-step ] unit-test
{ 10 } [ 12 5 round-to-step ] unit-test
{ 15 } [ 13 5 round-to-step ] unit-test

View File

@ -255,3 +255,6 @@ M: float round-to-even
: round-to-decimal ( x n -- y )
10^ [ * 0.5 over 0 > [ + ] [ - ] if truncate ] [ / ] bi ;
: round-to-step ( x step -- y )
[ [ / round ] [ * ] bi ] unless-zero ;