POV-Ray : Newsgroups : povray.bugreports : calculus bug in PovRay3.1 : Re: calculus bug in PovRay3.1 Server Time
26 Jun 2024 05:57:46 EDT (-0400)
  Re: calculus bug in PovRay3.1  
From: Thorsten Froehlich
Date: 22 Jun 1999 08:17:09
Message: <376f7ec5@news.povray.org>
In article <376F47F5.89E8568D@ele.kth.se> , Uwe Zimmermann <uwe### [at] elekthse>
wrote:

> Hello List,
>
> yesterday I installed the 3.1e version of PovRay on my Windows NT4 sp3
> computer and discovered a bug in the mathematics part of PovRay:
>
> the mod(A,B) function is meant to provide the modulus of A divided by B.
> Per definition the modulus is a NON-NEGATIVE INTEGER value. However if
> you ask PovRay to perform modulus calculations with A being negative you
> get a negative result:
>
>                 PovRay        definition
>
> mod(0,5)          0                0        OK
> mod(1,5)          1                1        OK
> mod(2,5)          2                2        OK
> mod(3,5)          3                3        OK
> mod(4,5)          4                4        OK
> mod(5,5)          0                0        OK
> mod(6,5)          1                1        OK
> mod(7,5)          2                2        OK
>
> BUT
>
> mod(0,5)          0                0        OK
> mod(-1,5)        -1                4        WRONG
> mod(-2,5)        -2                3        WRONG
> mod(-3,5)        -3                2        WRONG
> mod(-4,5)        -4                1        WRONG
> mod(-5,5)         0                0        WRONG
> mod(-6,5)        -1                4        WRONG
> mod(-7,5)        -2                3        WRONG
>
> as I noticed this bug was already present in v3.0 of PovRay for win32
> and thus I'm wondering if it's a bug or a feature. At least it should be
> noted in the documentation that PovRay does not use the standard
> definition of the modulus calculation.

You are right that the C library fmod function (which the POV-Ray mod
function is based on) does not return the mathmatically defined values of a
modulus operation. This is simply the way this POV-Ray function is defined
(because of the internal representation of floating point numbers).


     Thorsten


Post a reply to this message

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