|
|
Thorsten Froehlich <tho### [at] trfde> wrote:
: Do you really think there is some code in there that says:
: "add 0.00000000298023224 to clock to annoy users"? ;-)
I was wondering if floats could *really* be that inaccurate. When I make
this with povray:
#debug concat(str(99/100,0,25), "\n")
what I get is:
0.9899999999999999911182158
(instead of 0.99). I though, "is this really possible?".
Then I wanted to be sure and I made a small C program which does basically
the same thing:
#include "stdio.h"
int main()
{
printf("%.25f\n", 99.0/100.0);
return 0;
}
This program prints, surprise surprise:
0.9899999999999999911182158
So now I am convinced that there's no bug in povray.
Of course, when making a scene file, one has to minimize the effects of
floating point inaccuracy.
For example, don't do it this way:
#declare Ind = 0;
#declare Clock = 0;
#while(Ind <= 100)
#debug concat("Clock: ", str(Clock,0,25), "\n")
#declare Clock = Clock+1/100;
#declare Ind = Ind+1;
#end
(The last number printed is 1.0000000000000006661338148.)
Instead, do it this way:
#declare Ind = 0;
#while(Ind <= 100)
#declare Clock = Ind/100;
#debug concat("Clock: ", str(Clock,0,25), "\n")
#declare Ind = Ind+1;
#end
(The last number printed is 1.0000000000000000000000000.)
The reason for the second code being better than the first is left as
an exercise to the reader.
--
#macro M(A,N,D,L)plane{-z,-9pigment{mandel L*9translate N color_map{[0rgb x]
[1rgb 9]}scale<D,D*3D>*1e3}rotate y*A*8}#end M(-3<1.206434.28623>70,7)M(
-1<.7438.1795>1,20)M(1<.77595.13699>30,20)M(3<.75923.07145>80,99)// - Warp -
Post a reply to this message
|
|