|
![](/i/fill.gif) |
"Bob H." wrote:
>
> "Tom Melly" <tom### [at] tomandlu co uk> wrote in message
> news:3bfe2478@news.povray.org...
> > The docs refer to mod(A, B) as:
> > Formula is mod=((A/B)-int(A/B))*B
That's correct.
> >
> > Shouldn't that be:
> > Formula is mod=A-(int(A/B)*B)
>
That's also correct.
> Not that I'd know or anything but I thought: mod=A/B-int(A/B)
That's wrong.
> For instance, if A=3 and B=2 that would get you the modulus 0.5;
Wrong, again.
3 mod 2 is 1
You cannot change that fact.
(more exactly, the fact is that 3 = 1 when considering modulo 2,
in fact 15 = 1 too [modulo 2], and mathematicaly 15 = 3 also [...]).
>so long as
> int() rounds down anyway.
Dependant on what you call down.
int keeps only the integer part. So,it's really down for positive numbers,
but it's a kind of up for negative numbers ( int(-2.8) = -2 ).
The formula given in the doc is fine using int() as it probably is
derived from the coding.
There is usually a catch with modulo operation with negative numbers,
at least in most computer implementation. I did not test the resulting value
for:
mod(-3,2)
mod(3,-2)
mod(-3,-2)
But I suspect they give some negative values as most langage do.
Post a reply to this message
|
![](/i/fill.gif) |