GNU Octave  9.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-2024 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 #if defined (__cplusplus)
32 # include <cmath>
33 
34 extern "C" {
35 #else
36 # include <math.h>
37 #endif
38 
39 /* Octave's idea of infinity. */
40 #define octave_Inf (lo_ieee_inf_value ())
41 
42 /* Octave's idea of a missing value. */
43 #define octave_NA (lo_ieee_na_value ())
44 
45 /* Octave's idea of not a number. */
46 #define octave_NaN (lo_ieee_nan_value ())
47 
48 /* Octave's idea of infinity. */
49 #define octave_Float_Inf (lo_ieee_float_inf_value ())
50 
51 /* Octave's idea of a missing value. */
52 #define octave_Float_NA (lo_ieee_float_na_value ())
53 
54 /* Octave's idea of not a number. */
55 #define octave_Float_NaN (lo_ieee_float_nan_value ())
56 
57 /* FIXME: This code assumes that a double has twice the
58  number of bits as an int */
59 
60 typedef union
61  {
62  double value;
63  unsigned int word[2];
65 
66 typedef union
67  {
68  float value;
69  unsigned int word;
71 
72 extern OCTAVE_API void octave_ieee_init (void);
73 
74 #if defined (__cplusplus)
75 inline int __lo_ieee_isnan (double x) { return std::isnan (x); }
76 inline int __lo_ieee_isfinite (double x) { return std::isfinite (x); }
77 inline int __lo_ieee_isinf (double x) { return std::isinf (x); }
78 
79 inline int __lo_ieee_signbit (double x) { return std::signbit (x); }
80 
81 inline int __lo_ieee_float_isnan (float x) { return std::isnan (x); }
82 inline int __lo_ieee_float_isfinite (float x) { return std::isfinite (x); }
83 inline int __lo_ieee_float_isinf (float x) { return std::isinf (x); }
84 
85 inline int __lo_ieee_float_signbit (float x) { return std::signbit (x); }
86 #else
87 inline int __lo_ieee_isnan (double x) { return isnan (x); }
88 inline int __lo_ieee_isfinite (double x) { return isfinite (x); }
89 inline int __lo_ieee_isinf (double x) { return isinf (x); }
90 
91 inline int __lo_ieee_signbit (double x) { return signbit (x); }
92 
93 inline int __lo_ieee_float_isnan (float x) { return isnan (x); }
94 inline int __lo_ieee_float_isfinite (float x) { return isfinite (x); }
95 inline int __lo_ieee_float_isinf (float x) { return isinf (x); }
96 
97 inline int __lo_ieee_float_signbit (float x) { return signbit (x); }
98 #endif
99 
100 extern OCTAVE_API int __lo_ieee_is_NA (double);
101 
102 extern OCTAVE_API double lo_ieee_inf_value (void);
103 extern OCTAVE_API double lo_ieee_na_value (void);
104 extern OCTAVE_API double lo_ieee_nan_value (void);
105 
106 extern OCTAVE_API int __lo_ieee_float_is_NA (float);
107 
108 extern OCTAVE_API float lo_ieee_float_inf_value (void);
109 extern OCTAVE_API float lo_ieee_float_na_value (void);
110 extern OCTAVE_API float lo_ieee_float_nan_value (void);
111 
112 #if defined (__cplusplus)
113 }
114 #endif
115 
116 #define lo_ieee_isnan(x) \
117  (sizeof (x) == sizeof (float) \
118  ? __lo_ieee_float_isnan (x) : __lo_ieee_isnan (x))
119 
120 #define lo_ieee_isfinite(x) \
121  (sizeof (x) == sizeof (float) \
122  ? __lo_ieee_float_isfinite (x) : __lo_ieee_isfinite (x))
123 
124 #define lo_ieee_isinf(x) \
125  (sizeof (x) == sizeof (float) \
126  ? __lo_ieee_float_isinf (x) : __lo_ieee_isinf (x))
127 
128 #define lo_ieee_is_NA(x) \
129  (sizeof (x) == sizeof (float) \
130  ? __lo_ieee_float_is_NA (x) : __lo_ieee_is_NA (x))
131 
132 #define lo_ieee_signbit(x) \
133  (sizeof (x) == sizeof (float) \
134  ? __lo_ieee_float_signbit (x) : __lo_ieee_signbit (x))
135 
136 #if defined (__cplusplus)
137 
139 
140 template <typename T>
141 struct numeric_limits
142 {
143 public:
144  static T NA () { return static_cast<T> (0); }
145  static T NaN () { return static_cast<T> (0); }
146  static T Inf () { return static_cast<T> (0); }
147 };
148 
149 template <>
150 struct numeric_limits<double>
151 {
152 public:
153  static double NA () { return octave_NA; }
154  static double NaN () { return octave_NaN; }
155  static double Inf () { return octave_Inf; }
156 };
157 
158 template <>
159 struct numeric_limits<float>
160 {
161 public:
162  static float NA () { return octave_Float_NA; }
163  static float NaN () { return octave_Float_NaN; }
164  static float Inf () { return octave_Float_Inf; }
165 };
166 
167 OCTAVE_END_NAMESPACE(octave)
168 
169 #endif
170 
171 #endif
#define Inf
Definition: Faddeeva.cc:260
#define NaN
Definition: Faddeeva.cc:261
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
double lo_ieee_inf_value(void)
Definition: lo-ieee.cc:68
double lo_ieee_na_value(void)
Definition: lo-ieee.cc:76
float lo_ieee_float_inf_value(void)
Definition: lo-ieee.cc:100
int __lo_ieee_signbit(double x)
Definition: lo-ieee.h:91
#define octave_Float_Inf
Definition: lo-ieee.h:49
void octave_ieee_init(void)
Definition: lo-ieee.cc:124
int __lo_ieee_isfinite(double x)
Definition: lo-ieee.h:88
#define octave_Float_NaN
Definition: lo-ieee.h:55
int __lo_ieee_isinf(double x)
Definition: lo-ieee.h:89
#define octave_Inf
Definition: lo-ieee.h:40
#define octave_NA
Definition: lo-ieee.h:43
#define octave_NaN
Definition: lo-ieee.h:46
int __lo_ieee_float_isinf(float x)
Definition: lo-ieee.h:95
int __lo_ieee_float_signbit(float x)
Definition: lo-ieee.h:97
double lo_ieee_nan_value(void)
Definition: lo-ieee.cc:84
int __lo_ieee_float_isfinite(float x)
Definition: lo-ieee.h:94
int __lo_ieee_float_is_NA(float)
Definition: lo-ieee.cc:92
float lo_ieee_float_na_value(void)
Definition: lo-ieee.cc:108
#define octave_Float_NA
Definition: lo-ieee.h:52
float lo_ieee_float_nan_value(void)
Definition: lo-ieee.cc:116
int __lo_ieee_float_isnan(float x)
Definition: lo-ieee.h:93
int __lo_ieee_isnan(double x)
Definition: lo-ieee.h:87
int __lo_ieee_is_NA(double)
Definition: lo-ieee.cc:59
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.cc:55
double value
Definition: lo-ieee.h:62
float value
Definition: lo-ieee.h:68
unsigned int word
Definition: lo-ieee.h:69