POV-Ray : Newsgroups : povray.general : Possible bug or Error precision ? Server Time
1 Nov 2024 07:28:33 EDT (-0400)
  Possible bug or Error precision ? (Message 1 to 2 of 2)  
From: Manuel Mata
Subject: Possible bug or Error precision ?
Date: 3 Dec 2004 14:30:01
Message: <web.41b0bd3dc8e3c26193173ccd0@news.povray.org>
Hi guys.
I have all this code for making a little animation and i noted something
strange.
I'm developing a boolean macro that returns true when a float passed as
parameter is an "integer" value.

////////////////////////////////////////////////////////
#declare STEP=0.25;

#include "colors.inc"

#macro drawSpline(s,i,j,step)
   union{
   #local counter=i;
   #while(counter<=j)
      object{sphere{0 0.1 translate s(counter)}}
      isInteger(counter)//this only print a message
      #local counter=counter+step;
   #end
   }
#end

#macro isInteger(f)
   #debug concat("f:",str(f,0,2),"   floor(f):",str(floor(f),0,2),"
f-floor(f):",str(f-floor(f),0,2),"n")//last is a newline char
#end

#declare path=spline{
natural_spline
0,<-2,0,-1>
1,<1,0,-3>
2,<3,0,-1>
3,<2,0,2>
4,<-3,0,2>
}

object{drawSpline(path,0,4,STEP) pigment{Cyan}}
union{
   object{sphere{0 0.2 translate path(0)}}
   object{sphere{0 0.2 translate path(1)}}
   object{sphere{0 0.2 translate path(2)}}
   object{sphere{0 0.2 translate path(3)}}
   object{sphere{0 0.2 translate path(4)}}
   pigment{Yellow}
}

cylinder{0 x*1000 0.05 pigment{Red}}
cylinder{0 z*1000 0.05 pigment{Blue}}
cylinder{0 y*1000 0.05 pigment{Green}}
camera{location <-2,3,-5> look_at <0,0,0>}
light_source{<-5,3,-2>*1000 White*1.8}
light_source{<2,7,-5>*1000 White*0.8 shadowless}
plane{y 0 pigment{checker White,Gray80 scale 1}}
////////////////////////////////////////////////////////

When u render the scene u get some debug messages at the debug window.
With STEP=0.25 i see that floor(1) is 1.00 so f-floor(f) is 0.00 and works
fine
With STEP=0.1  i see that floor(1) is 0.00 so f-floor(f) is 1.00 and should
be 0.00



I really don't know why.
A bug, my fault ?

                         Manuel Mata
                         http://www.ignorancia.org/mmata


Post a reply to this message

From: Mike Raiford
Subject: Re: Possible bug or Error precision ?
Date: 3 Dec 2004 15:47:10
Message: <41b0d0ce$1@news.povray.org>
Manuel Mata wrote:
  <Snipped Long Code Listing>

Simple floating point precesion error. If you set the starting value to 
a very small positive number you get the expected results


-- 
~Mike


Post a reply to this message

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