%
isn't defined. modulo
only works on integers. I want something equivalent to Javascript's modulo / c's fmod.
views:
163answers:
4
+1
A:
I don't know scheme, but mathematically you could do something like:
rem = num - trunc(num / mod) * mod;
So for a number like 2.5 mod 2 you would get:
2.5 - trunc(2.5 / 2) * 2
= 2.5 - trunc(1.25) * 2
= 2.5 - 1 * 2
= 2.5 - 2
= 0.5
Aaron
2009-11-06 19:11:36
A:
It looks like remainder is the word you want. From here:
(remainder -13 -4.0) -1.0
plinth
2009-11-06 19:16:47
it seems to not take floating point args as the 1st argument, still
Claudiu
2009-11-06 19:18:13
+1
A:
Here is the javascript equivalent, I believe, where n=dividend, d=divisor:
(let ((nOverD (/ n d)))
(let ((q (if (> nOverD 0.0) (floor nOverD) (ceiling nOverD))))
(- n (* d q))))
Claudiu
2009-11-06 20:54:53