POV-Ray : Newsgroups : povray.advanced-users : Negative division : Re: Negative division Server Time
29 Jul 2024 02:29:13 EDT (-0400)
  Re: Negative division  
From: Tor Olav Kristensen
Date: 9 Mar 2003 22:39:54
Message: <Xns933A2F6DE3518torolavkhotmailcom@204.213.191.226>
"Anders K." <and### [at] kaseorgcom> wrote in news:3e6bcf10@news.povray.org:

> Andrew Coppin wrote:
>> What do div() and mod() do in the case of negative
>> numerator/denominator? 
> 
> POV-Ray's answers are:
> 
> div(7, 3) = 2   mod(7, 3) = 1
> div(-7, 3) = -2   mod(-7, 3) = -1
> div(7, -3) = -2   mod(7, -3) = 1
> div(-7, -3) = 2   mod(-7, -3) = -1
> 
> whereas the correct answers are:
> 
> div(7, 3) = 2   mod(7, 3) = 1
> div(-7, 3) = -3   mod(-7, 3) = 2
> div(7, -3) = -2   mod(7, -3) = 1
> div(-7, -3) = 3   mod(-7, -3) = 2
>
> This has annoyed me a lot. If they fixed the broken gradient pattern, why
> can't they fix the equally broken div() and mod() functions?

I think that the implementation of these operators may differ
from system to system.

Therefore there might be no "correct answers" for negative and
fractional operands.


Note that both POV-Ray's answers and the "correct answers"
above make sure that:

div(N, D) * D + mod(N, D) = N

I.E.:

div( 7, 3) * 3 + mod( 7, 3) =   2 * 3 +  1 =   2 * 3 +  1 =   7
div(-7, 3) * 3 + mod(-7, 3) =  -2 * 3 + -1 =  -3 * 3 +  2 =  -7
div( 7,-3) *-3 + mod( 7,-3) =  -2 *-3 +  1 =  -2 *-3 +  1 =   7
div(-7,-3) *-3 + mod(-7,-3) =   2 *-3 + -1 =   3 *-3 +  2 =  -7


Maybe one should test if the rule also holds for fractional
numbers in POV-Ray.


Btw.: My Hewlett Packard calculator; HP48SX, says:

 7  3  MOD  ->  1
-7  3  MOD  ->  2
 7 -3  MOD  -> -2
-7 -3  MOD  -> -1

(It does not have a DIV operator.)


I just did a google search:
http://www.google.com/search?q=MOD+implementation+%22negative+numbers%22

- and found this:
http://mathforum.org/library/drmath/view/52343.html

(It seems to be very relevant, but I'm to tired to read it
right now.)


Tor Olav


Post a reply to this message

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