diff liboctave/lo-ieee.cc @ 4025:cfb762dc9259

[project @ 2002-08-09 06:32:15 by jwe]
author jwe
date Fri, 09 Aug 2002 06:32:16 +0000
parents 6293a9d5650a
children 3cc39e3b8fa5
line wrap: on
line diff
--- a/liboctave/lo-ieee.cc
+++ b/liboctave/lo-ieee.cc
@@ -46,6 +46,7 @@
 #endif
 
 #include "lo-ieee.h"
+#include "mach-info.h"
 
 // Octave's idea of infinity.
 double octave_Inf;
@@ -53,6 +54,21 @@
 // Octave's idea of not a number.
 double octave_NaN;
 
+// Octave's idea of a missing value.
+double octave_NA;
+
+static int hw;
+static int lw;
+
+typedef union
+{
+  double value;
+  unsigned int word[2];
+} ieee_double;
+
+#define NA_HW 0x7ff00000
+#define NA_LW 1954
+
 void
 octave_ieee_init (void)
 {
@@ -90,6 +106,27 @@
   octave_NaN = octave_Inf / octave_Inf;
 #endif
 
+  // This is patterned after code in R.
+
+  oct_mach_info::float_format ff = oct_mach_info::native_float_format ();
+
+  if (ff == oct_mach_info::ieee_big_endian)
+    {
+      hw = 0;
+      lw = 1;
+    }
+  else
+    {
+      hw = 1;
+      lw = 0;
+    }
+
+  ieee_double t;
+  t.word[hw] = NA_HW;
+  t.word[lw] = NA_LW;
+
+  octave_NA = t.value;
+
 #endif
 }
 
@@ -109,6 +146,20 @@
 
 #endif
 
+extern "C" int
+lo_ieee_is_NA (double x)
+{
+  ieee_double t;
+  t.value = x;
+  return (isnan (x) && t.word[lw] == NA_LW) ? 1 : 0;
+}
+
+extern "C" int
+lo_ieee_is_NaN_or_NA (double x)
+{
+  return isnan (x);
+}
+
 /*
 ;;; Local Variables: ***
 ;;; mode: C++ ***