math.extras: adding round-to-step.
parent
dca20550ac
commit
fdc43d0574
|
@ -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
|
||||
|
|
|
@ -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 ;
|
||||
|
|
Loading…
Reference in New Issue