# HG changeset patch # User John W. Eaton # Date 1205865975 14400 # Node ID 6929e40fc5979c87b5e3061c97e25008e3a94822 # Parent 90ad1f69ca9df12ac13eb446d4cef1bf3525caa4 compatible handling of NaN -> int conversions diff -r 90ad1f69ca9d -r 6929e40fc597 liboctave/ChangeLog --- a/liboctave/ChangeLog Tue Mar 18 14:05:50 2008 -0400 +++ b/liboctave/ChangeLog Tue Mar 18 14:46:15 2008 -0400 @@ -1,3 +1,8 @@ +2008-03-18 John W. Eaton + + * 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 * Sparse.cc (Sparse::index, assign): Likewise. diff -r 90ad1f69ca9d -r 6929e40fc597 liboctave/oct-inttypes.h --- a/liboctave/oct-inttypes.h Tue Mar 18 14:05:50 2008 -0400 +++ b/liboctave/oct-inttypes.h Tue Mar 18 14:46:15 2008 -0400 @@ -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 (const double& x, const T& mn, \ + const T& mx) \ + { \ + return (lo_ieee_isnan (x) ? 0 : (x > mx ? mx : (x < mn ? mn : static_cast (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.