Mercurial > octave
annotate liboctave/system/mach-info.cc @ 21202:f7121e111991
maint: indent #ifdef blocks in liboctave and src directories.
* Array-C.cc, Array-b.cc, Array-ch.cc, Array-d.cc, Array-f.cc, Array-fC.cc,
Array-i.cc, Array-idx-vec.cc, Array-s.cc, Array-str.cc, Array-util.cc,
Array-voidp.cc, Array.cc, CColVector.cc, CDiagMatrix.cc, CMatrix.cc,
CNDArray.cc, CRowVector.cc, CSparse.cc, CSparse.h, DiagArray2.cc, MArray-C.cc,
MArray-d.cc, MArray-f.cc, MArray-fC.cc, MArray-i.cc, MArray-s.cc, MArray.cc,
MDiagArray2.cc, MSparse-C.cc, MSparse-d.cc, MSparse.h, MatrixType.cc,
PermMatrix.cc, Range.cc, Sparse-C.cc, Sparse-b.cc, Sparse-d.cc, Sparse.cc,
boolMatrix.cc, boolNDArray.cc, boolSparse.cc, chMatrix.cc, chNDArray.cc,
dColVector.cc, dDiagMatrix.cc, dMatrix.cc, dNDArray.cc, dRowVector.cc,
dSparse.cc, dSparse.h, dim-vector.cc, fCColVector.cc, fCDiagMatrix.cc,
fCMatrix.cc, fCNDArray.cc, fCRowVector.cc, fColVector.cc, fDiagMatrix.cc,
fMatrix.cc, fNDArray.cc, fRowVector.cc, idx-vector.cc, int16NDArray.cc,
int32NDArray.cc, int64NDArray.cc, int8NDArray.cc, intNDArray.cc,
uint16NDArray.cc, uint32NDArray.cc, uint64NDArray.cc, uint8NDArray.cc,
blaswrap.c, cquit.c, f77-extern.cc, f77-fcn.c, f77-fcn.h, lo-error.c, quit.cc,
quit.h, CmplxAEPBAL.cc, CmplxCHOL.cc, CmplxGEPBAL.cc, CmplxHESS.cc, CmplxLU.cc,
CmplxQR.cc, CmplxQRP.cc, CmplxSCHUR.cc, CmplxSVD.cc, CollocWt.cc, DASPK.cc,
DASRT.cc, DASSL.cc, EIG.cc, LSODE.cc, ODES.cc, Quad.cc, base-lu.cc, base-qr.cc,
dbleAEPBAL.cc, dbleCHOL.cc, dbleGEPBAL.cc, dbleHESS.cc, dbleLU.cc, dbleQR.cc,
dbleQRP.cc, dbleSCHUR.cc, dbleSVD.cc, eigs-base.cc, fCmplxAEPBAL.cc,
fCmplxCHOL.cc, fCmplxGEPBAL.cc, fCmplxHESS.cc, fCmplxLU.cc, fCmplxQR.cc,
fCmplxQRP.cc, fCmplxSCHUR.cc, fCmplxSVD.cc, fEIG.cc, floatAEPBAL.cc,
floatCHOL.cc, floatGEPBAL.cc, floatHESS.cc, floatLU.cc, floatQR.cc,
floatQRP.cc, floatSCHUR.cc, floatSVD.cc, lo-mappers.cc, lo-specfun.cc,
oct-convn.cc, oct-fftw.cc, oct-fftw.h, oct-norm.cc, oct-rand.cc,
oct-spparms.cc, randgamma.c, randmtzig.c, randpoisson.c, sparse-chol.cc,
sparse-dmsolve.cc, sparse-lu.cc, sparse-qr.cc, mx-defs.h, dir-ops.cc,
file-ops.cc, file-stat.cc, lo-sysdep.cc, mach-info.cc, oct-env.cc,
oct-group.cc, oct-openmp.h, oct-passwd.cc, oct-syscalls.cc, oct-time.cc,
oct-uname.cc, pathlen.h, sysdir.h, syswait.h, cmd-edit.cc, cmd-hist.cc,
data-conv.cc, f2c-main.c, glob-match.cc, lo-array-errwarn.cc,
lo-array-gripes.cc, lo-cutils.c, lo-cutils.h, lo-ieee.cc, lo-math.h,
lo-regexp.cc, lo-utils.cc, oct-base64.cc, oct-glob.cc, oct-inttypes.cc,
oct-inttypes.h, oct-locbuf.cc, oct-mutex.cc, oct-refcount.h, oct-rl-edit.c,
oct-rl-hist.c, oct-shlib.cc, oct-sort.cc, pathsearch.cc, singleton-cleanup.cc,
sparse-sort.cc, sparse-util.cc, statdefs.h, str-vec.cc, unwind-prot.cc,
url-transfer.cc, display-available.h, main-cli.cc, main-gui.cc, main.in.cc,
mkoctfile.in.cc, octave-config.in.cc, shared-fcns.h:
indent #ifdef blocks in liboctave and src directories.
author | Rik <rik@octave.org> |
---|---|
date | Sat, 06 Feb 2016 06:40:13 -0800 |
parents | 7cac4e7458f2 |
children | 40de9f8f23a6 |
rev | line source |
---|---|
1960 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
3 Copyright (C) 1996-2015 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 | |
21202
f7121e111991
maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents:
21136
diff
changeset
|
24 # include <config.h> |
1960 | 25 #endif |
26 | |
27 #include "f77-fcn.h" | |
2317 | 28 #include "lo-error.h" |
29 #include "mach-info.h" | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
30 #include "singleton-cleanup.h" |
1960 | 31 |
32 extern "C" | |
33 { | |
5275 | 34 double F77_FUNC (d1mach, D1MACH) (const octave_idx_type&); |
1960 | 35 } |
36 | |
2317 | 37 oct_mach_info *oct_mach_info::instance = 0; |
1960 | 38 |
39 union equiv | |
40 { | |
41 double d; | |
42 int i[2]; | |
43 }; | |
44 | |
45 struct | |
46 float_params | |
47 { | |
2317 | 48 oct_mach_info::float_format fp_fmt; |
1960 | 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 | |
11501
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
73 static oct_mach_info::float_format |
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
74 get_float_format (void) |
1960 | 75 { |
11501
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
76 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
|
77 |
1960 | 78 float_params fp[5]; |
79 | |
4574 | 80 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
|
81 1048576, 0, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
82 2146435071, -1, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
83 1017118720, 0, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
84 1018167296, 0); |
1960 | 85 |
4574 | 86 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
|
87 0, 1048576, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
88 -1, 2146435071, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
89 0, 1017118720, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
90 0, 1018167296); |
1960 | 91 |
4574 | 92 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
|
93 0, 0, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
94 0, 0, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
95 0, 0, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
96 0, 0); |
1960 | 97 |
98 equiv mach_fp_par[4]; | |
99 | |
3887 | 100 mach_fp_par[0].d = F77_FUNC (d1mach, D1MACH) (1); |
101 mach_fp_par[1].d = F77_FUNC (d1mach, D1MACH) (2); | |
102 mach_fp_par[2].d = F77_FUNC (d1mach, D1MACH) (3); | |
103 mach_fp_par[3].d = F77_FUNC (d1mach, D1MACH) (4); | |
1960 | 104 |
105 int i = 0; | |
106 do | |
107 { | |
108 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
|
109 { |
11501
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
110 retval = fp[i].fp_fmt; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
111 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
112 } |
1960 | 113 } |
4574 | 114 while (fp[++i].fp_fmt != oct_mach_info::flt_fmt_unknown); |
4605 | 115 |
11501
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
116 return retval; |
2317 | 117 } |
118 | |
11501
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
119 static bool |
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
120 ten_little_endians (void) |
2317 | 121 { |
122 // Are we little or big endian? From Harbison & Steele. | |
123 | |
124 union | |
125 { | |
126 long l; | |
127 char c[sizeof (long)]; | |
128 } u; | |
129 | |
130 u.l = 1; | |
131 | |
11501
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
132 return (u.c[sizeof (long) - 1] == 1); |
2317 | 133 } |
134 | |
135 oct_mach_info::oct_mach_info (void) | |
11501
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
136 : native_float_fmt (get_float_format ()), |
331fcc41ca23
data member initialization fixes
John W. Eaton <jwe@octave.org>
parents:
10314
diff
changeset
|
137 big_chief (ten_little_endians ()) { } |
2317 | 138 |
2926 | 139 bool |
140 oct_mach_info::instance_ok (void) | |
141 { | |
142 bool retval = true; | |
143 | |
144 if (! instance) | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
145 { |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
146 instance = new oct_mach_info (); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
147 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
148 if (instance) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
149 singleton_cleanup_list::add (cleanup_instance); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
150 } |
2926 | 151 |
152 if (! instance) | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
153 (*current_liboctave_error_handler) |
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
154 ("unable to create command history object!"); |
2926 | 155 |
156 return retval; | |
157 } | |
158 | |
2317 | 159 oct_mach_info::float_format |
160 oct_mach_info::native_float_format (void) | |
161 { | |
2926 | 162 return (instance_ok ()) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
163 ? instance->native_float_fmt : oct_mach_info::flt_fmt_unknown; |
2317 | 164 } |
165 | |
166 bool | |
167 oct_mach_info::words_big_endian (void) | |
168 { | |
2926 | 169 return (instance_ok ()) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
170 ? instance->big_chief : false; |
2317 | 171 } |
172 | |
173 bool | |
174 oct_mach_info::words_little_endian (void) | |
175 { | |
2926 | 176 return (instance_ok ()) |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
177 ? (! instance->big_chief) : false; |
2317 | 178 } |
179 | |
180 oct_mach_info::float_format | |
3504 | 181 oct_mach_info::string_to_float_format (const std::string& s) |
2317 | 182 { |
4574 | 183 oct_mach_info::float_format retval = oct_mach_info::flt_fmt_unknown; |
1960 | 184 |
2317 | 185 if (s == "native" || s == "n") |
5015 | 186 retval = oct_mach_info::native_float_format (); |
2317 | 187 else if (s == "ieee-be" || s == "b") |
4574 | 188 retval = oct_mach_info::flt_fmt_ieee_big_endian; |
2317 | 189 else if (s == "ieee-le" || s == "l") |
4574 | 190 retval = oct_mach_info::flt_fmt_ieee_little_endian; |
2317 | 191 else if (s == "unknown") |
4574 | 192 retval = oct_mach_info::flt_fmt_unknown; |
2317 | 193 else |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
194 (*current_liboctave_error_handler) ("invalid architecture type specified"); |
2317 | 195 |
196 return retval; | |
197 } | |
198 | |
3504 | 199 std::string |
2317 | 200 oct_mach_info::float_format_as_string (float_format flt_fmt) |
201 { | |
3504 | 202 std::string retval = "unknown"; |
2317 | 203 |
204 switch (flt_fmt) | |
205 { | |
4574 | 206 case flt_fmt_ieee_big_endian: |
14488
aa490c112c88
Normalize floating point format string conversions
Mike Miller <mtmiller@ieee.org>
parents:
14138
diff
changeset
|
207 retval = "ieee-be"; |
2317 | 208 break; |
209 | |
4574 | 210 case flt_fmt_ieee_little_endian: |
14488
aa490c112c88
Normalize floating point format string conversions
Mike Miller <mtmiller@ieee.org>
parents:
14138
diff
changeset
|
211 retval = "ieee-le"; |
2317 | 212 break; |
213 | |
214 default: | |
215 break; | |
216 } | |
217 | |
218 return retval; | |
1960 | 219 } |