GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
lo-ieee.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2013 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if !defined (octave_lo_ieee_h)
24 #define octave_lo_ieee_h 1
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 /* Octave's idea of infinity. */
31 extern OCTAVE_API double octave_Inf;
32 
33 /* Octave's idea of a missing value. */
34 extern OCTAVE_API double octave_NA;
35 
36 /* Octave's idea of not a number. */
37 extern OCTAVE_API double octave_NaN;
38 
39 /* Octave's idea of infinity. */
40 extern OCTAVE_API float octave_Float_Inf;
41 
42 /* Octave's idea of a missing value. */
43 extern OCTAVE_API float octave_Float_NA;
44 
45 /* Octave's idea of not a number. */
46 extern OCTAVE_API float octave_Float_NaN;
47 
48 /* FIXME -- this code assumes that a double has twice the
49  number of bits as an int */
50 
51 extern OCTAVE_API int lo_ieee_hw;
52 extern OCTAVE_API int lo_ieee_lw;
53 
54 typedef union
55 {
56  double value;
57  unsigned int word[2];
59 
60 typedef union
61 {
62  float value;
63  unsigned int word;
65 
66 #define LO_IEEE_NA_HW_OLD 0x7ff00000
67 #define LO_IEEE_NA_LW_OLD 1954
68 #define LO_IEEE_NA_HW 0x7FF840F4
69 #define LO_IEEE_NA_LW 0x40000000
70 #define LO_IEEE_NA_FLOAT 0x7FC207A2
71 
72 extern OCTAVE_API void octave_ieee_init (void);
73 
74 extern OCTAVE_API int __lo_ieee_isnan (double x);
75 extern OCTAVE_API int __lo_ieee_finite (double x);
76 extern OCTAVE_API int __lo_ieee_isinf (double x);
77 
78 extern OCTAVE_API int __lo_ieee_is_NA (double);
79 extern OCTAVE_API int __lo_ieee_is_old_NA (double);
80 extern OCTAVE_API int __lo_ieee_is_NaN_or_NA (double) GCC_ATTR_DEPRECATED;
81 extern OCTAVE_API double __lo_ieee_replace_old_NA (double);
82 
83 extern OCTAVE_API double lo_ieee_inf_value (void);
84 extern OCTAVE_API double lo_ieee_na_value (void);
85 extern OCTAVE_API double lo_ieee_nan_value (void);
86 
87 extern OCTAVE_API int __lo_ieee_signbit (double);
88 
89 extern OCTAVE_API int __lo_ieee_float_isnan (float x);
90 extern OCTAVE_API int __lo_ieee_float_finite (float x);
91 extern OCTAVE_API int __lo_ieee_float_isinf (float x);
92 
93 extern OCTAVE_API int __lo_ieee_float_is_NA (float);
94 extern OCTAVE_API int __lo_ieee_float_is_NaN_or_NA (float) GCC_ATTR_DEPRECATED;
95 
96 extern OCTAVE_API float lo_ieee_float_inf_value (void);
97 extern OCTAVE_API float lo_ieee_float_na_value (void);
98 extern OCTAVE_API float lo_ieee_float_nan_value (void);
99 
100 extern OCTAVE_API int __lo_ieee_float_signbit (float);
101 
102 #ifdef __cplusplus
103 }
104 #endif
105 
106 #define lo_ieee_isnan(x) (sizeof (x) == sizeof (float) ? \
107  __lo_ieee_float_isnan (x) : __lo_ieee_isnan (x))
108 #define lo_ieee_finite(x) (sizeof (x) == sizeof (float) ? \
109  __lo_ieee_float_finite (x) : __lo_ieee_finite (x))
110 #define lo_ieee_isinf(x) (sizeof (x) == sizeof (float) ? \
111  __lo_ieee_float_isinf (x) : __lo_ieee_isinf (x))
112 
113 
114 #define lo_ieee_is_NA(x) (sizeof (x) == sizeof (float) ? \
115  __lo_ieee_float_is_NA (x) : __lo_ieee_is_NA (x))
116 #define lo_ieee_is_NaN_or_NA(x) (sizeof (x) == sizeof (float) ? \
117  __lo_ieee_float_is_NaN_or_NA (x) : __lo_ieee_is_NaN_or_NA (x))
118 #define lo_ieee_signbit(x) (sizeof (x) == sizeof (float) ? \
119  __lo_ieee_float_signbit (x) : __lo_ieee_signbit (x))
120 
121 #ifdef __cplusplus
122 
123 template <typename T>
124 struct octave_numeric_limits
125 {
126  static T NA (void) { return static_cast<T> (0); }
127 };
128 
129 template <>
130 struct octave_numeric_limits<double>
131 {
132  static double NA (void) { return octave_NA; }
133 };
134 
135 template <>
136 struct octave_numeric_limits<float>
137 {
138  static float NA (void) { return octave_Float_NA; }
139 };
140 
141 #endif
142 
143 #endif