POV-Ray : Newsgroups : povray.advanced-users : Negative division : Re: Negative division Server Time
29 Jul 2024 02:30:08 EDT (-0400)
  Re: Negative division  
From: Will W
Date: 10 Mar 2003 01:07:40
Message: <3e6c2bac@news.povray.org>
I've read yours and other comments here with interest.

In practical terms there is no general rule that can be applied to integer
division or the modulo operator with negative numbers. Mathematicians
currently favor a "truncate toward negative infinity" model while engineers
have traditionally favored a "truncate toward zero" model-- since the
engineers are the ones who built all the early compilers, their approach has
been dominant in computers. It's another one of those areas where the
mathemeticians yell "I'm right!" and the engineers yell back "You can be
dead right! Our way builds safer bridges!"

The most one can expect from an interpreter, compiler, or even a spreadsheet
when using these operations is that it be self-consistent. POV-Ray appears
to be self-consistent. I don't think it's any big thing that it departs from
mathematical purity-- it is in good company. Anyone who is going to get into
esoteric stuff like taking the modulus of negative numbers needs to test how
the platform they are working on implements that function. In the drug
dosage work I used to do with spreadsheets, I learned to look for other
approaches so that Quattro and Lotus 1-2-3 would give the same results. I'm
too new to ray tracing to know for sure, but I suspect that any division
operation on a negative number can be avoided by using a different approach.

At least POV-Ray's pow( ) function avoids the ambiguities of  -2^2, whose
"correct" answer is often compiler dependent. On whether the negation sign
is treated as a unary operator of highest precedence or as the equivalent of
multiplying by negative one, which is a lower precedence.


"Tor Olav Kristensen" <tor_olav_kCURLYAhotmail.com> wrote in message
news:Xns### [at] 204213191226...
> "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:

<snip good stuff>

> http://mathforum.org/library/drmath/view/52343.html
>
> (It seems to be very relevant, but I'm to tired to read it
> right now.)

It is very relevant, but keep in mind it is written by a mathematician and
doesn't present the engineering view.


--
Will Woodhull  <<NOT an engineer-- just an RN with some odd work history>>
Thornhenge, SW Oregon, USA
willl.at.thornhenge.net


Post a reply to this message

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