Mercurial > hg > octave-nkf
annotate liboctave/util/lo-ieee.cc @ 20830:b65888ec820e draft default tip gccjit
dmalcom gcc jit import
author | Stefan Mahr <dac922@gmx.de> |
---|---|
date | Fri, 27 Feb 2015 16:59:36 +0100 |
parents | 4197fc428c7d |
children |
rev | line source |
---|---|
1967 | 1 /* |
2 | |
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19519
diff
changeset
|
3 Copyright (C) 1996-2015 John W. Eaton |
1967 | 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 | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
1967 | 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 | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
1967 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
18608
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
27 #include <cfloat> |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
28 #include <cmath> |
9592
5828d64ca004
lo-ieee.cc: include cstdlib, update copyright date
John W. Eaton <jwe@octave.org>
parents:
9591
diff
changeset
|
29 #include <cstdlib> |
1967 | 30 |
11234
2718e1fdf82f
IEEE math initialization tweaks
John W. Eaton <jwe@octave.org>
parents:
11230
diff
changeset
|
31 #include <limits> |
2508 | 32 |
18608
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
33 static double lo_inf; |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
34 static double lo_nan; |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
35 static double lo_na; |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
36 |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
37 static float lo_float_inf; |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
38 static float lo_float_nan; |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
39 static float lo_float_na; |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
40 |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
41 static int lo_ieee_hw; |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
42 static int lo_ieee_lw; |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
43 |
4698 | 44 #include "lo-error.h" |
1967 | 45 #include "lo-ieee.h" |
18608
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
46 #include "lo-math.h" |
4025 | 47 #include "mach-info.h" |
1967 | 48 |
18608
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
49 int |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
50 __lo_ieee_isnan (double x) |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
51 { |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
52 #if defined (HAVE_CMATH_ISNAN) |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
53 return std::isnan (x); |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
54 #else |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
55 // Gnulib provides. |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
56 return isnan (x); |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
57 #endif |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
58 } |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
59 |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
60 int |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
61 __lo_ieee_finite (double x) |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
62 { |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
63 #if defined (HAVE_CMATH_ISFINITE) |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
64 return std::isfinite (x); |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
65 #else |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
66 // Gnulib provides. |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
67 return finite (x); |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
68 #endif |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
69 } |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
70 |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
71 int |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
72 __lo_ieee_isinf (double x) |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
73 { |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
74 #if defined (HAVE_CMATH_ISINF) |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
75 return std::isinf (x); |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
76 #else |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
77 // Gnulib provides. |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
78 return isinf (x); |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
79 #endif |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
80 } |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
81 |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
82 int |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
83 __lo_ieee_is_NA (double x) |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
84 { |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
85 lo_ieee_double t; |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
86 t.value = x; |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
87 return (__lo_ieee_isnan (x) && t.word[lo_ieee_hw] == LO_IEEE_NA_HW |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
88 && t.word[lo_ieee_lw] == LO_IEEE_NA_LW) ? 1 : 0; |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
89 } |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
90 |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
91 int |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
92 __lo_ieee_is_old_NA (double x) |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
93 { |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
94 lo_ieee_double t; |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
95 t.value = x; |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
96 return (__lo_ieee_isnan (x) && t.word[lo_ieee_lw] == LO_IEEE_NA_LW_OLD |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
97 && t.word[lo_ieee_hw] == LO_IEEE_NA_HW_OLD) ? 1 : 0; |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
98 } |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
99 |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
100 double |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
101 __lo_ieee_replace_old_NA (double x) |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
102 { |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
103 if (__lo_ieee_is_old_NA (x)) |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
104 return lo_ieee_na_value (); |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
105 else |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
106 return x; |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
107 } |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
108 |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
109 double |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
110 lo_ieee_inf_value (void) |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
111 { |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
112 octave_ieee_init (); |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
113 |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
114 return lo_inf; |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
115 } |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
116 |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
117 double |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
118 lo_ieee_na_value (void) |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
119 { |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
120 octave_ieee_init (); |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
121 |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
122 return lo_na; |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
123 } |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
124 |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
125 double |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
126 lo_ieee_nan_value (void) |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
127 { |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
128 octave_ieee_init (); |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
129 |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
130 return lo_nan; |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
131 } |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
132 |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
133 int |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
134 __lo_ieee_signbit (double x) |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
135 { |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
136 #if defined (HAVE_CMATH_SIGNBIT) |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
137 return std::signbit (x); |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
138 #else |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
139 // Gnulib provides. |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
140 return signbit (x); |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
141 #endif |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
142 } |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
143 |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
144 int |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
145 __lo_ieee_float_isnan (float x) |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
146 { |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
147 #if defined (HAVE_CMATH_ISNAN) |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
148 return std::isnan (x); |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
149 #else |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
150 // Gnulib provides. |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
151 return isnan (x); |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
152 #endif |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
153 } |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
154 |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
155 int |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
156 __lo_ieee_float_finite (float x) |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
157 { |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
158 #if defined (HAVE_CMATH_ISFINITE) |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
159 return std::isfinite (x) != 0 && ! __lo_ieee_float_isnan (x); |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
160 #else |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
161 // Gnulib provides. |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
162 return finite (x); |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
163 #endif |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
164 } |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
165 |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
166 int |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
167 __lo_ieee_float_isinf (float x) |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
168 { |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
169 #if defined (HAVE_CMATH_ISINF) |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
170 return std::isinf (x); |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
171 #else |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
172 // Gnulib provides. |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
173 return isinf (x); |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
174 #endif |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
175 } |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
176 |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
177 int |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
178 __lo_ieee_float_is_NA (float x) |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
179 { |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
180 lo_ieee_float t; |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
181 t.value = x; |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
182 return (__lo_ieee_float_isnan (x) && (t.word == LO_IEEE_NA_FLOAT)) ? 1 : 0; |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
183 } |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
184 |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
185 float |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
186 lo_ieee_float_inf_value (void) |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
187 { |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
188 octave_ieee_init (); |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
189 |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
190 return lo_float_inf; |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
191 } |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
192 |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
193 float |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
194 lo_ieee_float_na_value (void) |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
195 { |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
196 octave_ieee_init (); |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
197 |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
198 return lo_float_na; |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
199 } |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
200 |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
201 float |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
202 lo_ieee_float_nan_value (void) |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
203 { |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
204 octave_ieee_init (); |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
205 |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
206 return lo_float_nan; |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
207 } |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
208 |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
209 int |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
210 __lo_ieee_float_signbit (float x) |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
211 { |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
212 #if defined (HAVE_CMATH_SIGNBIT) |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
213 return std::signbit (x); |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
214 #else |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
215 // Gnulib provides. |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
216 return signbit (x); |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
217 #endif |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
218 } |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
219 |
1967 | 220 void |
221 octave_ieee_init (void) | |
222 { | |
18608
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
223 bool initialized = false; |
1967 | 224 |
18608
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
225 if (! initialized) |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
226 { |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
227 oct_mach_info::float_format ff = oct_mach_info::native_float_format (); |
4698 | 228 |
18608
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
229 switch (ff) |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
230 { |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
231 case oct_mach_info::flt_fmt_ieee_big_endian: |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
232 case oct_mach_info::flt_fmt_ieee_little_endian: |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
233 { |
18608
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
234 lo_nan = std::numeric_limits<double>::quiet_NaN (); |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
235 lo_inf = std::numeric_limits<double>::infinity (); |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
236 |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
237 lo_float_nan = std::numeric_limits<float>::quiet_NaN (); |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
238 lo_float_inf = std::numeric_limits<float>::infinity (); |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
239 |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
240 // The following is patterned after code in R. |
4025 | 241 |
18608
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
242 if (ff == oct_mach_info::flt_fmt_ieee_big_endian) |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
243 { |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
244 lo_ieee_hw = 0; |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
245 lo_ieee_lw = 1; |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
246 } |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
247 else |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
248 { |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
249 lo_ieee_hw = 1; |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
250 lo_ieee_lw = 0; |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
251 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
252 |
18608
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
253 lo_ieee_double t; |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
254 t.word[lo_ieee_hw] = LO_IEEE_NA_HW; |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
255 t.word[lo_ieee_lw] = LO_IEEE_NA_LW; |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
256 |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
257 lo_na = t.value; |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
258 |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
259 lo_ieee_float tf; |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
260 tf.word = LO_IEEE_NA_FLOAT; |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
261 |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
262 lo_float_na = tf.value; |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
263 } |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
264 break; |
4025 | 265 |
18608
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
266 default: |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
267 // If the format is unknown, then you will probably not have a |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
268 // useful system, so we will abort here. Anyone wishing to |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
269 // experiment with building Octave on a system without IEEE |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
270 // floating point should be capable of removing this check and |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
271 // the configure test. |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
272 (*current_liboctave_error_handler) |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
273 ("lo_ieee_init: floating point format is not IEEE! Maybe DLAMCH is miscompiled, or you are using some strange system without IEEE floating point math?"); |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
274 abort (); |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
275 } |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
276 |
89bd70fae066
fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
277 initialized = true; |
4601 | 278 } |
1967 | 279 } |