comparison libinterp/corefcn/oct-stream.cc @ 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 491b0adfec95
children 5bd1ca29c5f0
comparison
equal deleted inserted replaced
18652:3647db1a37d7 18653:7d0014bb9e4e
2403 2403
2404 static bool 2404 static bool
2405 ok_for_unsigned_int_conv (const octave_value& val) 2405 ok_for_unsigned_int_conv (const octave_value& val)
2406 { 2406 {
2407 if (val.is_integer_type ()) 2407 if (val.is_integer_type ())
2408 return true; 2408 {
2409 // Easier than dispatching here...
2410
2411 octave_value ov_is_ge_zero
2412 = do_binary_op (octave_value::op_ge, val, octave_value (0.0));
2413
2414 return ov_is_ge_zero.is_true ();
2415 }
2409 else 2416 else
2410 { 2417 {
2411 double dval = val.double_value (); 2418 double dval = val.double_value ();
2412 2419
2413 uint64_t limit = std::numeric_limits<uint64_t>::max (); 2420 uint64_t limit = std::numeric_limits<uint64_t>::max ();
2414 2421
2415 if (dval == xround (dval) && dval <= limit) 2422 if (dval == xround (dval) && dval >= 0 && dval <= limit)
2416 return true; 2423 return true;
2417 } 2424 }
2418 2425
2419 return false; 2426 return false;
2420 } 2427 }