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 |
|
28 #include <stdlib.h> |
|
29 |
|
30 #include "error.h" |
444
|
31 #include "sysdep.h" |
|
32 |
|
33 // Octave's idea of infinity. |
|
34 double octave_Inf; |
|
35 |
|
36 // Octave's idea of not a number. |
|
37 double octave_NaN; |
1
|
38 |
401
|
39 #if defined (__386BSD__) && defined (HAVE_FLOATINGPOINT_H) |
|
40 #include <floatingpoint.h> |
|
41 #endif |
|
42 |
1
|
43 #ifdef NeXT |
|
44 extern "C" |
|
45 { |
|
46 typedef void (*_cplus_fcn_int) (int); |
|
47 extern void (*malloc_error (_cplus_fcn_int)) (int); |
|
48 } |
|
49 |
|
50 static void |
|
51 malloc_handler (int code) |
|
52 { |
|
53 if (code == 5) |
217
|
54 warning ("hopefully recoverable malloc error: freeing wild pointer"); |
1
|
55 else |
|
56 { |
|
57 panic ("probably irrecoverable malloc error: code %d", code); |
|
58 } |
|
59 } |
|
60 |
|
61 static void |
|
62 NeXT_init (void) |
|
63 { |
|
64 malloc_error (malloc_handler); |
|
65 } |
|
66 #endif |
|
67 |
444
|
68 static void |
|
69 octave_ieee_init (void) |
|
70 { |
|
71 #if defined (HAVE_ISINF) || defined (HAVE_FINITE) |
|
72 |
|
73 // Some version of gcc on some old version of Linux used to crash when |
|
74 // trying to make Inf and NaN. |
|
75 |
|
76 #if defined (HAVE_INFINITY) |
|
77 octave_Inf = infinity (); |
|
78 #else |
|
79 #ifdef linux |
|
80 octave_Inf = HUGE_VAL; |
|
81 #else |
|
82 double tmp = 1e+10; |
|
83 octave_Inf = tmp; |
|
84 for (;;) |
|
85 { |
|
86 octave_Inf *= 1e+10; |
|
87 if (octave_Inf == tmp) |
|
88 break; |
|
89 tmp = octave_Inf; |
|
90 } |
|
91 #endif |
|
92 #endif |
|
93 |
|
94 #if defined (HAVE_QUIET_NAN) |
|
95 octave_NaN = quiet_nan (); |
|
96 #else |
|
97 #ifdef linux |
|
98 octave_NaN = NAN; |
|
99 #else |
|
100 octave_NaN = octave_Inf / octave_Inf; |
|
101 #endif |
|
102 #endif |
|
103 |
|
104 #else |
|
105 |
|
106 // This is sort of cheesy, but what can we do, other than blowing it |
|
107 // off completely, or writing an entire IEEE emulation package? |
|
108 |
|
109 octave_Inf = DBL_MAX; |
|
110 octave_NaN = DBL_MAX; |
|
111 |
|
112 #endif |
|
113 } |
|
114 |
1
|
115 void |
|
116 sysdep_init (void) |
|
117 { |
401
|
118 #if defined (__386BSD__) && defined (HAVE_FLOATINGPOINT_H) |
|
119 // Disable trapping on common exceptions. |
|
120 fpsetmask (~(FP_X_OFL|FP_X_INV|FP_X_DZ|FP_X_DNML|FP_X_UFL|FP_X_IMP)); |
|
121 #endif |
|
122 |
1
|
123 #ifdef NeXT |
|
124 NeXT_init (); |
|
125 #endif |
444
|
126 |
|
127 octave_ieee_init (); |
1
|
128 } |
|
129 |
|
130 /* |
|
131 ;;; Local Variables: *** |
|
132 ;;; mode: C++ *** |
|
133 ;;; page-delimiter: "^/\\*" *** |
|
134 ;;; End: *** |
|
135 */ |