1967
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 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 |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 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, write to the Free |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
1967
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
|
28 #include <cfloat> |
1977
|
29 #include <cmath> |
1967
|
30 |
|
31 #if defined (HAVE_FLOATINGPOINT_H) |
|
32 #include <floatingpoint.h> |
|
33 #endif |
|
34 |
3268
|
35 #if defined (HAVE_IEEEFP_H) |
|
36 #include <ieeefp.h> |
|
37 #endif |
|
38 |
2598
|
39 #if defined (HAVE_NAN_H) |
|
40 #if defined (SCO) |
2560
|
41 #define _IEEE 1 |
2598
|
42 #endif |
2508
|
43 #include <nan.h> |
2598
|
44 #if defined (SCO) |
2560
|
45 #undef _IEEE |
2508
|
46 #endif |
2598
|
47 #endif |
2508
|
48 |
4698
|
49 #include "lo-error.h" |
1967
|
50 #include "lo-ieee.h" |
4025
|
51 #include "mach-info.h" |
1967
|
52 |
|
53 void |
|
54 octave_ieee_init (void) |
|
55 { |
4698
|
56 // Default values. DBL_MAX is not right for NaN and NA, but do you |
|
57 // have a better suggestion? If you don't have IEEE floating point |
|
58 // values, there are many parts of Octave that will not work |
|
59 // correctly. |
|
60 |
|
61 octave_Inf = octave_NaN = octave_NA = DBL_MAX; |
|
62 |
4601
|
63 oct_mach_info::float_format ff = oct_mach_info::native_float_format (); |
|
64 |
4698
|
65 switch (ff) |
4601
|
66 { |
4698
|
67 case oct_mach_info::flt_fmt_ieee_big_endian: |
|
68 case oct_mach_info::flt_fmt_ieee_little_endian: |
|
69 { |
|
70 // Don't optimize away tmp_inf / tmp_inf to generate octave_NaN. |
|
71 |
|
72 volatile double tmp_inf; |
1967
|
73 |
2713
|
74 #if defined (SCO) |
4698
|
75 volatile double tmp = 1.0; |
|
76 tmp_inf = 1.0 / (tmp - tmp); |
4164
|
77 #elif defined (__alpha__) && defined (__osf__) |
4698
|
78 extern unsigned int DINFINITY[2]; |
|
79 tmp_inf = (*(X_CAST(double *, DINFINITY))); |
1967
|
80 #else |
4698
|
81 double tmp = 1e+10; |
|
82 tmp_inf = tmp; |
|
83 for (;;) |
|
84 { |
|
85 tmp_inf *= 1e+10; |
|
86 if (tmp_inf == tmp) |
|
87 break; |
|
88 tmp = tmp_inf; |
|
89 } |
1967
|
90 #endif |
|
91 |
4164
|
92 #if defined (__alpha__) && defined (__osf__) |
4698
|
93 extern unsigned int DQNAN[2]; |
|
94 octave_NaN = (*(X_CAST(double *, DQNAN))); |
1967
|
95 #else |
4698
|
96 octave_NaN = tmp_inf / tmp_inf; |
1967
|
97 #endif |
|
98 |
4698
|
99 octave_Inf = tmp_inf; |
|
100 |
|
101 // This is patterned after code in R. |
|
102 |
|
103 if (ff == oct_mach_info::flt_fmt_ieee_big_endian) |
|
104 { |
|
105 lo_ieee_hw = 0; |
|
106 lo_ieee_lw = 1; |
|
107 } |
|
108 else |
|
109 { |
|
110 lo_ieee_hw = 1; |
|
111 lo_ieee_lw = 0; |
|
112 } |
4025
|
113 |
4698
|
114 lo_ieee_double t; |
|
115 t.word[lo_ieee_hw] = LO_IEEE_NA_HW; |
|
116 t.word[lo_ieee_lw] = LO_IEEE_NA_LW; |
|
117 |
|
118 octave_NA = t.value; |
|
119 } |
|
120 break; |
4025
|
121 |
4698
|
122 case oct_mach_info::flt_fmt_cray: |
|
123 case oct_mach_info::flt_fmt_vax_d: |
|
124 case oct_mach_info::flt_fmt_vax_g: |
|
125 break; |
4025
|
126 |
4698
|
127 default: |
|
128 // If the format is unknown, then you will probably not have a |
|
129 // useful system, but we will just issue a warning and go on... |
|
130 (*current_liboctave_warning_handler) |
|
131 ("lo_ieee_init: unrecognized floating point format!"); |
4601
|
132 } |
1967
|
133 } |
|
134 |
|
135 /* |
|
136 ;;; Local Variables: *** |
|
137 ;;; mode: C++ *** |
|
138 ;;; End: *** |
|
139 */ |