tags:

views:

163

answers:

4

% isn't defined. modulo only works on integers. I want something equivalent to Javascript's modulo / c's fmod.

+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
A: 

It looks like remainder is the word you want. From here:

(remainder -13 -4.0)      -1.0
plinth
it seems to not take floating point args as the 1st argument, still
Claudiu
+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
+1  A: 

The flonum library defines flmod, which does what you want. In Pilot Scheme:

(require rnrs/arithmetic/flonums-6)
(flmod pi (sqrt 2))
outis