changelog shortlog tags files raw

changeset: Change NA value to support single to double precision conversion

changeset 7991: 139f47cf17ab
parent 7990:86dae6e5b83c
child 7992:80e3fe8938f2
author: David Bateman <dbateman@free.fr>
date: Thu Jun 05 21:58:14 2008 +0200 (17 months ago)
files: liboctave/ChangeLog liboctave/data-conv.cc liboctave/lo-cieee.c liboctave/lo-ieee.h src/ChangeLog src/data.cc
description: Change NA value to support single to double precision conversion
       1--- a/liboctave/ChangeLog	Mon Jul 28 17:41:10 2008 +0200
       2+++ b/liboctave/ChangeLog	Thu Jun 05 21:58:14 2008 +0200
       3@@ -1,3 +1,21 @@
       4+2008-07-29  David Bateman  <dbateman@free.fr>
       5+
       6+	* lo-ieee.h (LO_IEEE_NA_HW, LO_IEEE_NA_LW, LO_IEEE_NA_FLOAT):
       7+	Change definition so cast from single to double and visa versa
       8+	maintains NA value.
       9+	(LO_IEEE_NA_HW_OLD, LO_IEEE_NA_LW_OLD): Keep old values.
      10+	(extern OCTAVE_API int __lo_ieee_is_old_NA (double)): Function to
      11+	detect old NA value.
      12+	(extern OCTAVE_API double __lo_ieee_replace_old_NA (double)):
      13+	Function to replace old NA value with new new.
      14+	* lo-cieee.c (int __lo_ieee_is_old_NA (double)): Function to
      15+	detect old NA value.
      16+	(double __lo_ieee_replace_old_NA (double)): Function to replace
      17+	old NA value with new new.
      18+	* data-conv.cc (void read_doubles(std::istream&, double *, 
      19+	save_type, int, bool, octave_mach_info::float_format)): Test if
      20+	loaded NA values is the old representation and replace it.
      21+	
      22 2008-07-28  Jaroslav Hajek <highegg@gmail.com>
      23 
      24 	* lo-math.h: Ensure log2 is undefined from cmath in C++ mode.
     1.1--- a/liboctave/data-conv.cc	Mon Jul 28 17:41:10 2008 +0200
     1.2+++ b/liboctave/data-conv.cc	Thu Jun 05 21:58:14 2008 +0200
     1.3@@ -34,6 +34,7 @@
     1.4 #include "byte-swap.h"
     1.5 #include "data-conv.h"
     1.6 #include "lo-error.h"
     1.7+#include "lo-ieee.h"
     1.8 
     1.9 template void swap_bytes<2> (volatile void *, int);
    1.10 template void swap_bytes<4> (volatile void *, int);
    1.11@@ -1048,8 +1049,13 @@
    1.12       break;
    1.13 
    1.14     case LS_DOUBLE: // No conversion necessary.
    1.15-      is.read (reinterpret_cast<char *> (data), 8 * len);
    1.16-      do_double_format_conversion (data, len, fmt);
    1.17+      {
    1.18+	is.read (reinterpret_cast<char *> (data), 8 * len);
    1.19+	do_double_format_conversion (data, len, fmt);
    1.20+
    1.21+	for (int i = 0; i < len; i++)
    1.22+	  data[i] = __lo_ieee_replace_old_NA (data[i]);
    1.23+      }
    1.24       break;
    1.25 
    1.26     default:
     2.1--- a/liboctave/lo-cieee.c	Mon Jul 28 17:41:10 2008 +0200
     2.2+++ b/liboctave/lo-cieee.c	Thu Jun 05 21:58:14 2008 +0200
     2.3@@ -150,10 +150,33 @@
     2.4 #if defined (HAVE_ISNAN)
     2.5   lo_ieee_double t;
     2.6   t.value = x;
     2.7-  return (isnan (x) && t.word[lo_ieee_lw] == LO_IEEE_NA_LW) ? 1 : 0;
     2.8+  return (isnan (x) && t.word[lo_ieee_hw] == LO_IEEE_NA_HW 
     2.9+	  && t.word[lo_ieee_lw] == LO_IEEE_NA_LW) ? 1 : 0;
    2.10 #else
    2.11   return 0;
    2.12 #endif
    2.13+}
    2.14+
    2.15+int
    2.16+__lo_ieee_is_old_NA (double x)
    2.17+{
    2.18+#if defined (HAVE_ISNAN)
    2.19+  lo_ieee_double t;
    2.20+  t.value = x;
    2.21+  return (isnan (x) && t.word[lo_ieee_lw] == LO_IEEE_NA_LW_OLD 
    2.22+	  && t.word[lo_ieee_hw] == LO_IEEE_NA_HW_OLD) ? 1 : 0;
    2.23+#else
    2.24+  return 0;
    2.25+#endif
    2.26+}
    2.27+
    2.28+double
    2.29+__lo_ieee_replace_old_NA (double x)
    2.30+{
    2.31+  if (__lo_ieee_is_old_NA (x))
    2.32+    return lo_ieee_na_value ();
    2.33+  else
    2.34+    return x;
    2.35 }
    2.36 
    2.37 int
     3.1--- a/liboctave/lo-ieee.h	Mon Jul 28 17:41:10 2008 +0200
     3.2+++ b/liboctave/lo-ieee.h	Thu Jun 05 21:58:14 2008 +0200
     3.3@@ -64,9 +64,12 @@
     3.4   unsigned int word;
     3.5 } lo_ieee_float;
     3.6 
     3.7-#define LO_IEEE_NA_HW 0x7ff00000
     3.8-#define LO_IEEE_NA_LW 1954
     3.9-#define LO_IEEE_NA_FLOAT   0x7f8207a2
    3.10+#define LO_IEEE_NA_HW_OLD 0x7ff00000
    3.11+#define LO_IEEE_NA_LW_OLD 1954
    3.12+#define LO_IEEE_NA_HW 0x7FF840F4
    3.13+#define LO_IEEE_NA_LW 0x40000000
    3.14+#define LO_IEEE_NA_FLOAT   0x7FC207A2
    3.15+ 
    3.16 
    3.17 extern OCTAVE_API void octave_ieee_init (void);
    3.18 
    3.19@@ -85,7 +88,9 @@
    3.20 extern OCTAVE_API int __lo_ieee_isinf (double x);
    3.21 
    3.22 extern OCTAVE_API int __lo_ieee_is_NA (double);
    3.23+extern OCTAVE_API int __lo_ieee_is_old_NA (double);
    3.24 extern OCTAVE_API int __lo_ieee_is_NaN_or_NA (double) GCC_ATTR_DEPRECATED;
    3.25+extern OCTAVE_API double __lo_ieee_replace_old_NA (double);
    3.26 
    3.27 extern OCTAVE_API double lo_ieee_inf_value (void);
    3.28 extern OCTAVE_API double lo_ieee_na_value (void);
     4.1--- a/src/ChangeLog	Mon Jul 28 17:41:10 2008 +0200
     4.2+++ b/src/ChangeLog	Thu Jun 05 21:58:14 2008 +0200
     4.3@@ -1,4 +1,7 @@
     4.4 2008-07-29  David Bateman  <dbateman@free.fr>
     4.5+
     4.6+	* data.cc (FNA): Add tests for conversion of single to double NA
     4.7+	values.
     4.8 
     4.9 	* ov-flt-re-mat.cc (Fsingle): Documentation fix.
    4.10 
     5.1--- a/src/data.cc	Mon Jul 28 17:41:10 2008 +0200
     5.2+++ b/src/data.cc	Thu Jun 05 21:58:14 2008 +0200
     5.3@@ -3824,6 +3824,13 @@
     5.4 		      lo_ieee_float_na_value (), "NA");
     5.5 }
     5.6 
     5.7+/*
     5.8+
     5.9+%!assert(single(NA('double')),NA('single'))
    5.10+%!assert(double(NA('single')),NA('double'))
    5.11+
    5.12+ */
    5.13+
    5.14 DEFUN (false, args, ,
    5.15   "-*- texinfo -*-\n\
    5.16 @deftypefn {Built-in Function} {} false (@var{x})\n\