GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
mach-info.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2017 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 #if defined (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 namespace octave
38 {
39  mach_info *mach_info::instance = 0;
40 
41  union equiv
42  {
43  double d;
44  int i[2];
45  };
46 
47  struct
49  {
51  equiv fp_par[4];
52  };
53 
54 #define INIT_FLT_PAR(fp, fmt, sm1, sm2, lrg1, lrg2, rt1, rt2, dv1, dv2) \
55  do \
56  { \
57  fp.fp_fmt = (fmt); \
58  fp.fp_par[0].i[0] = (sm1); fp.fp_par[0].i[1] = (sm2); \
59  fp.fp_par[1].i[0] = (lrg1); fp.fp_par[1].i[1] = (lrg2); \
60  fp.fp_par[2].i[0] = (rt1); fp.fp_par[2].i[1] = (rt2); \
61  fp.fp_par[3].i[0] = (dv1); fp.fp_par[3].i[1] = (dv2); \
62  } \
63  while (0)
64 
65  static int
66  equiv_compare (const equiv *std, const equiv *v, int len)
67  {
68  int i;
69  for (i = 0; i < len; i++)
70  if (v[i].i[0] != std[i].i[0] || v[i].i[1] != std[i].i[1])
71  return 0;
72  return 1;
73  }
74 
77  {
79 
80  float_params fp[5];
81 
83  1048576, 0,
84  2146435071, -1,
85  1017118720, 0,
86  1018167296, 0);
87 
89  0, 1048576,
90  -1, 2146435071,
91  0, 1017118720,
92  0, 1018167296);
93 
95  0, 0,
96  0, 0,
97  0, 0,
98  0, 0);
99 
100  equiv mach_fp_par[4];
101 
102  mach_fp_par[0].d = F77_FUNC (d1mach, D1MACH) (1);
103  mach_fp_par[1].d = F77_FUNC (d1mach, D1MACH) (2);
104  mach_fp_par[2].d = F77_FUNC (d1mach, D1MACH) (3);
105  mach_fp_par[3].d = F77_FUNC (d1mach, D1MACH) (4);
106 
107  int i = 0;
108  do
109  {
110  if (equiv_compare (fp[i].fp_par, mach_fp_par, 4))
111  {
112  retval = fp[i].fp_fmt;
113  break;
114  }
115  }
116  while (fp[++i].fp_fmt != mach_info::flt_fmt_unknown);
117 
118  return retval;
119  }
120 
121  static bool
123  {
124  // Are we little or big endian? From Harbison & Steele.
125 
126  union
127  {
128  long l;
129  char c[sizeof (long)];
130  } u;
131 
132  u.l = 1;
133 
134  return (u.c[sizeof (long) - 1] == 1);
135  }
136 
138  : native_float_fmt (get_float_format ()),
139  big_chief (ten_little_endians ()) { }
140 
141  bool
143  {
144  bool retval = true;
145 
146  if (! instance)
147  {
148  instance = new mach_info ();
149 
150  if (instance)
152  }
153 
154  if (! instance)
155  (*current_liboctave_error_handler)
156  ("unable to create command history object!");
157 
158  return retval;
159  }
160 
163  {
164  return (instance_ok ())
166  }
167 
168  bool
170  {
171  return (instance_ok ())
172  ? instance->big_chief : false;
173  }
174 
175  bool
177  {
178  return (instance_ok ())
179  ? (! instance->big_chief) : false;
180  }
181 
184  {
186 
187  if (s == "native" || s == "n")
188  retval = mach_info::native_float_format ();
189  else if (s == "ieee-be" || s == "b")
191  else if (s == "ieee-le" || s == "l")
193  else if (s == "unknown")
195  else
196  (*current_liboctave_error_handler) ("invalid architecture type specified");
197 
198  return retval;
199  }
200 
203  {
204  std::string retval = "unknown";
205 
206  switch (flt_fmt)
207  {
209  retval = "ieee-be";
210  break;
211 
213  retval = "ieee-le";
214  break;
215 
216  default:
217  break;
218  }
219 
220  return retval;
221  }
222 }
float_format native_float_fmt
Definition: mach-info.h:68
static int equiv_compare(const equiv *std, const equiv *v, int len)
Definition: mach-info.cc:66
double F77_FUNC(d1mach, D1MACH)(const octave_idx_type &)
Octave interface to the compression and uncompression libraries.
Definition: aepbalance.cc:47
static mach_info * instance
Definition: mach-info.h:63
static bool ten_little_endians(void)
Definition: mach-info.cc:122
OCTAVE_NORETURN liboctave_error_handler current_liboctave_error_handler
Definition: lo-error.c:38
double precision function d1mach(i)
Definition: d1mach.f:1
STL namespace.
octave::mach_info::float_format flt_fmt
Definition: load-save.cc:723
u
Definition: lu.cc:138
s
Definition: file-io.cc:2682
static bool words_little_endian(void)
Definition: mach-info.cc:176
static float_format string_to_float_format(const std::string &)
Definition: mach-info.cc:183
static bool words_big_endian(void)
Definition: mach-info.cc:169
static void add(fptr f)
static void cleanup_instance(void)
Definition: mach-info.h:65
static bool instance_ok(void)
Definition: mach-info.cc:142
octave_value retval
Definition: data.cc:6294
static std::string float_format_as_string(float_format)
Definition: mach-info.cc:202
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
Definition: lu.cc:138
static float_format native_float_format(void)
Definition: mach-info.cc:162
=val(i)}if ode{val(i)}occurs in table i
Definition: lookup.cc:239
mach_info::float_format fp_fmt
Definition: mach-info.cc:50
static mach_info::float_format get_float_format(void)
Definition: mach-info.cc:76
#define INIT_FLT_PAR(fp, fmt, sm1, sm2, lrg1, lrg2, rt1, rt2, dv1, dv2)
Definition: mach-info.cc:54
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:854