Mercurial > octave
changeset 23556:31b1ef1ee585
Fix Octave's -text format for saving data to make it lossless for IEEE-754 doubles.
* ls-oct-text.cc (Vsave_precision): Change default to 17 digits.
* ls-oct-text.cc (Fsave_precision): Add explanation of suitable values to docstring.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 07 Jun 2017 12:29:23 -0700 |
parents | 9151922777e2 |
children | 00b11cee2100 |
files | libinterp/corefcn/ls-oct-text.cc |
diffstat | 1 files changed, 11 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/ls-oct-text.cc Wed Jun 07 12:11:33 2017 -0700 +++ b/libinterp/corefcn/ls-oct-text.cc Wed Jun 07 12:29:23 2017 -0700 @@ -64,8 +64,9 @@ #include "version.h" #include "dMatrix.h" -// The number of decimal digits to use when writing ascii data. -static int Vsave_precision = 16; +// The number of decimal digits to use when writing ASCII data. +// 17 is the minimum necessary for lossless save/restore of IEEE-754 doubles. +static int Vsave_precision = 17; // Functions for reading octave format text data. @@ -406,9 +407,17 @@ Query or set the internal variable that specifies the number of digits to keep when saving data in text format. +The default value is 17 which is the minimum necessary for the lossless saving +and restoring of IEEE-754 double values; For IEEE-754 single values the minimum +value is 9. If file size is a concern, it is probably better to choose a +binary format for saving data rather than to reduce the precision of the saved +values. + When called from inside a function with the @qcode{"local"} option, the variable is changed locally for the function and any subroutines it calls. The original variable value is restored when exiting the function. + +@seealso{save_default_options} @end deftypefn */) { return SET_INTERNAL_VARIABLE_WITH_LIMITS (save_precision, -1,