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: Martin Kunz
Subject: Re: cell2csv (io package): Higher precision of floating point numbers?
Date: Wed, 24 Aug 2016 13:29:55 +0200
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0

Hi Philip,

Thanks for your reply! Working on Windows this felt a bit adventurous. ;-)
I downloaded io 2.4.2 manually from Octave-Forge and and unpacked it. As my problem was with writing data to .csv, I looked into cell2csv.cc, which luckily is a rather simple file. In line 117 there is:

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

which I changed to

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

Excited as I was I did not look at your instructions again, but just repacked the modified package and installed it with

pkg install -verbose io-2.4.2.tar.gz
This was successful, and even better: The change worked. The following code
a={1,1.1,1.111111,1.11111111111111111},cell2csv("ones.csv",a)
now produces a file containing
1,1.1,1.111111,1.11111111111
For the "%g" output conversion the specified precision is the maximum number of significant digits to print, hence numbers exactly representable with fewer digits are not padded with zeros and the resulting files are not blown up too much. You might therefore consider to adopt this change to the official io package?

Thanks for your help!
Martin


reply via email to

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