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