vil_na.cxx
Go to the documentation of this file.
1 // This is core/vil/vil_na.cxx
2 //:
3 // \file
4 // This file is a cut-and-paste of vnl_na.cxx
5 
6 #include <istream>
7 #include <ios>
8 #include "vil_na.h"
9 #include <vxl_config.h>
10 #ifdef _MSC_VER
11 # include <vcl_msvc_warnings.h>
12 #endif
13 
14 //: A particular qNaN to indicate not available.
15 // This returns the bit pattern 0x7ff00000000007a2, as used by Octave and R
16 // Don't assume that any VXL functions will treat the value as NA rather than NaN, unless
17 // explicitly documented.
18 double vil_na(double)
19 {
20  double a;
21 
22 #if VXL_HAS_INT_64
23  *reinterpret_cast<vxl_uint_64*>(&a) = 0x7ff00000000007a2LL;
24 #else
25 # if VXL_BIG_ENDIAN
26 # define hw 0
27 # define lw 1
28 # else // VXL_LITTLE_ENDIAN
29 # define hw 1
30 # define lw 0
31 # endif
32  reinterpret_cast<vxl_uint_32*>(&a)[hw]=0x7ff00000;
33  reinterpret_cast<vxl_uint_32*>(&a)[lw]=0x000007a2;
34 #endif
35 
36  return a;
37 }
38 
39 
40 
41 //: A particular qNaN to indicate not available.
42 // This returns the bit pattern 0x7f8007a2
43 // Don't assume that any VXL functions will treat the value as NA rather than NaN, unless
44 // explicitly documented.
45 float vil_na(float)
46 {
47  float a;
48 
49  *reinterpret_cast<vxl_uint_32*>(&a) = 0x7f8007a2L;
50 
51  return a;
52 }
53 
54 
55 //: True if parameter is specific NA qNaN.
56 // Tests for bit pattern 0x7ff00000000007a2, as used by Octave and R
57 bool vil_na_isna(double x)
58 {
59 #if VXL_HAS_INT_64
60  return ((*reinterpret_cast<vxl_uint_64*>(&x))&0xfff7ffffffffffffLL) // ignore signalling bit
61  == 0x7ff00000000007a2LL;
62 #else
63  return ((reinterpret_cast<vxl_int_32*>(&x)[hw]) & 0xfff7ffff) == 0x7ff00000 &&
64  reinterpret_cast<vxl_int_32*>(&x)[lw] == 0x000007a2;
65 #endif
66 }
67 
68 //: True if parameter is specific NA qNaN.
69 // Tests for bit pattern 0x7F8007a2
70 bool vil_na_isna(float x)
71 {
72  return ((*reinterpret_cast<vxl_uint_32*>(&x))&0xffbfffffL) // ignore signalling bit
73  == 0x7f8007a2L;
74 }
75 //----------------------------------------------------------------------
double vil_na(double)
A particular qNaN to indicate not available.
Definition: vil_na.cxx:18
#define lw
NA (Not Available) is a particular double NaN to represent missing data.
#define hw
bool vil_na_isna(double x)
True if parameter is specific NA qNaN.
Definition: vil_na.cxx:57