POV-Ray : Newsgroups : povray.general : #write losing accuracy Server Time
28 Dec 2024 09:24:58 EST (-0500)
  #write losing accuracy (Message 1 to 8 of 8)  
From: FNH
Subject: #write losing accuracy
Date: 16 Mar 2014 11:35:01
Message: <web.5325c39890dbb66f3ae3bdc70@news.povray.org>
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 .

Any ideas why that is?


Post a reply to this message

From: Stephen
Subject: Re: #write losing accuracy
Date: 16 Mar 2014 11:42:53
Message: <5325c67d@news.povray.org>
On 16/03/2014 3:30 PM, FNH 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 .
>
> Any ideas why that is?
>
>
Did you define the BINARY_WORD_TYPE?

See: 3.3.2.3.4 The write Directive

-- 
Regards
     Stephen

I solemnly promise to kick the next angle, I see.


Post a reply to this message

From: Warp
Subject: Re: #write losing accuracy
Date: 16 Mar 2014 12:47:54
Message: <5325d5b9@news.povray.org>
Stephen <mca### [at] aolcom> wrote:
> On 16/03/2014 3:30 PM, FNH 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 .
> >
> > Any ideas why that is?
> >
> >
> Did you define the BINARY_WORD_TYPE?

That will only write the integral part of the value as raw binary bytes.
It has nothing to do with the accuracy of the ascii representation of
floating point values.

-- 
                                                          - Warp


Post a reply to this message

From: Stephen
Subject: Re: #write losing accuracy
Date: 16 Mar 2014 14:49:01
Message: <5325f21d$1@news.povray.org>
On 16/03/2014 4:47 PM, Warp wrote:
> That will only write the integral part of the value as raw binary bytes.
> It has nothing to do with the accuracy of the ascii representation of
> floating point values.

Strike that, then. :-(

-- 
Regards
     Stephen

I solemnly promise to kick the next angle, I see.


Post a reply to this message

From: Alain
Subject: Re: #write losing accuracy
Date: 16 Mar 2014 16:57:58
Message: <53261056$1@news.povray.org>

> 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 .
>
> Any ideas why that is?
>
>
Just make sure that you actualy write up to 5 decimal places if you 
want/need 5 decimal places. Take a look at the str(A,L,P) function. make 
sure that P is at least 5.


Post a reply to this message

From: Kenneth
Subject: Re: #write losing accuracy
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

From: Kenneth
Subject: Re: #write losing accuracy
Date: 18 Mar 2014 04:40:01
Message: <web.532805a03187bc37c2d977c20@news.povray.org>
"Kenneth" <kdw### [at] gmailcom> wrote:

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

DAMN, I left off the final parenthesis there (even after double-checking my
syntax!!) Sorry! (It will cause POV-Ray to hard-crash... mea culpa...)

It should be...
#write(XYZ,str(500 + rand(R),0,12))


Post a reply to this message

From: Kenneth
Subject: Re: #write losing accuracy
Date: 18 Mar 2014 05:10:01
Message: <web.53280c883187bc37c2d977c20@news.povray.org>
"Kenneth" <kdw### [at] gmailcom> wrote:
> "Kenneth" <kdw### [at] gmailcom> wrote:
>
> >
> > Like this:
> > #write(XYZ,str(500 + rand(R),0,12)
> > ..... which writes 500.943482920049 -- 12 actual decimal places.
> >
>
> DAMN, I left off the final parenthesis there (even after double-checking my
> syntax!!) Sorry! (It will cause POV-Ray to hard-crash... mea culpa...)
>

Hmm, it actually doesn't crash, it just causes a fatal error.

(This *does* cause a crash:   #write(XYZ,500 + rand(R) // no final parenthesis


Post a reply to this message

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