GNU Octave  8.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
lo-ieee.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1996-2023 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if ! defined (octave_lo_ieee_h)
27 #define octave_lo_ieee_h 1
28 
29 #include "octave-config.h"
30 
31 #include <cmath>
32 
33 #if defined (__cplusplus)
34 extern "C" {
35 #endif
36 
37 /* Octave's idea of infinity. */
38 #define octave_Inf (lo_ieee_inf_value ())
39 
40 /* Octave's idea of a missing value. */
41 #define octave_NA (lo_ieee_na_value ())
42 
43 /* Octave's idea of not a number. */
44 #define octave_NaN (lo_ieee_nan_value ())
45 
46 /* Octave's idea of infinity. */
47 #define octave_Float_Inf (lo_ieee_float_inf_value ())
48 
49 /* Octave's idea of a missing value. */
50 #define octave_Float_NA (lo_ieee_float_na_value ())
51 
52 /* Octave's idea of not a number. */
53 #define octave_Float_NaN (lo_ieee_float_nan_value ())
54 
55 /* FIXME: This code assumes that a double has twice the
56  number of bits as an int */
57 
58 typedef union
59  {
60  double value;
61  unsigned int word[2];
63 
64 typedef union
65  {
66  float value;
67  unsigned int word;
69 
70 extern OCTAVE_API void octave_ieee_init (void);
71 
72 inline int __lo_ieee_isnan (double x) { return std::isnan (x); }
73 inline int __lo_ieee_isfinite (double x) { return std::isfinite (x); }
74 inline int __lo_ieee_isinf (double x) { return std::isinf (x); }
75 
76 extern OCTAVE_API int __lo_ieee_is_NA (double);
77 
78 extern OCTAVE_API double lo_ieee_inf_value (void);
79 extern OCTAVE_API double lo_ieee_na_value (void);
80 extern OCTAVE_API double lo_ieee_nan_value (void);
81 
82 inline int __lo_ieee_signbit (double x) { return std::signbit (x); }
83 
84 inline int __lo_ieee_float_isnan (float x) { return std::isnan (x); }
85 inline int __lo_ieee_float_isfinite (float x) { return std::isfinite (x); }
86 inline int __lo_ieee_float_isinf (float x) { return std::isinf (x); }
87 
88 extern OCTAVE_API int __lo_ieee_float_is_NA (float);
89 
90 extern OCTAVE_API float lo_ieee_float_inf_value (void);
91 extern OCTAVE_API float lo_ieee_float_na_value (void);
92 extern OCTAVE_API float lo_ieee_float_nan_value (void);
93 
94 inline int __lo_ieee_float_signbit (float x) { return std::signbit (x); }
95 
96 #if defined (__cplusplus)
97 }
98 #endif
99 
100 #define lo_ieee_isnan(x) \
101  (sizeof (x) == sizeof (float) \
102  ? __lo_ieee_float_isnan (x) : __lo_ieee_isnan (x))
103 
104 #define lo_ieee_isfinite(x) \
105  (sizeof (x) == sizeof (float) \
106  ? __lo_ieee_float_isfinite (x) : __lo_ieee_isfinite (x))
107 
108 #define lo_ieee_isinf(x) \
109  (sizeof (x) == sizeof (float) \
110  ? __lo_ieee_float_isinf (x) : __lo_ieee_isinf (x))
111 
112 #define lo_ieee_is_NA(x) \
113  (sizeof (x) == sizeof (float) \
114  ? __lo_ieee_float_is_NA (x) : __lo_ieee_is_NA (x))
115 
116 #define lo_ieee_is_NaN_or_NA(x) \
117  (sizeof (x) == sizeof (float) \
118  ? __lo_ieee_float_is_NaN_or_NA (x) : __lo_ieee_is_NaN_or_NA (x))
119 
120 #define lo_ieee_signbit(x) \
121  (sizeof (x) == sizeof (float) \
122  ? __lo_ieee_float_signbit (x) : __lo_ieee_signbit (x))
123 
124 #if defined (__cplusplus)
125 
127 
128 template <typename T>
129 struct numeric_limits
130 {
131 public:
132  static T NA (void) { return static_cast<T> (0); }
133  static T NaN (void) { return static_cast<T> (0); }
134  static T Inf (void) { return static_cast<T> (0); }
135 };
136 
137 template <>
138 struct numeric_limits<double>
139 {
140 public:
141  static double NA (void) { return octave_NA; }
142  static double NaN (void) { return octave_NaN; }
143  static double Inf (void) { return octave_Inf; }
144 };
145 
146 template <>
147 struct numeric_limits<float>
148 {
149 public:
150  static float NA (void) { return octave_Float_NA; }
151  static float NaN (void) { return octave_Float_NaN; }
152  static float Inf (void) { return octave_Float_Inf; }
153 };
154 
156 
157 #endif
158 
159 #if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS)
160 
161 OCTAVE_DEPRECATED (7, "use '__lo_ieee_isfinite' instead")
162 inline int __lo_ieee_finite (double x) { return __lo_ieee_isfinite (x); }
163 
164 OCTAVE_DEPRECATED (7, "use '__lo_ieee_float_isfinite' instead")
165 inline int __lo_ieee_float_finite (float x)
166 { return __lo_ieee_float_isfinite (x); }
167 
168 #define lo_ieee_finite(x) lo_ieee_isfinite(x)
169 
170 #endif
171 
172 #endif
OCTAVE_END_NAMESPACE(octave)
#define Inf
Definition: Faddeeva.cc:260
#define NaN
Definition: Faddeeva.cc:261
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
OCTAVE_API float lo_ieee_float_nan_value(void)
Definition: lo-ieee.cc:116
int __lo_ieee_signbit(double x)
Definition: lo-ieee.h:82
#define octave_Float_Inf
Definition: lo-ieee.h:47
OCTAVE_API double lo_ieee_nan_value(void)
Definition: lo-ieee.cc:84
OCTAVE_API float lo_ieee_float_na_value(void)
Definition: lo-ieee.cc:108
int __lo_ieee_isfinite(double x)
Definition: lo-ieee.h:73
#define octave_Float_NaN
Definition: lo-ieee.h:53
OCTAVE_API double lo_ieee_inf_value(void)
Definition: lo-ieee.cc:68
int __lo_ieee_isinf(double x)
Definition: lo-ieee.h:74
#define octave_Inf
Definition: lo-ieee.h:38
OCTAVE_API int __lo_ieee_is_NA(double)
Definition: lo-ieee.cc:59
OCTAVE_API int __lo_ieee_float_is_NA(float)
Definition: lo-ieee.cc:92
#define octave_NA
Definition: lo-ieee.h:41
#define octave_NaN
Definition: lo-ieee.h:44
OCTAVE_API double lo_ieee_na_value(void)
Definition: lo-ieee.cc:76
int __lo_ieee_float_isinf(float x)
Definition: lo-ieee.h:86
int __lo_ieee_float_signbit(float x)
Definition: lo-ieee.h:94
OCTAVE_API void octave_ieee_init(void)
Definition: lo-ieee.cc:124
int __lo_ieee_float_isfinite(float x)
Definition: lo-ieee.h:85
#define octave_Float_NA
Definition: lo-ieee.h:50
int __lo_ieee_float_isnan(float x)
Definition: lo-ieee.h:84
OCTAVE_API float lo_ieee_float_inf_value(void)
Definition: lo-ieee.cc:100
int __lo_ieee_isnan(double x)
Definition: lo-ieee.h:72
bool isfinite(double x)
Definition: lo-mappers.h:192
bool isinf(double x)
Definition: lo-mappers.h:203
double signbit(double x)
Definition: lo-mappers.h:54
bool isnan(bool)
Definition: lo-mappers.h:178
F77_RET_T const F77_DBLE * x
#define OCTAVE_API
Definition: main.in.cc:55
double value
Definition: lo-ieee.h:60
float value
Definition: lo-ieee.h:66
unsigned int word
Definition: lo-ieee.h:67