1
|
1 // sysdep.cc -*- C++ -*- |
|
2 /* |
|
3 |
401
|
4 Copyright (C) 1993, 1994 John W. Eaton |
1
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
240
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include "config.h" |
1
|
26 #endif |
|
27 |
470
|
28 #include <math.h> |
1
|
29 #include <stdlib.h> |
|
30 |
|
31 #include "error.h" |
444
|
32 #include "sysdep.h" |
|
33 |
|
34 // Octave's idea of infinity. |
|
35 double octave_Inf; |
|
36 |
|
37 // Octave's idea of not a number. |
|
38 double octave_NaN; |
1
|
39 |
401
|
40 #if defined (__386BSD__) && defined (HAVE_FLOATINGPOINT_H) |
|
41 #include <floatingpoint.h> |
|
42 #endif |
|
43 |
1
|
44 #ifdef NeXT |
|
45 extern "C" |
|
46 { |
|
47 typedef void (*_cplus_fcn_int) (int); |
|
48 extern void (*malloc_error (_cplus_fcn_int)) (int); |
|
49 } |
|
50 |
|
51 static void |
|
52 malloc_handler (int code) |
|
53 { |
|
54 if (code == 5) |
217
|
55 warning ("hopefully recoverable malloc error: freeing wild pointer"); |
1
|
56 else |
|
57 { |
|
58 panic ("probably irrecoverable malloc error: code %d", code); |
|
59 } |
|
60 } |
|
61 |
|
62 static void |
|
63 NeXT_init (void) |
|
64 { |
|
65 malloc_error (malloc_handler); |
|
66 } |
|
67 #endif |
|
68 |
444
|
69 static void |
|
70 octave_ieee_init (void) |
|
71 { |
|
72 #if defined (HAVE_ISINF) || defined (HAVE_FINITE) |
|
73 |
|
74 // Some version of gcc on some old version of Linux used to crash when |
|
75 // trying to make Inf and NaN. |
|
76 |
|
77 #if defined (HAVE_INFINITY) |
470
|
78 octave_Inf = (double) infinity (); |
444
|
79 #else |
|
80 #ifdef linux |
|
81 octave_Inf = HUGE_VAL; |
|
82 #else |
|
83 double tmp = 1e+10; |
|
84 octave_Inf = tmp; |
|
85 for (;;) |
|
86 { |
|
87 octave_Inf *= 1e+10; |
|
88 if (octave_Inf == tmp) |
|
89 break; |
|
90 tmp = octave_Inf; |
|
91 } |
|
92 #endif |
|
93 #endif |
|
94 |
|
95 #if defined (HAVE_QUIET_NAN) |
470
|
96 octave_NaN = (double) quiet_nan (); |
444
|
97 #else |
|
98 #ifdef linux |
|
99 octave_NaN = NAN; |
|
100 #else |
|
101 octave_NaN = octave_Inf / octave_Inf; |
|
102 #endif |
|
103 #endif |
|
104 |
|
105 #else |
|
106 |
|
107 // This is sort of cheesy, but what can we do, other than blowing it |
|
108 // off completely, or writing an entire IEEE emulation package? |
|
109 |
|
110 octave_Inf = DBL_MAX; |
|
111 octave_NaN = DBL_MAX; |
|
112 |
|
113 #endif |
|
114 } |
|
115 |
1
|
116 void |
|
117 sysdep_init (void) |
|
118 { |
401
|
119 #if defined (__386BSD__) && defined (HAVE_FLOATINGPOINT_H) |
|
120 // Disable trapping on common exceptions. |
|
121 fpsetmask (~(FP_X_OFL|FP_X_INV|FP_X_DZ|FP_X_DNML|FP_X_UFL|FP_X_IMP)); |
|
122 #endif |
|
123 |
1
|
124 #ifdef NeXT |
|
125 NeXT_init (); |
|
126 #endif |
444
|
127 |
|
128 octave_ieee_init (); |
1
|
129 } |
|
130 |
|
131 /* |
|
132 ;;; Local Variables: *** |
|
133 ;;; mode: C++ *** |
|
134 ;;; page-delimiter: "^/\\*" *** |
|
135 ;;; End: *** |
|
136 */ |