Oh Dear

Michiel Helvensteijn m.helvensteijn.remove at gmail.com
Sun Jul 12 14:59:43 PDT 2009


Andrei Alexandrescu wrote:

> \dee\ also defines modulus for  floating-point numbers in the same way
> as the  IEEE~754  standard.  When  at least one  of @a@  and @b@  is a
> floating-point value in \cc{a \%  b}, the result is the floating-point
> number @r@ satisfying the relation \cc{a = b * n + r}, where @n@ is an
> integer\footnote{``integer'' in  the mathematical sense  here} and @r@
> is a positive number less than @b@'s absolute value.

Oh, about this part. I left it out because it's not about integer division,
but while I'm at it anyway.

I believe you wanted the word "non-negative" there, instead of "positive".
However, I just ran the following test:

----------------------------
writefln(5.0%2.0);
writefln(5.0%(-2.0));
writefln((-5.0)%2.0);
writefln((-5.0)%(-2.0));
----------------------------

it outputs:

----------
1
1
-1
-1
----------

So the remainder can still become negative, it seems. Same as with integer
modulo. I would expect this consistency, but your paragraph there says
something different.

-- 
Michiel Helvensteijn




More information about the Digitalmars-d mailing list