GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
lo-ieee.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1996-2025 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
34extern "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
60typedef union
61 {
62 double value;
63 unsigned int word[2];
65
66typedef union
67 {
68 float value;
69 unsigned int word;
71
72extern OCTAVE_API void octave_ieee_init (void);
73
74#if defined (__cplusplus)
75OCTAVE_DEPRECATED (10, "use std::isnan instead")
76inline int __lo_ieee_isnan (double x) { return std::isnan (x); }
77OCTAVE_DEPRECATED (10, "use std::isfinite instead")
78inline int __lo_ieee_isfinite (double x) { return std::isfinite (x); }
79OCTAVE_DEPRECATED (10, "use std::isinf instead")
80inline int __lo_ieee_isinf (double x) { return std::isinf (x); }
81
82OCTAVE_DEPRECATED (10, "use std::signbit instead")
83inline int __lo_ieee_signbit (double x) { return std::signbit (x); }
84
85OCTAVE_DEPRECATED (10, "use std::isnan instead")
86inline int __lo_ieee_float_isnan (float x) { return std::isnan (x); }
87OCTAVE_DEPRECATED (10, "use std::isfinite instead")
88inline int __lo_ieee_float_isfinite (float x) { return std::isfinite (x); }
89OCTAVE_DEPRECATED (10, "use std::isinf instead")
90inline int __lo_ieee_float_isinf (float x) { return std::isinf (x); }
91
92OCTAVE_DEPRECATED (10, "use std::signbit instead")
93inline int __lo_ieee_float_signbit (float x) { return std::signbit (x); }
94#else
95OCTAVE_DEPRECATED (10, "use isnan instead")
96inline int __lo_ieee_isnan (double x) { return isnan (x); }
97OCTAVE_DEPRECATED (10, "use isfinite instead")
98inline int __lo_ieee_isfinite (double x) { return isfinite (x); }
99OCTAVE_DEPRECATED (10, "use isinf instead")
100inline int __lo_ieee_isinf (double x) { return isinf (x); }
101
102OCTAVE_DEPRECATED (10, "use signbit instead")
103inline int __lo_ieee_signbit (double x) { return signbit (x); }
104
105OCTAVE_DEPRECATED (10, "use isnan instead")
106inline int __lo_ieee_float_isnan (float x) { return isnan (x); }
107OCTAVE_DEPRECATED (10, "use isfinite instead")
108inline int __lo_ieee_float_isfinite (float x) { return isfinite (x); }
109OCTAVE_DEPRECATED (10, "use isinf instead")
110inline int __lo_ieee_float_isinf (float x) { return isinf (x); }
111
112OCTAVE_DEPRECATED (10, "use signbit instead")
113inline int __lo_ieee_float_signbit (float x) { return signbit (x); }
114#endif
115
116extern OCTAVE_API int __lo_ieee_is_NA (double);
117
118extern OCTAVE_API double lo_ieee_inf_value (void);
119extern OCTAVE_API double lo_ieee_na_value (void);
120extern OCTAVE_API double lo_ieee_nan_value (void);
121
122extern OCTAVE_API int __lo_ieee_float_is_NA (float);
123
124extern OCTAVE_API float lo_ieee_float_inf_value (void);
125extern OCTAVE_API float lo_ieee_float_na_value (void);
126extern OCTAVE_API float lo_ieee_float_nan_value (void);
127
128#if defined (__cplusplus)
129}
130#endif
131
132#define lo_ieee_isnan(x) \
133 (sizeof (x) == sizeof (float) \
134 ? __lo_ieee_float_isnan (x) : __lo_ieee_isnan (x))
135
136#define lo_ieee_isfinite(x) \
137 (sizeof (x) == sizeof (float) \
138 ? __lo_ieee_float_isfinite (x) : __lo_ieee_isfinite (x))
139
140#define lo_ieee_isinf(x) \
141 (sizeof (x) == sizeof (float) \
142 ? __lo_ieee_float_isinf (x) : __lo_ieee_isinf (x))
143
144#define lo_ieee_is_NA(x) \
145 (sizeof (x) == sizeof (float) \
146 ? __lo_ieee_float_is_NA (x) : __lo_ieee_is_NA (x))
147
148#define lo_ieee_signbit(x) \
149 (sizeof (x) == sizeof (float) \
150 ? __lo_ieee_float_signbit (x) : __lo_ieee_signbit (x))
151
152#if defined (__cplusplus)
153
155
156template <typename T>
157struct numeric_limits
158{
159public:
160 static T NA () { return static_cast<T> (0); }
161 static T NaN () { return static_cast<T> (0); }
162 static T Inf () { return static_cast<T> (0); }
163};
164
165template <>
166struct numeric_limits<double>
167{
168public:
169 static double NA () { return octave_NA; }
170 static double NaN () { return octave_NaN; }
171 static double Inf () { return octave_Inf; }
172};
173
174template <>
175struct numeric_limits<float>
176{
177public:
178 static float NA () { return octave_Float_NA; }
179 static float NaN () { return octave_Float_NaN; }
180 static float Inf () { return octave_Float_Inf; }
181};
182
183OCTAVE_END_NAMESPACE(octave)
184
185#endif
186
187#endif
#define Inf
Definition Faddeeva.cc:257
#define NaN
Definition Faddeeva.cc:258
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:103
#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:98
#define octave_Float_NaN
Definition lo-ieee.h:55
int __lo_ieee_isinf(double x)
Definition lo-ieee.h:100
#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:110
int __lo_ieee_float_signbit(float x)
Definition lo-ieee.h:113
double lo_ieee_nan_value(void)
Definition lo-ieee.cc:84
int __lo_ieee_float_isfinite(float x)
Definition lo-ieee.h:108
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:106
int __lo_ieee_isnan(double x)
Definition lo-ieee.h:96
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.in.cc:55
double value
Definition lo-ieee.h:62
float value
Definition lo-ieee.h:68
unsigned int word
Definition lo-ieee.h:69