POV-Ray : Newsgroups : povray.beta-test : Doc Error for mod? Server Time
30 Jul 2024 08:19:18 EDT (-0400)
  Doc Error for mod? (Message 1 to 9 of 9)  
From: Tom Melly
Subject: Doc Error for mod?
Date: 23 Nov 2001 05:27:04
Message: <3bfe2478@news.povray.org>
The docs refer to mod(A, B) as:
Formula is mod=((A/B)-int(A/B))*B

Shouldn't that be:
Formula is mod=A-(int(A/B)*B)

--
#macro G(D,E,F)#local I=array[3]{D,E,F}#local B=0;triangle{#while(
B<3)#while(I[B])A[mod(I[B],10)]+#local I[B]=div(I[B],10);#end<-5,-
2,9>#local B=B+1;#end}#end #local A=array[7]{x,x*2,x*4,y,y*2,y*4,z
}light_source{-x*6-z*9,1}mesh{G(105,10,146)G(105,246,10)G(105,56,
146)G(105,1256,246)G(1256,126,220)G(22156,2216,201)pigment{rgb 1}}//TM


Post a reply to this message

From: Bob H 
Subject: Re: Doc Error for mod?
Date: 23 Nov 2001 08:16:00
Message: <3bfe4c10@news.povray.org>
"Tom Melly" <tom### [at] tomandlucouk> 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
>
> Shouldn't that be:
> Formula is mod=A-(int(A/B)*B)

Not that I'd know or anything but I thought:  mod=A/B-int(A/B)
For instance, if A=3 and B=2 that would get you the modulus 0.5; so long as
int() rounds down anyway.

Bob H.


Post a reply to this message

From: Jérôme Grimbert
Subject: Re: Doc Error for mod?
Date: 23 Nov 2001 08:45:38
Message: <3BFE5354.407A08EE@atosorigin.com>
"Bob H." wrote:
> 
> "Tom Melly" <tom### [at] tomandlucouk> 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

From: Bob H 
Subject: Re: Doc Error for mod? (nevermind me)
Date: 23 Nov 2001 08:49:51
Message: <3bfe53ff@news.povray.org>
"Bob H." <omn### [at] msncom> wrote in message
news:3bfe4c10@news.povray.org...
> "Tom Melly" <tom### [at] tomandlucouk> 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
> >
> > Shouldn't that be:
> > Formula is mod=A-(int(A/B)*B)
>
> Not that I'd know or anything but I thought:  mod=A/B-int(A/B)
> For instance, if A=3 and B=2 that would get you the modulus 0.5; so long
as
> int() rounds down anyway.

Well, chalk another lesson up for me.  One of those obscure mathematical
things to me, I always think modulus gets you just a (decimal) remainder
after division.  Looking it up I see it could be a whole number or at least
1 anyhow.  Still, seems that if you do either the Doc formula or yours, Tom,
that it comes out the same.  Just I'm not not %100 sure.

In fact what I said is probably, simply put, a "remainder" only whereas
modulus is another matter.  So please excuse my ignorance.  Thank you  :-)

Bob H.


Post a reply to this message

From: Bob H 
Subject: Re: Doc Error for mod?
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

From: Jérôme Grimbert
Subject: Re: Doc Error for mod?
Date: 23 Nov 2001 09:32:57
Message: <3BFE5E76.B3090531@atosorigin.com>
"Bob H." wrote:

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

No. 
int stand for "integer part". So int(2.99999999) is still 2, even if
it is dam close to 3.
(Ok, 2. and an infinity of 9 is really 3, but computer have a problem
with handling infinity that always I surprise me :-).

You're thinking of the 'nearest integer' rounding, which can be done with
int() too:  near(a) = int(a+0.5)
(And still, some may want to round x.5 toward x rather than x+1,
so it can still provide more discussion about using int or floor or ceil
 [because of the different rounding direction for positive/negative]).

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

YMMV, according to the library used, so beware when having negative numbers.
 (or when comparing results)

> 
> Bob H.


Post a reply to this message

From: Tom Melly
Subject: Re: Doc Error for mod?
Date: 23 Nov 2001 11:41:59
Message: <3bfe7c57@news.povray.org>

news:3BFE5354.407A08EE@atosorigin.com...
> "Bob H." wrote:

> >
> > "Tom Melly" <tom### [at] tomandlucouk> 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.
>

Oh, good. I mean, I'm still confused, but good, as in good, the docs aren't
wrong...


Post a reply to this message

From: Anders K 
Subject: Re: Doc Error for mod?
Date: 23 Nov 2001 12:16:20
Message: <3bfe8464$1@news.povray.org>
> The docs refer to mod(A, B) as:
> Formula is mod=((A/B)-int(A/B))*B
>
> Shouldn't that be:
> Formula is mod=A-(int(A/B)*B)

Those formulas are exactly the same. (A/B)*B = A.


Post a reply to this message

From: Bob H 
Subject: Re: Doc Error for mod?
Date: 23 Nov 2001 20:25:59
Message: <3bfef727@news.povray.org>

news:3BFE5E76.B3090531@atosorigin.com...
> "Bob H." wrote:
> > 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?
>
> No.
> int stand for "integer part". So int(2.99999999) is still 2, even if
> it is dam close to 3.
> (Ok, 2. and an infinity of 9 is really 3, but computer have a problem
> with handling infinity that always I surprise me :-).
>
> You're thinking of the 'nearest integer' rounding, which can be done with
> int() too:  near(a) = int(a+0.5)
> (And still, some may want to round x.5 toward x rather than x+1,
> so it can still provide more discussion about using int or floor or ceil
>  [because of the different rounding direction for positive/negative]).

Okay, got it.  Enough of my blindly thinking int() was rounding up and down
based on which side of halfway between whole numbers then.  Thanks for
clearing that up for me.  One of those things I get stuck in my mind some
way and never question (unless problem arises).

Very good point about negatives being opposite direction, sort of, for
rounding; or toward zero like the doc says.

Bob H.


Post a reply to this message

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