GNU Octave  4.0.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-2015 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 #define octave_Inf (lo_ieee_inf_value ())
32 
33 /* Octave's idea of a missing value. */
34 #define octave_NA (lo_ieee_na_value ())
35 
36 /* Octave's idea of not a number. */
37 #define octave_NaN (lo_ieee_nan_value ())
38 
39 /* Octave's idea of infinity. */
40 #define octave_Float_Inf (lo_ieee_float_inf_value ())
41 
42 /* Octave's idea of a missing value. */
43 #define octave_Float_NA (lo_ieee_float_na_value ())
44 
45 /* Octave's idea of not a number. */
46 #define octave_Float_NaN (lo_ieee_float_nan_value ())
47 
48 /* FIXME -- this code assumes that a double has twice the
49  number of bits as an int */
50 
51 typedef union
52 {
53  double value;
54  unsigned int word[2];
56 
57 typedef union
58 {
59  float value;
60  unsigned int word;
62 
63 #define LO_IEEE_NA_HW_OLD 0x7ff00000
64 #define LO_IEEE_NA_LW_OLD 1954
65 #define LO_IEEE_NA_HW 0x7FF840F4
66 #define LO_IEEE_NA_LW 0x40000000
67 #define LO_IEEE_NA_FLOAT 0x7FC207A2
68 
69 extern OCTAVE_API void octave_ieee_init (void);
70 
71 extern OCTAVE_API int __lo_ieee_isnan (double x);
72 extern OCTAVE_API int __lo_ieee_finite (double x);
73 extern OCTAVE_API int __lo_ieee_isinf (double x);
74 
75 extern OCTAVE_API int __lo_ieee_is_NA (double);
76 extern OCTAVE_API int __lo_ieee_is_old_NA (double);
77 extern OCTAVE_API double __lo_ieee_replace_old_NA (double);
78 
79 extern OCTAVE_API double lo_ieee_inf_value (void);
80 extern OCTAVE_API double lo_ieee_na_value (void);
81 extern OCTAVE_API double lo_ieee_nan_value (void);
82 
83 extern OCTAVE_API int __lo_ieee_signbit (double);
84 
85 extern OCTAVE_API int __lo_ieee_float_isnan (float x);
86 extern OCTAVE_API int __lo_ieee_float_finite (float x);
87 extern OCTAVE_API int __lo_ieee_float_isinf (float x);
88 
89 extern OCTAVE_API int __lo_ieee_float_is_NA (float);
90 
91 extern OCTAVE_API float lo_ieee_float_inf_value (void);
92 extern OCTAVE_API float lo_ieee_float_na_value (void);
93 extern OCTAVE_API float lo_ieee_float_nan_value (void);
94 
95 extern OCTAVE_API int __lo_ieee_float_signbit (float);
96 
97 #ifdef __cplusplus
98 }
99 #endif
100 
101 #define lo_ieee_isnan(x) (sizeof (x) == sizeof (float) ? \
102  __lo_ieee_float_isnan (x) : __lo_ieee_isnan (x))
103 #define lo_ieee_finite(x) (sizeof (x) == sizeof (float) ? \
104  __lo_ieee_float_finite (x) : __lo_ieee_finite (x))
105 #define lo_ieee_isinf(x) (sizeof (x) == sizeof (float) ? \
106  __lo_ieee_float_isinf (x) : __lo_ieee_isinf (x))
107 
108 
109 #define lo_ieee_is_NA(x) (sizeof (x) == sizeof (float) ? \
110  __lo_ieee_float_is_NA (x) : __lo_ieee_is_NA (x))
111 #define lo_ieee_is_NaN_or_NA(x) (sizeof (x) == sizeof (float) ? \
112  __lo_ieee_float_is_NaN_or_NA (x) : __lo_ieee_is_NaN_or_NA (x))
113 #define lo_ieee_signbit(x) (sizeof (x) == sizeof (float) ? \
114  __lo_ieee_float_signbit (x) : __lo_ieee_signbit (x))
115 
116 #ifdef __cplusplus
117 
118 template <typename T>
119 struct octave_numeric_limits
120 {
121  static T NA (void) { return static_cast<T> (0); }
122 };
123 
124 template <>
125 struct octave_numeric_limits<double>
126 {
127  static double NA (void) { return octave_NA; }
128 };
129 
130 template <>
131 struct octave_numeric_limits<float>
132 {
133  static float NA (void) { return octave_Float_NA; }
134 };
135 
136 #endif
137 
138 #endif
OCTAVE_API int __lo_ieee_finite(double x)
Definition: lo-ieee.cc:61
OCTAVE_API int __lo_ieee_float_finite(float x)
Definition: lo-ieee.cc:156
OCTAVE_API int __lo_ieee_isnan(double x)
Definition: lo-ieee.cc:50
OCTAVE_API double lo_ieee_inf_value(void)
Definition: lo-ieee.cc:110
OCTAVE_API float lo_ieee_float_na_value(void)
Definition: lo-ieee.cc:194
OCTAVE_API int __lo_ieee_is_NA(double)
Definition: lo-ieee.cc:83
OCTAVE_API double lo_ieee_na_value(void)
Definition: lo-ieee.cc:118
OCTAVE_API int __lo_ieee_float_isnan(float x)
Definition: lo-ieee.cc:145
OCTAVE_API int __lo_ieee_float_is_NA(float)
Definition: lo-ieee.cc:178
OCTAVE_API int __lo_ieee_float_signbit(float)
Definition: lo-ieee.cc:210
double value
Definition: lo-ieee.h:53
float value
Definition: lo-ieee.h:59
OCTAVE_API double __lo_ieee_replace_old_NA(double)
Definition: lo-ieee.cc:101
OCTAVE_API int __lo_ieee_isinf(double x)
Definition: lo-ieee.cc:72
OCTAVE_API void octave_ieee_init(void)
Definition: lo-ieee.cc:221
#define octave_NA
Definition: lo-ieee.h:34
#define octave_Float_NA
Definition: lo-ieee.h:43
OCTAVE_API float lo_ieee_float_nan_value(void)
Definition: lo-ieee.cc:202
OCTAVE_API int __lo_ieee_signbit(double)
Definition: lo-ieee.cc:134
OCTAVE_API double lo_ieee_nan_value(void)
Definition: lo-ieee.cc:126
unsigned int word
Definition: lo-ieee.h:60
OCTAVE_API float lo_ieee_float_inf_value(void)
Definition: lo-ieee.cc:186
OCTAVE_API int __lo_ieee_is_old_NA(double)
Definition: lo-ieee.cc:92
OCTAVE_API int __lo_ieee_float_isinf(float x)
Definition: lo-ieee.cc:167
F77_RET_T const double * x