POV-Ray : Newsgroups : povray.general : #write losing accuracy : Re: #write losing accuracy Server Time
6 Oct 2024 09:43:10 EDT (-0400)
  Re: #write losing accuracy  
From: Kenneth
Date: 18 Mar 2014 04:25:01
Message: <web.532801e33187bc37c2d977c20@news.povray.org>
"FNH" <nomail@nomail> wrote:
> I've just used #write to write a variable with the value 11.23302 to a file,
> but when I open the resulting file it contains only 11.233 .
>

By default, POV-Ray writes only 6 significant figures (if that's the correct
phrase), at least in 32-bit POV-Ray.

Example:
#declare R = seed(52);
#fopen XYZ "test_file.txt" write
#write(XYZ,rand(R))
#fclose XYZ

..... this writes 0.943483

But this...
#write(XYZ,500 + rand(R))
..... writes 500.943 -- still 6 figures, with the final digit rounded off.

As Alain says, the way to get more decimal places is to use str()-- or vstr() if
you're writing vectors:

Like this:
#write(XYZ,str(500 + rand(R),0,12)
..... which writes 500.943482920049 -- 12 actual decimal places.

Or, for a vector,
#write(XYZ,"<",vstr(3,<rand(R),rand(R),rand(R)>,",",0,8),">") // 8 decimals
..... with the result being  <0.94348292,0.53555440,0.92402154>

As far as I know, #read reads back exactly what was written-- no more, no less.


Post a reply to this message

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