1960
|
1 // float-fmt.cc -*- C++ -*- |
|
2 /* |
|
3 |
|
4 Copyright (C) 1996 John W. Eaton |
|
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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
|
28 #include "f77-fcn.h" |
|
29 #include "float-fmt.h" |
|
30 |
|
31 extern "C" |
|
32 { |
|
33 double F77_FCN (d1mach, D1MACH) (const int&); |
|
34 } |
|
35 |
|
36 // The floating point format on this system. |
|
37 floating_point_format native_float_format = OCTAVE_UNKNOWN_FLT_FMT; |
|
38 |
|
39 union equiv |
|
40 { |
|
41 double d; |
|
42 int i[2]; |
|
43 }; |
|
44 |
|
45 struct |
|
46 float_params |
|
47 { |
|
48 floating_point_format fp_fmt; |
|
49 equiv fp_par[4]; |
|
50 }; |
|
51 |
|
52 #define INIT_FLT_PAR(fp, fmt, sm1, sm2, lrg1, lrg2, rt1, rt2, dv1, dv2) \ |
|
53 do \ |
|
54 { \ |
|
55 fp.fp_fmt = (fmt); \ |
|
56 fp.fp_par[0].i[0] = (sm1); fp.fp_par[0].i[1] = (sm2); \ |
|
57 fp.fp_par[1].i[0] = (lrg1); fp.fp_par[1].i[1] = (lrg2); \ |
|
58 fp.fp_par[2].i[0] = (rt1); fp.fp_par[2].i[1] = (rt2); \ |
|
59 fp.fp_par[3].i[0] = (dv1); fp.fp_par[3].i[1] = (dv2); \ |
|
60 } \ |
|
61 while (0) |
|
62 |
|
63 static int |
|
64 equiv_compare (const equiv *std, const equiv *v, int len) |
|
65 { |
|
66 int i; |
|
67 for (i = 0; i < len; i++) |
|
68 if (v[i].i[0] != std[i].i[0] || v[i].i[1] != std[i].i[1]) |
|
69 return 0; |
|
70 return 1; |
|
71 } |
|
72 |
|
73 int |
|
74 float_format_init (void) |
|
75 { |
|
76 float_params fp[5]; |
|
77 |
|
78 INIT_FLT_PAR (fp[0], OCTAVE_IEEE_BIG, |
|
79 1048576, 0, |
|
80 2146435071, -1, |
|
81 1017118720, 0, |
|
82 1018167296, 0); |
|
83 |
|
84 INIT_FLT_PAR (fp[1], OCTAVE_IEEE_LITTLE, |
|
85 0, 1048576, |
|
86 -1, 2146435071, |
|
87 0, 1017118720, |
|
88 0, 1018167296); |
|
89 |
|
90 INIT_FLT_PAR (fp[2], OCTAVE_VAX_D, |
|
91 128, 0, |
|
92 -32769, -1, |
|
93 9344, 0, |
|
94 9344, 0); |
|
95 |
|
96 INIT_FLT_PAR (fp[3], OCTAVE_VAX_G, |
|
97 16, 0, |
|
98 -32769, -1, |
|
99 15552, 0, |
|
100 15552, 0); |
|
101 |
|
102 INIT_FLT_PAR (fp[4], OCTAVE_UNKNOWN_FLT_FMT, |
|
103 0, 0, |
|
104 0, 0, |
|
105 0, 0, |
|
106 0, 0); |
|
107 |
|
108 equiv mach_fp_par[4]; |
|
109 |
|
110 mach_fp_par[0].d = F77_FCN (d1mach, D1MACH) (1); |
|
111 mach_fp_par[1].d = F77_FCN (d1mach, D1MACH) (2); |
|
112 mach_fp_par[2].d = F77_FCN (d1mach, D1MACH) (3); |
|
113 mach_fp_par[3].d = F77_FCN (d1mach, D1MACH) (4); |
|
114 |
|
115 int i = 0; |
|
116 do |
|
117 { |
|
118 if (equiv_compare (fp[i].fp_par, mach_fp_par, 4)) |
|
119 { |
|
120 native_float_format = fp[i].fp_fmt; |
|
121 break; |
|
122 } |
|
123 } |
|
124 while (fp[++i].fp_fmt != OCTAVE_UNKNOWN_FLT_FMT); |
|
125 |
|
126 return (native_float_format != OCTAVE_UNKNOWN_FLT_FMT); |
|
127 } |
|
128 |
|
129 /* |
|
130 ;;; Local Variables: *** |
|
131 ;;; mode: C++ *** |
|
132 ;;; page-delimiter: "^/\\*" *** |
|
133 ;;; End: *** |
|
134 */ |