POV-Ray : Newsgroups : povray.beta-test : while bug ? Server Time
4 Nov 2024 19:21:45 EST (-0500)
  while bug ? (Message 1 to 10 of 27)  
Goto Latest 10 Messages Next 10 Messages >>>
From: Mael
Subject: while bug ?
Date: 10 Oct 2001 04:12:39
Message: <3bc402f7$1@news.povray.org>
#local i=0;
#while (i<1)
  #debug concat(str(i,0,2),"\n")
  #local i=i+0.1;
#end

gives
0.00
0.10
0.20
0.30
0.40
0.50
0.60
0.70
0.80
0.90
1.00

is the1.00 normal ???
if we change i=i+0.1 into i=i+0.2 it stops at 0.8

povray3.5b6 win2000 Athlon 900MHz 256MB

M


Post a reply to this message

From: ingo
Subject: Re: while bug ?
Date: 10 Oct 2001 05:18:40
Message: <Xns9136730FC78FDseed7@povray.org>
in news:3bc402f7$1@news.povray.org Mael wrote:

> is the1.00 normal ???
> if we change i=i+0.1 into i=i+0.2 it stops at 0.8
> 

Same happens in 3.1g

Ingo

-- 
Photography: http://members.home.nl/ingoogni/
Pov-Ray    : http://members.home.nl/seed7/


Post a reply to this message

From: Ron Parker
Subject: Re: while bug ?
Date: 10 Oct 2001 08:00:15
Message: <slrn9s8e2f.9hj.ron.parker@fwi.com>
On 10 Oct 2001 05:18:40 -0400, ingo wrote:
>in news:3bc402f7$1@news.povray.org Mael wrote:
>
>> is the1.00 normal ???
>> if we change i=i+0.1 into i=i+0.2 it stops at 0.8
>> 
>
>Same happens in 3.1g

It's roundoff error.  I is probably .9999999 or so for the last iteration,
but it gets rounded for output.

-- 
#macro R(L P)sphere{L F}cylinder{L P F}#end#macro P(V)merge{R(z+a z)R(-z a-z)R(a
-z-z-z a+z)torus{1F clipped_by{plane{a 0}}}translate V}#end#macro Z(a F T)merge{
P(z+a)P(z-a)R(-z-z-x a)pigment{rgbt 1}hollow interior{media{emission T}}finish{
reflection.1}}#end Z(-x-x.2y)Z(-x-x.4x)camera{location z*-10rotate x*90}


Post a reply to this message

From: Mael
Subject: Re: while bug ?
Date: 10 Oct 2001 08:30:07
Message: <3bc43f4f@news.povray.org>
> It's roundoff error.  I is probably .9999999 or so for the last iteration,
> but it gets rounded for output.

isn t it strange to get a roundoff error for only 10 additions  ? i thought
pov was more precise :(

M


Post a reply to this message

From: Francois Labreque
Subject: Re: while bug ?
Date: 10 Oct 2001 08:39:10
Message: <3BC4411A.7060206@videotron.ca>
Mael wrote:

>>It's roundoff error.  I is probably .9999999 or so for the last iteration,
>>but it gets rounded for output.
>>
> 
> isn t it strange to get a roundoff error for only 10 additions  ? i thought
> pov was more precise :(
> 
> M
> 


You can get roundoff error with only one addition.  It comes from the 
fact that floating point numbers can not always be converted between 
base2 and base10 without roundoff.


To see what happens, you have to modify your code to show all the 
decimal places, like this:

#local i=0;
#while (i<1)
   #debug concat(str(i,0,17),"\n")
   #local i=i+0.1;
#end


Which (on my machine) produces:

0.00000000000000000
0.10000000000000001
0.20000000000000001
0.30000000000000004
0.40000000000000002
0.50000000000000000
0.59999999999999998
0.69999999999999996
0.79999999999999993
0.89999999999999991
0.99999999999999989

-- 
/*Francois Labreque*/#local a=x+y;#local b=x+a;#local c=a+b;#macro P(F//
/*    flabreque    */L)polygon{5,F,F+z,L+z,L,F pigment{rgb 9}}#end union
/*        @        */{P(0,a)P(a,b)P(b,c)P(2*a,2*b)P(2*b,b+c)P(b+c,<2,3>)
/*   videotron.ca  */}camera{location<6,1.25,-6>look_at a orthographic}


Post a reply to this message

From: Mael
Subject: Re: while bug ?
Date: 10 Oct 2001 08:46:21
Message: <3bc4431d$1@news.povray.org>
ok, thank you, it's clear.. we can't trust computers for maths :)
i'll change the test in the loop to avoid this

M


Post a reply to this message

From: Ron Parker
Subject: Re: while bug ?
Date: 10 Oct 2001 08:54:04
Message: <slrn9s8h7d.9kj.ron.parker@fwi.com>
On Wed, 10 Oct 2001 14:50:11 +0200, Mael wrote:
>ok, thank you, it's clear.. we can't trust computers for maths :)

The problem is that .1 in decimal is a repeating fraction in binary, so it
can never be represented precisely,  just as 1/3 is a repeating fraction in
decimal (but terminates in base 3.)

-- 
#macro R(L P)sphere{L F}cylinder{L P F}#end#macro P(V)merge{R(z+a z)R(-z a-z)R(a
-z-z-z a+z)torus{1F clipped_by{plane{a 0}}}translate V}#end#macro Z(a F T)merge{
P(z+a)P(z-a)R(-z-z-x a)pigment{rgbt 1}hollow interior{media{emission T}}finish{
reflection.1}}#end Z(-x-x.2y)Z(-x-x.4x)camera{location z*-10rotate x*90}


Post a reply to this message

From: Anders K 
Subject: Re: while bug ?
Date: 10 Oct 2001 08:59:42
Message: <3bc4463e$1@news.povray.org>
> #local i=0;
> #while (i<1)
>   #debug concat(str(i,0,2),"\n")
>   #local i=i+0.1;
> #end

Try

#local i = 0;
#while (i < 10)
  #debug concat(str(i/10, 0, 2), "\n")
  #local i = i + 1;
#end

Since there is no round off error with adding integers.


Post a reply to this message

From: Francois Labreque
Subject: Re: while bug ?
Date: 10 Oct 2001 09:03:49
Message: <3BC446E1.3090107@videotron.ca>
Mael wrote:

> ok, thank you, it's clear.. we can't trust computers for maths :)


Yes we can.  As long as we remembers that computers do not have the same 
number of fingers to count on.

-- 
/*Francois Labreque*/#local a=x+y;#local b=x+a;#local c=a+b;#macro P(F//
/*    flabreque    */L)polygon{5,F,F+z,L+z,L,F pigment{rgb 9}}#end union
/*        @        */{P(0,a)P(a,b)P(b,c)P(2*a,2*b)P(2*b,b+c)P(b+c,<2,3>)
/*   videotron.ca  */}camera{location<6,1.25,-6>look_at a orthographic}


Post a reply to this message

From: Warp
Subject: Re: while bug ?
Date: 10 Oct 2001 09:55:02
Message: <3bc45335@news.povray.org>
Mael <mae### [at] hotmailcom> wrote:
: isn t it strange to get a roundoff error for only 10 additions  ? i thought
: pov was more precise :(

  0.1 can't be represented accurately with binary floating point format.

  The reason is the same as why 1/3 can't be represented accurately with
decimal format.

-- 
#macro N(D,I)#if(I<6)cylinder{M()#local D[I]=div(D[I],104);M().5,2pigment{
rgb M()}}N(D,(D[I]>99?I:I+1))#end#end#macro M()<mod(D[I],13)-6,mod(div(D[I
],13),8)-3,10>#end blob{N(array[6]{11117333955,
7382340,3358,3900569407,970,4254934330},0)}//                     - Warp -


Post a reply to this message

Goto Latest 10 Messages Next 10 Messages >>>

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