help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: cell2csv (io package): Higher precision of floating point numbers?


From: Ozzy Lash
Subject: Re: cell2csv (io package): Higher precision of floating point numbers?
Date: Wed, 24 Aug 2016 10:40:48 -0500



On Wed, Aug 24, 2016 at 7:30 AM, Martin Kunz <address@hidden> wrote:
Not that many people need so much precision. Any idea what number of digits
are output by e.g., csvwrite ?

Easy enough to test:

a=[1,1.1,1.111111,1.11111111111111111],csvwrite("ones.csv",a)

creates a file that contains:

1,1.1,1.111111,1.111111111111111

i.e. a maximum of 16 significant digits. eps() is 2.2E-16, so csvwrite uses the full precision of double values. In the light of csvwrite's behaviour I would suggest

sprintf(tmp, "%.16g", c(i, j).double_value());

for the new cell2csv.cc .

If users do not need this precision and would like to keep files small, they can always round floating numbers to the desired precision prior to writing them to a file.

Cheers,

Martin


_______________________________________________
Help-octave mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/help-octave



You may need to increase the size of the tmp variable (right above the sprintf).  With a precision of 16 I think you could get values like:

x.xxxxxxxxxxxxxxxxE-xxx

which would have 23 characters plus the trailing null.  I'm not sure if it could get bigger than that.

Bill

reply via email to

[Prev in Thread] Current Thread [Next in Thread]