GNU Octave  9.1.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-2024 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 
42 
43 OCTAVE_BEGIN_NAMESPACE(mach_info)
44 
45 static float_format get_float_format ()
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
61 is_big_endian ()
62 {
63  return octave_is_big_endian ();
64 }
65 
68 {
69  static float_format fmt = get_float_format ();
70 
71  return fmt;
72 }
73 
74 bool
76 {
77  static bool big_endian = is_big_endian ();
78 
79  return big_endian;
80 }
81 
82 bool
84 {
85  static bool little_endian = ! is_big_endian ();
86 
87  return little_endian;
88 }
89 
91 string_to_float_format (const std::string& s)
92 {
94 
95  if (s == "native" || s == "n")
96  retval = native_float_format ();
97  else if (s == "ieee-be" || s == "b")
98  retval = flt_fmt_ieee_big_endian;
99  else if (s == "ieee-le" || s == "l")
101  else if (s == "unknown")
102  retval = flt_fmt_unknown;
103  else
105  ("invalid architecture type specified");
106 
107  return retval;
108 }
109 
110 std::string
112 {
113  std::string retval = "unknown";
114 
115  switch (flt_fmt)
116  {
118  retval = "ieee-be";
119  break;
120 
122  retval = "ieee-le";
123  break;
124 
125  default:
126  break;
127  }
128 
129  return retval;
130 }
131 
132 OCTAVE_END_NAMESPACE(mach_info)
133 OCTAVE_END_NAMESPACE(octave)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
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
bool words_little_endian()
Definition: mach-info.cc:83
std::string float_format_as_string(float_format flt_fmt)
Definition: mach-info.cc:111
bool words_big_endian()
Definition: mach-info.cc:75
float_format native_float_format()
Definition: mach-info.cc:67
float_format string_to_float_format(const std::string &s)
Definition: mach-info.cc:91
int octave_get_float_format(void)
Definition: cmach-info.c:77
@ flt_fmt_ieee_big_endian
Definition: mach-info.h:44
@ flt_fmt_unknown
Definition: mach-info.h:42
@ flt_fmt_ieee_little_endian
Definition: mach-info.h:43