POV-Ray : Newsgroups : povray.beta-test : Doc Error for mod? : Re: Doc Error for mod? Server Time
30 Jul 2024 10:12:43 EDT (-0400)
  Re: Doc Error for mod?  
From: Bob H 
Date: 23 Nov 2001 09:00:27
Message: <3bfe567b@news.povray.org>

news:3BFE5354.407A08EE@atosorigin.com...
> "Bob H." wrote:
> >
> > Not that I'd know or anything but I thought:  mod=A/B-int(A/B)
>
> That's wrong.
>
>  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 [...]).

Thanks, I needed a math lesson  :-)

> >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.

I see, but maybe you meant int(-2.5) would be -2 but I'd expect -2.8 to
become -3.  I only meant from 0.5, 1.5, 3.5, etc. would go toward 0.  Not
so?

> 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.

Scientific calculator says yes.  Respectively: +1, -1, -1.

Bob H.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.