Mercurial > octave-libtiff
comparison libinterp/octave-value/ov-base.cc @ 30867:014030798d5e stable
Avoid issues when converting large integers to floating point (bug #62212).
* libinterp/corefcn/oct-stream.cc (get_size),
libinterp/corefcn/xpow.cc (xisint),
libinterp/octave-value/ov-base.cc (INT_CONV_METHOD),
libinterp/octave-value/ov.cc (check_colon_operand, range_numel (T, double, T)),
liboctave/numeric/lo-mappers.cc (nint_big, nint),
liboctave/util/oct-inttypes.cc (emulate_mop,
operator - (const double, const octave_uint64)),
liboctave/util/oct-string.cc (rational_approx): Take into account that the
maximum value of (signed or unsigned) integers might change its value if
converted to floating point. In comparisons, check against the first value
*outside* the range of the integer type instead of the last value *inside* its
range.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Mon, 28 Mar 2022 19:27:35 +0200 |
parents | 2989202f92f8 |
children | 79edd49a5a97 |
comparison
equal
deleted
inserted
replaced
30864:5fa3d8f0dcb3 | 30867:014030798d5e |
---|---|
473 catch (octave::execution_exception& ee) \ | 473 catch (octave::execution_exception& ee) \ |
474 { \ | 474 { \ |
475 err_wrong_type_arg (ee, "octave_base_value::" #F "_value ()", type_name ()); \ | 475 err_wrong_type_arg (ee, "octave_base_value::" #F "_value ()", type_name ()); \ |
476 } \ | 476 } \ |
477 \ | 477 \ |
478 static const double out_of_range_top \ | |
479 = static_cast<double>(std::numeric_limits<T>::max ()) + 1.; \ | |
478 if (require_int && octave::math::x_nint (d) != d) \ | 480 if (require_int && octave::math::x_nint (d) != d) \ |
479 error_with_cfn ("conversion of %g to " #T " value failed", d); \ | 481 error_with_cfn ("conversion of %g to " #T " value failed", d); \ |
480 else if (d < std::numeric_limits<T>::min ()) \ | 482 else if (d < std::numeric_limits<T>::min ()) \ |
481 retval = std::numeric_limits<T>::min (); \ | 483 retval = std::numeric_limits<T>::min (); \ |
482 else if (d > std::numeric_limits<T>::max ()) \ | 484 else if (d >= out_of_range_top) \ |
483 retval = std::numeric_limits<T>::max (); \ | 485 retval = std::numeric_limits<T>::max (); \ |
484 else \ | 486 else \ |
485 retval = static_cast<T> (octave::math::fix (d)); \ | 487 retval = static_cast<T> (octave::math::fix (d)); \ |
486 \ | 488 \ |
487 return retval; \ | 489 return retval; \ |