GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
mach-info.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1996-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if defined (HAVE_CONFIG_H)
27 # include "config.h"
28 #endif
29 
30 #include "f77-fcn.h"
31 #include "lo-error.h"
32 #include "mach-info.h"
33 
34 extern "C"
35 {
36  int octave_get_float_format (void);
37 
38  int octave_is_big_endian (void);
39 }
40 
41 namespace octave
42 {
43  namespace mach_info
44  {
46  {
47  switch (octave_get_float_format ())
48  {
49  case 1:
51 
52  case 2:
54 
55  default:
56  return flt_fmt_unknown;
57  }
58  }
59 
60  static bool is_big_endian (void)
61  {
62  return octave_is_big_endian ();
63  }
64 
66  {
67  static float_format fmt = get_float_format ();
68 
69  return fmt;
70  }
71 
72  bool words_big_endian (void)
73  {
74  static bool big_endian = is_big_endian ();
75 
76  return big_endian;
77  }
78 
79  bool words_little_endian (void)
80  {
81  static bool little_endian = ! is_big_endian ();
82 
83  return little_endian;
84  }
85 
86  float_format string_to_float_format (const std::string& s)
87  {
89 
90  if (s == "native" || s == "n")
92  else if (s == "ieee-be" || s == "b")
94  else if (s == "ieee-le" || s == "l")
96  else if (s == "unknown")
98  else
100  ("invalid architecture type specified");
101 
102  return retval;
103  }
104 
105  std::string float_format_as_string (float_format flt_fmt)
106  {
107  std::string retval = "unknown";
108 
109  switch (flt_fmt)
110  {
112  retval = "ieee-be";
113  break;
114 
116  retval = "ieee-le";
117  break;
118 
119  default:
120  break;
121  }
122 
123  return retval;
124  }
125  }
126 }
OCTAVE_NORETURN liboctave_error_handler current_liboctave_error_handler
Definition: lo-error.c:41
int octave_is_big_endian(void)
Definition: cmach-info.c:132
int octave_get_float_format(void)
Definition: cmach-info.c:77
static bool is_big_endian(void)
Definition: mach-info.cc:60
std::string float_format_as_string(float_format flt_fmt)
Definition: mach-info.cc:105
static float_format get_float_format(void)
Definition: mach-info.cc:45
float_format native_float_format(void)
Definition: mach-info.cc:65
bool words_little_endian(void)
Definition: mach-info.cc:79
@ flt_fmt_ieee_little_endian
Definition: mach-info.h:43
bool words_big_endian(void)
Definition: mach-info.cc:72
float_format string_to_float_format(const std::string &s)
Definition: mach-info.cc:86
octave_value::octave_value(const Array< char > &chm, char type) return retval
Definition: ov.cc:811