octave-bug-tracker
[Top][All Lists]
Advanced

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

[Octave-bug-tracker] [bug #51178] publish() sometimes removes last eleme


From: Rik
Subject: [Octave-bug-tracker] [bug #51178] publish() sometimes removes last element from vector after section break
Date: Tue, 6 Jun 2017 12:43:22 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0

Follow-up Comment #3, bug #51178 (project octave):

Octave should potentially be concerned that values are not be stored
accurately.  I am not sure yet whether this is just a problem with ranges, or
it is a general problem with all double values.

Currently, Octave uses the routine octave_write_double which internally relies
on the C++ std::lib to format the output.  This routine writes 16 digits of
precision, which would appear to be correct.


log10 (flintmax)
ans =  15.955


However, as a hack, I changed the routine to use 17 digits of precision.


diff -r 05bbca224a14 -r 36c3a3205e28 liboctave/util/lo-utils.cc
--- a/liboctave/util/lo-utils.cc        Tue Jun 06 08:50:20 2017 -0700
+++ b/liboctave/util/lo-utils.cc        Tue Jun 06 09:33:49 2017 -0700
@@ -381,6 +381,9 @@ template <> OCTAVE_API FloatComplex octa
   return octave_read_cx_fp_value<float> (is);
 }
 
+#include <stdio.h>
+#include "oct-locbuf.h"
+
 void
 octave_write_double (std::ostream& os, double d)
 {
@@ -391,7 +394,11 @@ octave_write_double (std::ostream& os, d
   else if (lo_ieee_isinf (d))
     os << (d < 0 ? "-Inf" : "Inf");
   else
-    os << d;
+    {
+      OCTAVE_LOCAL_BUFFER (char, tmp, 64); 
+      sprintf (tmp, "%.17g", d);
+      os << tmp;
+    }
 }
 
 void


This fixes the issue, tst_save_range now returns 142 three times.  I've
attached the diff for reference.

So the remaining question is whether Octave should enhance octave_write_double
to be more precise, whether only the save_ascii routine for range variables
should be updated, or whether this is really a problem on the load side.



(file #40864)
    _______________________________________________________

Additional Item Attachment:

File name: write_dbl.diff                 Size:0 KB


    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?51178>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

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