changeset 18653:7d0014bb9e4e

also switch from unsigned integer to real format for negative values * oct-stream.cc (ok_for_unsigned_int_conv): Return false if value is negative.
author John W. Eaton <jwe@octave.org>
date Wed, 16 Apr 2014 20:45:33 -0400
parents 3647db1a37d7
children 4f43f87b7c3e
files libinterp/corefcn/oct-stream.cc
diffstat 1 files changed, 9 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/oct-stream.cc	Wed Apr 16 20:44:00 2014 -0400
+++ b/libinterp/corefcn/oct-stream.cc	Wed Apr 16 20:45:33 2014 -0400
@@ -2405,14 +2405,21 @@
 ok_for_unsigned_int_conv (const octave_value& val)
 {
   if (val.is_integer_type ())
-    return true;
+    {
+      // Easier than dispatching here...
+
+      octave_value ov_is_ge_zero
+        = do_binary_op (octave_value::op_ge, val, octave_value (0.0));
+
+      return ov_is_ge_zero.is_true ();
+    }
   else
     {
       double dval = val.double_value ();
 
       uint64_t limit = std::numeric_limits<uint64_t>::max ();
 
-      if (dval == xround (dval) && dval <= limit)
+      if (dval == xround (dval) && dval >= 0 && dval <= limit)
         return true;
     }