On Wed, Apr 27, 2011 at 13:41, Erik Eckhardt <

erik@...> wrote:

> That was a singularly unhelpful (and possibly insulting) reply.

More importantly, it was incorrect. ECMA-262 says:

"If the dividend is a zero and the divisor is finite, the result is

the same as the dividend.

In the remaining cases, where neither an infinity, nor a zero, nor NaN

is involved, the

floating-point remainder r from a dividend n and a divisor d is

defined by the mathematical

relation r = n − (d * q) where q is an integer that is negative only

if n/d is negative and

positive only if n/d is positive, and whose magnitude is as large as

possible without

exceeding the magnitude of the true mathematical quotient of n and d."

So r = n - (d * q)

but we know d = 1, so r = n - q where q is an integer as big as it can

be without exceeding n.

Hence r = n - Math.floor(n). Which is what I'd write, because I hate

'clever' code.

mathew

--

<URL:

http://www.pobox.com/~meta/>