POV-Ray : Newsgroups : povray.advanced-users : Negative division : Re: Negative division Server Time
29 Jul 2024 08:23:56 EDT (-0400)
  Re: Negative division  
From: Anders K 
Date: 10 Mar 2003 21:58:44
Message: <3e6d50e4@news.povray.org>
I wrote:
> > div(7, 3) = 2
> > div(-7, 3) = -3
> > div(7, -3) = -2
> > div(-7, -3) = 3

Thorsten Froehlich wrote:
> How can the result possibly be +-3 for any of these?  No matter how you
> round, this makes only sense if you apply *different* rounding rules
> depending on the signs.  And doing so is nonsensical.

No, the formulas I'm using are very simple and consistent:
  div(a, b) = floor(a / b)
  mod(a, b) = a - div(a, b)
Where floor always rounds down to the nearest integer.

Instead of floor, POV-Ray is using trunc (which POV-Ray calls int, but
shouldn't), and trunc rounds up if a number's less than zero, and down if a
number's greater than zero. So it's POV-Ray's current behavior that uses
different rounding rules, and in your own words, is nonsensical.

Anders


Post a reply to this message

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