# HG changeset patch # User David Bateman # Date 1212695894 -7200 # Node ID 139f47cf17ab8a9bcb67f5e5d88fda0520cbaf67 # Parent 86dae6e5b83cb7ff65f08c297fac8a20e6790a1d Change NA value to support single to double precision conversion diff -r 86dae6e5b83c -r 139f47cf17ab liboctave/ChangeLog --- a/liboctave/ChangeLog Mon Jul 28 17:41:10 2008 +0200 +++ b/liboctave/ChangeLog Thu Jun 05 21:58:14 2008 +0200 @@ -1,3 +1,21 @@ +2008-07-29 David Bateman + + * lo-ieee.h (LO_IEEE_NA_HW, LO_IEEE_NA_LW, LO_IEEE_NA_FLOAT): + Change definition so cast from single to double and visa versa + maintains NA value. + (LO_IEEE_NA_HW_OLD, LO_IEEE_NA_LW_OLD): Keep old values. + (extern OCTAVE_API int __lo_ieee_is_old_NA (double)): Function to + detect old NA value. + (extern OCTAVE_API double __lo_ieee_replace_old_NA (double)): + Function to replace old NA value with new new. + * lo-cieee.c (int __lo_ieee_is_old_NA (double)): Function to + detect old NA value. + (double __lo_ieee_replace_old_NA (double)): Function to replace + old NA value with new new. + * data-conv.cc (void read_doubles(std::istream&, double *, + save_type, int, bool, octave_mach_info::float_format)): Test if + loaded NA values is the old representation and replace it. + 2008-07-28 Jaroslav Hajek * lo-math.h: Ensure log2 is undefined from cmath in C++ mode. diff -r 86dae6e5b83c -r 139f47cf17ab liboctave/data-conv.cc --- a/liboctave/data-conv.cc Mon Jul 28 17:41:10 2008 +0200 +++ b/liboctave/data-conv.cc Thu Jun 05 21:58:14 2008 +0200 @@ -34,6 +34,7 @@ #include "byte-swap.h" #include "data-conv.h" #include "lo-error.h" +#include "lo-ieee.h" template void swap_bytes<2> (volatile void *, int); template void swap_bytes<4> (volatile void *, int); @@ -1048,8 +1049,13 @@ break; case LS_DOUBLE: // No conversion necessary. - is.read (reinterpret_cast (data), 8 * len); - do_double_format_conversion (data, len, fmt); + { + is.read (reinterpret_cast (data), 8 * len); + do_double_format_conversion (data, len, fmt); + + for (int i = 0; i < len; i++) + data[i] = __lo_ieee_replace_old_NA (data[i]); + } break; default: diff -r 86dae6e5b83c -r 139f47cf17ab liboctave/lo-cieee.c --- a/liboctave/lo-cieee.c Mon Jul 28 17:41:10 2008 +0200 +++ b/liboctave/lo-cieee.c Thu Jun 05 21:58:14 2008 +0200 @@ -150,13 +150,36 @@ #if defined (HAVE_ISNAN) lo_ieee_double t; t.value = x; - return (isnan (x) && t.word[lo_ieee_lw] == LO_IEEE_NA_LW) ? 1 : 0; + return (isnan (x) && t.word[lo_ieee_hw] == LO_IEEE_NA_HW + && t.word[lo_ieee_lw] == LO_IEEE_NA_LW) ? 1 : 0; #else return 0; #endif } int +__lo_ieee_is_old_NA (double x) +{ +#if defined (HAVE_ISNAN) + lo_ieee_double t; + t.value = x; + return (isnan (x) && t.word[lo_ieee_lw] == LO_IEEE_NA_LW_OLD + && t.word[lo_ieee_hw] == LO_IEEE_NA_HW_OLD) ? 1 : 0; +#else + return 0; +#endif +} + +double +__lo_ieee_replace_old_NA (double x) +{ + if (__lo_ieee_is_old_NA (x)) + return lo_ieee_na_value (); + else + return x; +} + +int __lo_ieee_is_NaN_or_NA (double x) { return __lo_ieee_isnan (x); diff -r 86dae6e5b83c -r 139f47cf17ab liboctave/lo-ieee.h --- a/liboctave/lo-ieee.h Mon Jul 28 17:41:10 2008 +0200 +++ b/liboctave/lo-ieee.h Thu Jun 05 21:58:14 2008 +0200 @@ -64,9 +64,12 @@ unsigned int word; } lo_ieee_float; -#define LO_IEEE_NA_HW 0x7ff00000 -#define LO_IEEE_NA_LW 1954 -#define LO_IEEE_NA_FLOAT 0x7f8207a2 +#define LO_IEEE_NA_HW_OLD 0x7ff00000 +#define LO_IEEE_NA_LW_OLD 1954 +#define LO_IEEE_NA_HW 0x7FF840F4 +#define LO_IEEE_NA_LW 0x40000000 +#define LO_IEEE_NA_FLOAT 0x7FC207A2 + extern OCTAVE_API void octave_ieee_init (void); @@ -85,7 +88,9 @@ extern OCTAVE_API int __lo_ieee_isinf (double x); extern OCTAVE_API int __lo_ieee_is_NA (double); +extern OCTAVE_API int __lo_ieee_is_old_NA (double); extern OCTAVE_API int __lo_ieee_is_NaN_or_NA (double) GCC_ATTR_DEPRECATED; +extern OCTAVE_API double __lo_ieee_replace_old_NA (double); extern OCTAVE_API double lo_ieee_inf_value (void); extern OCTAVE_API double lo_ieee_na_value (void); diff -r 86dae6e5b83c -r 139f47cf17ab src/ChangeLog --- a/src/ChangeLog Mon Jul 28 17:41:10 2008 +0200 +++ b/src/ChangeLog Thu Jun 05 21:58:14 2008 +0200 @@ -1,5 +1,8 @@ 2008-07-29 David Bateman + * data.cc (FNA): Add tests for conversion of single to double NA + values. + * ov-flt-re-mat.cc (Fsingle): Documentation fix. 2008-07-28 David Bateman diff -r 86dae6e5b83c -r 139f47cf17ab src/data.cc --- a/src/data.cc Mon Jul 28 17:41:10 2008 +0200 +++ b/src/data.cc Thu Jun 05 21:58:14 2008 +0200 @@ -3824,6 +3824,13 @@ lo_ieee_float_na_value (), "NA"); } +/* + +%!assert(single(NA('double')),NA('single')) +%!assert(double(NA('single')),NA('double')) + + */ + DEFUN (false, args, , "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} false (@var{x})\n\