POV-Ray : Newsgroups : povray.general : mod() returns negative result Server Time
1 Aug 2024 12:20:26 EDT (-0400)
  mod() returns negative result (Message 1 to 4 of 4)  
From: Ard
Subject: mod() returns negative result
Date: 16 Nov 2005 17:50:01
Message: <web.437bb4dd9dd1bd8eed802ab30@news.povray.org>
POV's mod(-3, 10) returns -3.  I don't have a problem with the
documentation: mod() works as described, returning ((A/B)-int(A/B))*B where
int(A) is not further from 0 than A on a number line.

However I do think that POV's mod() should behave like Perl's, and with
common (I thought) practice, where mod(A,B) lies in the range [0,B) for all
positive B.

Compare the gradient pattern: it used to be mirrored about 0, but post-3.5,
it is a continuous saw-tooth.  This new behaviour is what I expect from
mod().

Behaviour for B<0 seems to be debated but for the far more common case of
B>0, I believe mod(A,B) should be >= 0 for all A.

I'm sure the mathematicians in the audience will have their own references,
but here is another: http://en.wikipedia.org/wiki/Modulo_arithmetic

Anybody agree?  Anybody care?


Post a reply to this message

From: John VanSickle
Subject: Re: mod() returns negative result
Date: 16 Nov 2005 18:14:14
Message: <437bbd46$1@news.povray.org>
Ard wrote:

> POV's mod(-3, 10) returns -3.  I don't have a problem with the
> documentation: mod() works as described, returning ((A/B)-int(A/B))*B where
> int(A) is not further from 0 than A on a number line.
> 
> However I do think that POV's mod() should behave like Perl's, and with
> common (I thought) practice, where mod(A,B) lies in the range [0,B) for all
> positive B.

In modulo arithmetic, numbers outside of the 0 to n-1 range simply 
aren't in the field.

It would be more precise to call it a remainder function.

Regards,
John


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: mod() returns negative result
Date: 16 Nov 2005 19:55:50
Message: <437bd516$1@news.povray.org>
Ard wrote:
> POV's mod(-3, 10) returns -3.  I don't have a problem with the
> documentation: mod() works as described, returning ((A/B)-int(A/B))*B where
> int(A) is not further from 0 than A on a number line.
> 
> However I do think that POV's mod() should behave like Perl's, and with
> common (I thought) practice, where mod(A,B) lies in the range [0,B) for all
> positive B.
> 
> Compare the gradient pattern: it used to be mirrored about 0, but post-3.5,
> it is a continuous saw-tooth.  This new behaviour is what I expect from
> mod().
> 
> Behaviour for B<0 seems to be debated but for the far more common case of
> B>0, I believe mod(A,B) should be >= 0 for all A.
> 
> I'm sure the mathematicians in the audience will have their own references,
> but here is another: http://en.wikipedia.org/wiki/Modulo_arithmetic
> 
> Anybody agree?  Anybody care?

POV-Ray follows what the ISO standards for C and C++ use as mod.

	Thorsten


Post a reply to this message

From: Dave Matthews
Subject: Re: mod() returns negative result
Date: 17 Nov 2005 14:30:01
Message: <web.437cd936244465928c7259570@news.povray.org>
"Ard" <ard### [at] waikatoacnz> wrote:
> Anybody agree?  Anybody care?

As someone who uses congruences modulo a positive integer quite a bit, I
also am used to thinking of mod(a,b) as returning the "principal value" of
the congruence class (i.e. the number 0 <= r < b), but the fixes are pretty
easy, albiet frustrating when you forget the POVRay definition.  And since
I don't use C, C++ or Perl, I can't comment on what's "better," or "more
common" from a programming point of view, though Thorsten's usually pretty
definitive on those questions.

Dave Matthews


Post a reply to this message

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