Mercurial > hg > octave-lyh
annotate liboctave/mach-info.cc @ 13061:addfc0ae69c0
Make bicgstab interface more compatible
* bicgstab.m: Add the possibility to pass a function
handle for the coefficient matrix. Also add more tests.
author | Carlo de Falco <kingcrimson@tiscali.it> |
---|---|
date | Sat, 03 Sep 2011 20:06:30 +0200 |
parents | fd0a3ac60b0e |
children | 7dd7cccf0757 |
rev | line source |
---|---|
1960 | 1 /* |
2 | |
11523 | 3 Copyright (C) 1996-2011 John W. Eaton |
1960 | 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 | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
1960 | 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 | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
1960 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
27 #include "f77-fcn.h" | |
2317 | 28 #include "lo-error.h" |
29 #include "mach-info.h" | |
1960 | 30 |
31 extern "C" | |
32 { | |
5275 | 33 double F77_FUNC (d1mach, D1MACH) (const octave_idx_type&); |
1960 | 34 } |
35 | |
2317 | 36 oct_mach_info *oct_mach_info::instance = 0; |
1960 | 37 |
38 union equiv | |
39 { | |
40 double d; | |
41 int i[2]; | |
42 }; | |
43 | |
44 struct | |
45 float_params | |
46 { | |
2317 | 47 oct_mach_info::float_format fp_fmt; |
1960 | 48 equiv fp_par[4]; |
49 }; | |
50 | |
51 #define INIT_FLT_PAR(fp, fmt, sm1, sm2, lrg1, lrg2, rt1, rt2, dv1, dv2) \ | |
52 do \ | |
53 { \ | |
54 fp.fp_fmt = (fmt); \ | |
55 fp.fp_par[0].i[0] = (sm1); fp.fp_par[0].i[1] = (sm2); \ | |
56 fp.fp_par[1].i[0] = (lrg1); fp.fp_par[1].i[1] = (lrg2); \ | |
57 fp.fp_par[2].i[0] = (rt1); fp.fp_par[2].i[1] = (rt2); \ | |
58 fp.fp_par[3].i[0] = (dv1); fp.fp_par[3].i[1] = (dv2); \ | |
59 } \ | |
60 while (0) | |
61 | |
62 static int | |
63 equiv_compare (const equiv *std, const equiv *v, int len) | |
64 { | |
65 int i; | |
66 for (i = 0; i < len; i++) | |
67 if (v[i].i[0] != std[i].i[0] || v[i].i[1] != std[i].i[1]) | |
68 return 0; | |
69 return 1; | |
70 } | |
71 | |
11501
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
72 static oct_mach_info::float_format |
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
73 get_float_format (void) |
1960 | 74 { |
11501
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
75 oct_mach_info::float_format retval = oct_mach_info::flt_fmt_unknown; |
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
76 |
4605 | 77 #if defined (CRAY) |
78 | |
5775 | 79 // FIXME -- this should be determined automatically. |
4605 | 80 |
81 native_float_fmt = oct_mach_info::flt_fmt_cray; | |
82 | |
83 #else | |
84 | |
1960 | 85 float_params fp[5]; |
86 | |
4574 | 87 INIT_FLT_PAR (fp[0], oct_mach_info::flt_fmt_ieee_big_endian, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
88 1048576, 0, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
89 2146435071, -1, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
90 1017118720, 0, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
91 1018167296, 0); |
1960 | 92 |
4574 | 93 INIT_FLT_PAR (fp[1], oct_mach_info::flt_fmt_ieee_little_endian, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
94 0, 1048576, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
95 -1, 2146435071, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
96 0, 1017118720, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
97 0, 1018167296); |
1960 | 98 |
4574 | 99 INIT_FLT_PAR (fp[2], oct_mach_info::flt_fmt_vax_d, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
100 128, 0, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
101 -32769, -1, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
102 9344, 0, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
103 9344, 0); |
1960 | 104 |
4574 | 105 INIT_FLT_PAR (fp[3], oct_mach_info::flt_fmt_vax_g, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
106 16, 0, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
107 -32769, -1, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
108 15552, 0, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
109 15552, 0); |
1960 | 110 |
4574 | 111 INIT_FLT_PAR (fp[4], oct_mach_info::flt_fmt_unknown, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
112 0, 0, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
113 0, 0, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
114 0, 0, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
115 0, 0); |
1960 | 116 |
117 equiv mach_fp_par[4]; | |
118 | |
3887 | 119 mach_fp_par[0].d = F77_FUNC (d1mach, D1MACH) (1); |
120 mach_fp_par[1].d = F77_FUNC (d1mach, D1MACH) (2); | |
121 mach_fp_par[2].d = F77_FUNC (d1mach, D1MACH) (3); | |
122 mach_fp_par[3].d = F77_FUNC (d1mach, D1MACH) (4); | |
1960 | 123 |
124 int i = 0; | |
125 do | |
126 { | |
127 if (equiv_compare (fp[i].fp_par, mach_fp_par, 4)) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
128 { |
11501
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
129 retval = fp[i].fp_fmt; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
130 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
131 } |
1960 | 132 } |
4574 | 133 while (fp[++i].fp_fmt != oct_mach_info::flt_fmt_unknown); |
4605 | 134 |
135 #endif | |
11501
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
136 |
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
137 return retval; |
2317 | 138 } |
139 | |
11501
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
140 static bool |
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
141 ten_little_endians (void) |
2317 | 142 { |
143 // Are we little or big endian? From Harbison & Steele. | |
144 | |
145 union | |
146 { | |
147 long l; | |
148 char c[sizeof (long)]; | |
149 } u; | |
150 | |
151 u.l = 1; | |
152 | |
11501
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
153 return (u.c[sizeof (long) - 1] == 1); |
2317 | 154 } |
155 | |
156 oct_mach_info::oct_mach_info (void) | |
11501
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
157 : native_float_fmt (get_float_format ()), |
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
158 big_chief (ten_little_endians ()) { } |
2317 | 159 |
2926 | 160 bool |
161 oct_mach_info::instance_ok (void) | |
162 { | |
163 bool retval = true; | |
164 | |
165 if (! instance) | |
166 instance = new oct_mach_info (); | |
167 | |
168 if (! instance) | |
169 { | |
170 (*current_liboctave_error_handler) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
171 ("unable to create command history object!"); |
2926 | 172 |
173 retval = false; | |
174 } | |
175 | |
176 return retval; | |
177 } | |
178 | |
2317 | 179 oct_mach_info::float_format |
180 oct_mach_info::native_float_format (void) | |
181 { | |
2926 | 182 return (instance_ok ()) |
4574 | 183 ? instance->native_float_fmt : oct_mach_info::flt_fmt_unknown; |
2317 | 184 } |
185 | |
186 bool | |
187 oct_mach_info::words_big_endian (void) | |
188 { | |
2926 | 189 return (instance_ok ()) |
190 ? instance->big_chief : false; | |
2317 | 191 } |
192 | |
193 bool | |
194 oct_mach_info::words_little_endian (void) | |
195 { | |
2926 | 196 return (instance_ok ()) |
197 ? (! instance->big_chief) : false; | |
2317 | 198 } |
199 | |
200 oct_mach_info::float_format | |
3504 | 201 oct_mach_info::string_to_float_format (const std::string& s) |
2317 | 202 { |
4574 | 203 oct_mach_info::float_format retval = oct_mach_info::flt_fmt_unknown; |
1960 | 204 |
2317 | 205 if (s == "native" || s == "n") |
5015 | 206 retval = oct_mach_info::native_float_format (); |
2317 | 207 else if (s == "ieee-be" || s == "b") |
4574 | 208 retval = oct_mach_info::flt_fmt_ieee_big_endian; |
2317 | 209 else if (s == "ieee-le" || s == "l") |
4574 | 210 retval = oct_mach_info::flt_fmt_ieee_little_endian; |
2317 | 211 else if (s == "vaxd" || s == "d") |
4574 | 212 retval = oct_mach_info::flt_fmt_vax_d; |
2759 | 213 else if (s == "vaxg" || s == "g") |
4574 | 214 retval = oct_mach_info::flt_fmt_vax_g; |
2317 | 215 else if (s == "cray" || s == "c") |
4574 | 216 retval = oct_mach_info::flt_fmt_cray; |
2317 | 217 else if (s == "unknown") |
4574 | 218 retval = oct_mach_info::flt_fmt_unknown; |
2317 | 219 else |
220 (*current_liboctave_error_handler) | |
221 ("invalid architecture type specified"); | |
222 | |
223 return retval; | |
224 } | |
225 | |
3504 | 226 std::string |
2317 | 227 oct_mach_info::float_format_as_string (float_format flt_fmt) |
228 { | |
3504 | 229 std::string retval = "unknown"; |
2317 | 230 |
231 switch (flt_fmt) | |
232 { | |
4574 | 233 case flt_fmt_ieee_big_endian: |
2317 | 234 retval = "ieee_big_endian"; |
235 break; | |
236 | |
4574 | 237 case flt_fmt_ieee_little_endian: |
2317 | 238 retval = "ieee_little_endian"; |
239 break; | |
240 | |
4574 | 241 case flt_fmt_vax_d: |
2317 | 242 retval = "vax_d_float"; |
243 break; | |
244 | |
4574 | 245 case flt_fmt_vax_g: |
2317 | 246 retval = "vax_g_float"; |
247 break; | |
248 | |
4574 | 249 case flt_fmt_cray: |
2317 | 250 retval = "cray"; |
251 break; | |
252 | |
253 default: | |
254 break; | |
255 } | |
256 | |
257 return retval; | |
1960 | 258 } |