annotate liboctave/util/lo-ieee.cc @ 33658:b1d6e40ac737 stable tip

NEWS.9.md: Fix typo and minor formatting changes. * etc/NEWS.9.md: Fix typo. Adjust whitespace. Use markdown syntax for code snippets.
author Markus Mützel <markus.muetzel@gmx.de>
date Wed, 05 Jun 2024 11:27:35 +0200
parents 2e484f9f1f18
children 00e493a27de2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
32632
2e484f9f1f18 maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 31771
diff changeset
3 // Copyright (C) 1996-2024 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
25
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
26 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21202
diff changeset
27 # include "config.h"
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
28 #endif
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
29
18540
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
30 #include <cmath>
23448
e1c02e7126a9 avoid calling abort if possible; include cstdlib for declaration if needed
John W. Eaton <jwe@octave.org>
parents: 23443
diff changeset
31 #include <cstdlib>
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
32
11234
2718e1fdf82f IEEE math initialization tweaks
John W. Eaton <jwe@octave.org>
parents: 11230
diff changeset
33 #include <limits>
2508
f8d5dbbbc50a [project @ 1996-11-13 17:21:07 by jwe]
jwe
parents: 1993
diff changeset
34
23662
bd77ab816e43 eliminate obsolete file lo-math.h
John W. Eaton <jwe@octave.org>
parents: 23622
diff changeset
35 #include "lo-error.h"
bd77ab816e43 eliminate obsolete file lo-math.h
John W. Eaton <jwe@octave.org>
parents: 23622
diff changeset
36 #include "lo-ieee.h"
bd77ab816e43 eliminate obsolete file lo-math.h
John W. Eaton <jwe@octave.org>
parents: 23622
diff changeset
37 #include "mach-info.h"
bd77ab816e43 eliminate obsolete file lo-math.h
John W. Eaton <jwe@octave.org>
parents: 23622
diff changeset
38
18540
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
39 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
40 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
41 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
42
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
43 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
44 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
45 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
46
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
47 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
48 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
49
29986
3f598ae945f2 move macros from lo-ieee.h to lo-ieee.cc
John W. Eaton <jwe@octave.org>
parents: 29426
diff changeset
50 #if defined (HAVE_MIPS_NAN)
3f598ae945f2 move macros from lo-ieee.h to lo-ieee.cc
John W. Eaton <jwe@octave.org>
parents: 29426
diff changeset
51 #define LO_IEEE_NA_HW 0x7FF040F4
3f598ae945f2 move macros from lo-ieee.h to lo-ieee.cc
John W. Eaton <jwe@octave.org>
parents: 29426
diff changeset
52 #else
3f598ae945f2 move macros from lo-ieee.h to lo-ieee.cc
John W. Eaton <jwe@octave.org>
parents: 29426
diff changeset
53 #define LO_IEEE_NA_HW 0x7FF840F4
3f598ae945f2 move macros from lo-ieee.h to lo-ieee.cc
John W. Eaton <jwe@octave.org>
parents: 29426
diff changeset
54 #endif
3f598ae945f2 move macros from lo-ieee.h to lo-ieee.cc
John W. Eaton <jwe@octave.org>
parents: 29426
diff changeset
55 #define LO_IEEE_NA_LW 0x40000000
3f598ae945f2 move macros from lo-ieee.h to lo-ieee.cc
John W. Eaton <jwe@octave.org>
parents: 29426
diff changeset
56 #define LO_IEEE_NA_FLOAT 0x7FC207A2
3f598ae945f2 move macros from lo-ieee.h to lo-ieee.cc
John W. Eaton <jwe@octave.org>
parents: 29426
diff changeset
57
18540
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
58 int
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
59 __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
60 {
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_double t;
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
62 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
63 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
64 && 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
65 }
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
66
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
67 double
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
68 lo_ieee_inf_value ()
18540
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 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
71
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
72 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
73 }
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
74
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
75 double
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
76 lo_ieee_na_value ()
18540
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
77 {
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
78 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
79
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
80 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
81 }
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
82
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
83 double
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
84 lo_ieee_nan_value ()
18540
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
85 {
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
86 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
87
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
88 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
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_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
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_float 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_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
97 }
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 float
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
100 lo_ieee_float_inf_value ()
18540
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
101 {
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
102 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
103
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_float_inf;
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
105 }
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
106
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
107 float
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
108 lo_ieee_float_na_value ()
18540
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
109 {
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
110 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
111
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
112 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
113 }
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
114
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
115 float
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
116 lo_ieee_float_nan_value ()
18540
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
117 {
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
118 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
119
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
120 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
121 }
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
122
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
123 void
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
124 octave_ieee_init ()
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
125 {
26425
6bfed6e4e9e9 lo-ieee.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26376
diff changeset
126 static bool initialized = false;
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
127
18540
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
128 if (! initialized)
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
129 {
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
130 octave::mach_info::float_format ff = octave::mach_info::native_float_format ();
4698
737fd5c0ae06 [project @ 2004-01-19 19:25:26 by jwe]
jwe
parents: 4603
diff changeset
131
18540
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
132 switch (ff)
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
133 {
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
134 case octave::mach_info::flt_fmt_ieee_big_endian:
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
135 case octave::mach_info::flt_fmt_ieee_little_endian:
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10158
diff changeset
136 {
18540
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
137 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
138 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
139
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
140 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
141 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
142
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
143 // The following is patterned after code in R.
4025
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3475
diff changeset
144
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
145 if (ff == octave::mach_info::flt_fmt_ieee_big_endian)
18540
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 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
148 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
149 }
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
150 else
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
151 {
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
152 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
153 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
154 }
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7231
diff changeset
155
18540
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_double t;
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
157 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
158 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
159
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
160 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
161
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
162 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
163 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
164
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
165 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
166 }
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
167 break;
4025
cfb762dc9259 [project @ 2002-08-09 06:32:15 by jwe]
jwe
parents: 3475
diff changeset
168
18540
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
169 default:
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
170 // 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
171 // 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
172 // 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
173 // 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
174 // the configure test.
23448
e1c02e7126a9 avoid calling abort if possible; include cstdlib for declaration if needed
John W. Eaton <jwe@octave.org>
parents: 23443
diff changeset
175 //
26425
6bfed6e4e9e9 lo-ieee.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26376
diff changeset
176 // If the error handler returns, then we'll abort.
23448
e1c02e7126a9 avoid calling abort if possible; include cstdlib for declaration if needed
John W. Eaton <jwe@octave.org>
parents: 23443
diff changeset
177
18540
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
178 (*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
179 ("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?");
23448
e1c02e7126a9 avoid calling abort if possible; include cstdlib for declaration if needed
John W. Eaton <jwe@octave.org>
parents: 23443
diff changeset
180
18540
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
181 abort ();
89bd70fae066 fix initialization problem for Inf, NaN, and NA values (bug #41667)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
182 }
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 initialized = true;
4601
1ed6cfbc8ea4 [project @ 2003-11-12 18:30:29 by jwe]
jwe
parents: 4574
diff changeset
185 }
1967
4cb6aaa0f2c7 [project @ 1996-02-17 02:54:24 by jwe]
jwe
parents:
diff changeset
186 }