Mercurial > hg > octave-lojdl
changeset 7596:6929e40fc597
compatible handling of NaN -> int conversions
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 18 Mar 2008 14:46:15 -0400 |
parents | 90ad1f69ca9d |
children | 6b2a99e44ff2 |
files | liboctave/ChangeLog liboctave/oct-inttypes.h |
diffstat | 2 files changed, 26 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,8 @@ +2008-03-18 John W. Eaton <jwe@octave.org> + + * oct-inttypes.h (OCTAVE_DBL_FTR): New macro. + Use it to provide double specializations for octave_int_fit_to_range. + 2008-03-08 John W. Eaton <jwe@octave.org> * Sparse.cc (Sparse<T>::index, assign): Likewise.
--- a/liboctave/oct-inttypes.h +++ b/liboctave/oct-inttypes.h @@ -128,6 +128,27 @@ return (x > mx ? mx : (x < mn ? mn : T2 (x))); } +#define OCTAVE_DBL_FTR(T) \ + template <> \ + inline T \ + octave_int_fit_to_range<double, T> (const double& x, const T& mn, \ + const T& mx) \ + { \ + return (lo_ieee_isnan (x) ? 0 : (x > mx ? mx : (x < mn ? mn : static_cast<T> (x)))); \ + } + +OCTAVE_DBL_FTR (char) +OCTAVE_DBL_FTR (short) +OCTAVE_DBL_FTR (int) +OCTAVE_DBL_FTR (long) +OCTAVE_DBL_FTR (long long) + +OCTAVE_DBL_FTR (unsigned char) +OCTAVE_DBL_FTR (unsigned short) +OCTAVE_DBL_FTR (unsigned int) +OCTAVE_DBL_FTR (unsigned long) +OCTAVE_DBL_FTR (unsigned long long) + // If X is unsigned and the new type is signed, then we only have to // check the upper limit, but we should cast the maximum value of the // new type to an unsigned type before performing the comparison.