GNU Octave
3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Pages
liboctave
system
mach-info.cc
Go to the documentation of this file.
1
/*
2
3
Copyright (C) 1996-2013 John W. Eaton
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
9
Free Software Foundation; either version 3 of the License, or (at your
10
option) any later version.
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
18
along with Octave; see the file COPYING. If not, see
19
<http://www.gnu.org/licenses/>.
20
21
*/
22
23
#ifdef HAVE_CONFIG_H
24
#include <config.h>
25
#endif
26
27
#include "
f77-fcn.h
"
28
#include "
lo-error.h
"
29
#include "
mach-info.h
"
30
#include "
singleton-cleanup.h
"
31
32
extern
"C"
33
{
34
double
F77_FUNC
(
d1mach
, D1MACH) (
const
octave_idx_type
&);
35
}
36
37
oct_mach_info
*
oct_mach_info::instance
= 0;
38
39
union
equiv
40
{
41
double
d
;
42
int
i
[2];
43
};
44
45
struct
46
float_params
47
{
48
oct_mach_info::float_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
static
oct_mach_info::float_format
74
get_float_format
(
void
)
75
{
76
oct_mach_info::float_format
retval =
oct_mach_info::flt_fmt_unknown
;
77
78
float_params
fp[5];
79
80
INIT_FLT_PAR
(fp[0],
oct_mach_info::flt_fmt_ieee_big_endian
,
81
1048576, 0,
82
2146435071, -1,
83
1017118720, 0,
84
1018167296, 0);
85
86
INIT_FLT_PAR
(fp[1],
oct_mach_info::flt_fmt_ieee_little_endian
,
87
0, 1048576,
88
-1, 2146435071,
89
0, 1017118720,
90
0, 1018167296);
91
92
INIT_FLT_PAR
(fp[4],
oct_mach_info::flt_fmt_unknown
,
93
0, 0,
94
0, 0,
95
0, 0,
96
0, 0);
97
98
equiv
mach_fp_par[4];
99
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);
104
105
int
i = 0;
106
do
107
{
108
if
(
equiv_compare
(fp[i].fp_par, mach_fp_par, 4))
109
{
110
retval = fp[i].
fp_fmt
;
111
break
;
112
}
113
}
114
while
(fp[++i].fp_fmt !=
oct_mach_info::flt_fmt_unknown
);
115
116
return
retval;
117
}
118
119
static
bool
120
ten_little_endians
(
void
)
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
132
return
(u.c[sizeof (
long
) - 1] == 1);
133
}
134
135
oct_mach_info::oct_mach_info
(
void
)
136
: native_float_fmt (
get_float_format
()),
137
big_chief (
ten_little_endians
()) { }
138
139
bool
140
oct_mach_info::instance_ok
(
void
)
141
{
142
bool
retval =
true
;
143
144
if
(!
instance
)
145
{
146
instance
=
new
oct_mach_info
();
147
148
if
(
instance
)
149
singleton_cleanup_list::add
(
cleanup_instance
);
150
}
151
152
if
(!
instance
)
153
{
154
(*current_liboctave_error_handler)
155
(
"unable to create command history object!"
);
156
157
retval =
false
;
158
}
159
160
return
retval;
161
}
162
163
oct_mach_info::float_format
164
oct_mach_info::native_float_format
(
void
)
165
{
166
return
(
instance_ok
())
167
?
instance
->
native_float_fmt
:
oct_mach_info::flt_fmt_unknown
;
168
}
169
170
bool
171
oct_mach_info::words_big_endian
(
void
)
172
{
173
return
(
instance_ok
())
174
?
instance
->
big_chief
:
false
;
175
}
176
177
bool
178
oct_mach_info::words_little_endian
(
void
)
179
{
180
return
(
instance_ok
())
181
? (!
instance
->
big_chief
) :
false
;
182
}
183
184
oct_mach_info::float_format
185
oct_mach_info::string_to_float_format
(
const
std::string& s)
186
{
187
oct_mach_info::float_format
retval =
oct_mach_info::flt_fmt_unknown
;
188
189
if
(s ==
"native"
|| s ==
"n"
)
190
retval =
oct_mach_info::native_float_format
();
191
else
if
(s ==
"ieee-be"
|| s ==
"b"
)
192
retval =
oct_mach_info::flt_fmt_ieee_big_endian
;
193
else
if
(s ==
"ieee-le"
|| s ==
"l"
)
194
retval =
oct_mach_info::flt_fmt_ieee_little_endian
;
195
else
if
(s ==
"unknown"
)
196
retval =
oct_mach_info::flt_fmt_unknown
;
197
else
198
(*
current_liboctave_error_handler
)
199
(
"invalid architecture type specified"
);
200
201
return
retval;
202
}
203
204
std::string
205
oct_mach_info::float_format_as_string
(
float_format
flt_fmt)
206
{
207
std::string retval =
"unknown"
;
208
209
switch
(flt_fmt)
210
{
211
case
flt_fmt_ieee_big_endian
:
212
retval =
"ieee-be"
;
213
break
;
214
215
case
flt_fmt_ieee_little_endian
:
216
retval =
"ieee-le"
;
217
break
;
218
219
default
:
220
break
;
221
}
222
223
return
retval;
224
}
Generated on Mon Dec 30 2013 03:04:53 for GNU Octave by
1.8.1.2