GNU Octave  4.2.1
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-2017 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 #include "octave-config.h"
27 
28 #if defined (__cplusplus)
29 extern "C" {
30 #endif
31 
32 /* Octave's idea of infinity. */
33 #define octave_Inf (lo_ieee_inf_value ())
34 
35 /* Octave's idea of a missing value. */
36 #define octave_NA (lo_ieee_na_value ())
37 
38 /* Octave's idea of not a number. */
39 #define octave_NaN (lo_ieee_nan_value ())
40 
41 /* Octave's idea of infinity. */
42 #define octave_Float_Inf (lo_ieee_float_inf_value ())
43 
44 /* Octave's idea of a missing value. */
45 #define octave_Float_NA (lo_ieee_float_na_value ())
46 
47 /* Octave's idea of not a number. */
48 #define octave_Float_NaN (lo_ieee_float_nan_value ())
49 
50 /* FIXME: This code assumes that a double has twice the
51  number of bits as an int */
52 
53 typedef union
54 {
55  double value;
56  unsigned int word[2];
58 
59 typedef union
60 {
61  float value;
62  unsigned int word;
64 
65 #define LO_IEEE_NA_HW_OLD 0x7ff00000
66 #define LO_IEEE_NA_LW_OLD 1954
67 #define LO_IEEE_NA_HW 0x7FF840F4
68 #define LO_IEEE_NA_LW 0x40000000
69 #define LO_IEEE_NA_FLOAT 0x7FC207A2
70 
71 extern OCTAVE_API void octave_ieee_init (void);
72 
73 extern OCTAVE_API int __lo_ieee_isnan (double x);
74 extern OCTAVE_API int __lo_ieee_finite (double x);
75 extern OCTAVE_API int __lo_ieee_isinf (double x);
76 
77 extern OCTAVE_API int __lo_ieee_is_NA (double);
78 extern OCTAVE_API int __lo_ieee_is_old_NA (double);
79 extern OCTAVE_API double __lo_ieee_replace_old_NA (double);
80 
81 extern OCTAVE_API double lo_ieee_inf_value (void);
82 extern OCTAVE_API double lo_ieee_na_value (void);
83 extern OCTAVE_API double lo_ieee_nan_value (void);
84 
85 extern OCTAVE_API int __lo_ieee_signbit (double);
86 
87 extern OCTAVE_API int __lo_ieee_float_isnan (float x);
88 extern OCTAVE_API int __lo_ieee_float_finite (float x);
89 extern OCTAVE_API int __lo_ieee_float_isinf (float x);
90 
91 extern OCTAVE_API int __lo_ieee_float_is_NA (float);
92 
93 extern OCTAVE_API float lo_ieee_float_inf_value (void);
94 extern OCTAVE_API float lo_ieee_float_na_value (void);
95 extern OCTAVE_API float lo_ieee_float_nan_value (void);
96 
97 extern OCTAVE_API int __lo_ieee_float_signbit (float);
98 
99 #if defined (__cplusplus)
100 }
101 #endif
102 
103 #define lo_ieee_isnan(x) \
104  (sizeof (x) == sizeof (float) \
105  ? __lo_ieee_float_isnan (x) : __lo_ieee_isnan (x))
106 
107 #define lo_ieee_finite(x) \
108  (sizeof (x) == sizeof (float) \
109  ? __lo_ieee_float_finite (x) : __lo_ieee_finite (x))
110 
111 #define lo_ieee_isinf(x) \
112  (sizeof (x) == sizeof (float) \
113  ? __lo_ieee_float_isinf (x) : __lo_ieee_isinf (x))
114 
115 #define lo_ieee_is_NA(x) \
116  (sizeof (x) == sizeof (float) \
117  ? __lo_ieee_float_is_NA (x) : __lo_ieee_is_NA (x))
118 
119 #define lo_ieee_is_NaN_or_NA(x) \
120  (sizeof (x) == sizeof (float) \
121  ? __lo_ieee_float_is_NaN_or_NA (x) : __lo_ieee_is_NaN_or_NA (x))
122 
123 #define lo_ieee_signbit(x) \
124  (sizeof (x) == sizeof (float) \
125  ? __lo_ieee_float_signbit (x) : __lo_ieee_signbit (x))
126 
127 #if defined (__cplusplus)
128 
129 namespace octave
130 {
131  template <typename T>
132  struct numeric_limits
133  {
134  static T NA (void) { return static_cast<T> (0); }
135  static T NaN (void) { return static_cast<T> (0); }
136  static T Inf (void) { return static_cast<T> (0); }
137  };
138 
139  template <>
140  struct numeric_limits<double>
141  {
142  static double NA (void) { return octave_NA; }
143  static double NaN (void) { return octave_NaN; }
144  static double Inf (void) { return octave_Inf; }
145  };
146 
147  template <>
148  struct numeric_limits<float>
149  {
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 }
155 
156 #endif
157 
158 #endif
Octave interface to the compression and uncompression libraries.
Definition: aepbalance.cc:47
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
#define octave_Float_Inf
Definition: lo-ieee.h:42
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
#define octave_Float_NaN
Definition: lo-ieee.h:48
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:55
float value
Definition: lo-ieee.h:61
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
#define octave_Inf
Definition: lo-ieee.h:33
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
OCTAVE_API void octave_ieee_init(void)
Definition: lo-ieee.cc:221
#define octave_NA
Definition: lo-ieee.h:36
#define octave_Float_NA
Definition: lo-ieee.h:45
OCTAVE_API float lo_ieee_float_nan_value(void)
Definition: lo-ieee.cc:202
#define Inf
Definition: Faddeeva.cc:247
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
#define octave_NaN
Definition: lo-ieee.h:39
unsigned int word
Definition: lo-ieee.h:62
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 $)
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 F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &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 F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE * x