|
![](/i/fill.gif) |
"Anders K." <and### [at] kaseorg com> 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
|
![](/i/fill.gif) |