GNU Octave  4.4.1
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-2018 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
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License 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 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if ! defined (octave_lo_ieee_h)
24 #define octave_lo_ieee_h 1
25 
26 #include <cmath>
27 
28 #include "octave-config.h"
29 
30 #if defined (__cplusplus)
31 extern "C" {
32 #endif
33 
34 /* Octave's idea of infinity. */
35 #define octave_Inf (lo_ieee_inf_value ())
36 
37 /* Octave's idea of a missing value. */
38 #define octave_NA (lo_ieee_na_value ())
39 
40 /* Octave's idea of not a number. */
41 #define octave_NaN (lo_ieee_nan_value ())
42 
43 /* Octave's idea of infinity. */
44 #define octave_Float_Inf (lo_ieee_float_inf_value ())
45 
46 /* Octave's idea of a missing value. */
47 #define octave_Float_NA (lo_ieee_float_na_value ())
48 
49 /* Octave's idea of not a number. */
50 #define octave_Float_NaN (lo_ieee_float_nan_value ())
51 
52 /* FIXME: This code assumes that a double has twice the
53  number of bits as an int */
54 
55 typedef union
56 {
57  double value;
58  unsigned int word[2];
60 
61 typedef union
62 {
63  float value;
64  unsigned int word;
66 
67 #define LO_IEEE_NA_HW_OLD 0x7ff00000
68 #define LO_IEEE_NA_LW_OLD 1954
69 #define LO_IEEE_NA_HW 0x7FF840F4
70 #define LO_IEEE_NA_LW 0x40000000
71 #define LO_IEEE_NA_FLOAT 0x7FC207A2
72 
73 extern OCTAVE_API void octave_ieee_init (void);
74 
75 inline int __lo_ieee_isnan (double x) { return std::isnan (x); }
76 inline int __lo_ieee_finite (double x) { return std::isfinite (x); }
77 inline int __lo_ieee_isinf (double x) { return std::isinf (x); }
78 
79 extern OCTAVE_API int __lo_ieee_is_NA (double);
80 extern OCTAVE_API int __lo_ieee_is_old_NA (double);
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 inline int __lo_ieee_signbit (double x) { return std::signbit (x); }
88 
89 inline int __lo_ieee_float_isnan (float x) { return std::isnan (x); }
90 inline int __lo_ieee_float_finite (float x) { return std::isfinite (x); }
91 inline int __lo_ieee_float_isinf (float x) { return std::isinf (x); }
92 
93 extern OCTAVE_API int __lo_ieee_float_is_NA (float);
94 
95 extern OCTAVE_API float lo_ieee_float_inf_value (void);
96 extern OCTAVE_API float lo_ieee_float_na_value (void);
97 extern OCTAVE_API float lo_ieee_float_nan_value (void);
98 
99 inline int __lo_ieee_float_signbit (float x) { return std::signbit (x); }
100 
101 #if defined (__cplusplus)
102 }
103 #endif
104 
105 #define lo_ieee_isnan(x) \
106  (sizeof (x) == sizeof (float) \
107  ? __lo_ieee_float_isnan (x) : __lo_ieee_isnan (x))
108 
109 #define lo_ieee_finite(x) \
110  (sizeof (x) == sizeof (float) \
111  ? __lo_ieee_float_finite (x) : __lo_ieee_finite (x))
112 
113 #define lo_ieee_isinf(x) \
114  (sizeof (x) == sizeof (float) \
115  ? __lo_ieee_float_isinf (x) : __lo_ieee_isinf (x))
116 
117 #define lo_ieee_is_NA(x) \
118  (sizeof (x) == sizeof (float) \
119  ? __lo_ieee_float_is_NA (x) : __lo_ieee_is_NA (x))
120 
121 #define lo_ieee_is_NaN_or_NA(x) \
122  (sizeof (x) == sizeof (float) \
123  ? __lo_ieee_float_is_NaN_or_NA (x) : __lo_ieee_is_NaN_or_NA (x))
124 
125 #define lo_ieee_signbit(x) \
126  (sizeof (x) == sizeof (float) \
127  ? __lo_ieee_float_signbit (x) : __lo_ieee_signbit (x))
128 
129 #if defined (__cplusplus)
130 
131 namespace octave
132 {
133  template <typename T>
134  struct numeric_limits
135  {
136  static T NA (void) { return static_cast<T> (0); }
137  static T NaN (void) { return static_cast<T> (0); }
138  static T Inf (void) { return static_cast<T> (0); }
139  };
140 
141  template <>
142  struct numeric_limits<double>
143  {
144  static double NA (void) { return octave_NA; }
145  static double NaN (void) { return octave_NaN; }
146  static double Inf (void) { return octave_Inf; }
147  };
148 
149  template <>
150  struct numeric_limits<float>
151  {
152  static float NA (void) { return octave_Float_NA; }
153  static float NaN (void) { return octave_Float_NaN; }
154  static float Inf (void) { return octave_Float_Inf; }
155  };
156 }
157 
158 #endif
159 
160 #endif
#define octave_Float_Inf
Definition: lo-ieee.h:44
int __lo_ieee_finite(double x)
Definition: lo-ieee.h:76
OCTAVE_API double lo_ieee_inf_value(void)
Definition: lo-ieee.cc:75
bool isnan(bool)
Definition: lo-mappers.h:187
OCTAVE_API float lo_ieee_float_na_value(void)
Definition: lo-ieee.cc:115
bool isinf(double x)
Definition: lo-mappers.h:225
OCTAVE_API int __lo_ieee_is_NA(double)
Definition: lo-ieee.cc:48
OCTAVE_API double lo_ieee_na_value(void)
Definition: lo-ieee.cc:83
int __lo_ieee_signbit(double x)
Definition: lo-ieee.h:87
#define octave_Float_NaN
Definition: lo-ieee.h:50
OCTAVE_API int __lo_ieee_float_is_NA(float)
Definition: lo-ieee.cc:99
double value
Definition: lo-ieee.h:57
float value
Definition: lo-ieee.h:63
OCTAVE_API double __lo_ieee_replace_old_NA(double)
Definition: lo-ieee.cc:66
int __lo_ieee_float_isinf(float x)
Definition: lo-ieee.h:91
OCTAVE_EXPORT octave_value_list or N dimensional array whose elements are all equal to the special constant used to designate missing values Note that NA always compares not equal to NA(NA !=NA). To find NA values
#define octave_Inf
Definition: lo-ieee.h:35
OCTAVE_API void octave_ieee_init(void)
Definition: lo-ieee.cc:131
#define octave_NA
Definition: lo-ieee.h:38
#define octave_Float_NA
Definition: lo-ieee.h:47
int __lo_ieee_isnan(double x)
Definition: lo-ieee.h:75
OCTAVE_API float lo_ieee_float_nan_value(void)
Definition: lo-ieee.cc:123
int __lo_ieee_isinf(double x)
Definition: lo-ieee.h:77
#define Inf
Definition: Faddeeva.cc:247
OCTAVE_API double lo_ieee_nan_value(void)
Definition: lo-ieee.cc:91
#define octave_NaN
Definition: lo-ieee.h:41
OCTAVE_EXPORT octave_value_list or N dimensional array whose elements are all equal to the IEEE symbol NaN(Not a Number). NaN is the result of operations which do not produce a well defined 0 result. Common operations which produce a NaN are arithmetic with infinity ex($\infty - \infty$)
unsigned int word
Definition: lo-ieee.h:64
bool isfinite(double x)
Definition: lo-mappers.h:201
int __lo_ieee_float_isnan(float x)
Definition: lo-ieee.h:89
int __lo_ieee_float_signbit(float x)
Definition: lo-ieee.h:99
int __lo_ieee_float_finite(float x)
Definition: lo-ieee.h:90
OCTAVE_API float lo_ieee_float_inf_value(void)
Definition: lo-ieee.cc:107
OCTAVE_API int __lo_ieee_is_old_NA(double)
Definition: lo-ieee.cc:57
double signbit(double x)
Definition: lo-mappers.h:63
F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE * x