GNU Octave  8.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
ls-utils.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2003-2023 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 "data-conv.h"
31 
32 #include "ls-utils.h"
33 
35 
36 // MAX_VAL and MIN_VAL are assumed to have integral values even though
37 // they are stored in doubles.
38 
40 get_save_type (double /* max_val */, double /* min_val */)
41 {
42  save_type st = LS_DOUBLE;
43 
44  // Matlab doesn't seem to load the UINT32 type correctly, so let's
45  // avoid it (and the other unsigned types, even though they may not
46  // have the same problem. And apparently, there are problems with
47  // other smaller types as well. If we avoid them all, then maybe we
48  // will avoid problems. Unfortunately, we won't be able to save
49  // space...
50 
51  // if (max_val < 256 && min_val > -1)
52  // st = LS_U_CHAR;
53  // else if (max_val < 65536 && min_val > -1)
54  // st = LS_U_SHORT;
55  // else if (max_val < 4294967295UL && min_val > -1)
56  // st = LS_U_INT;
57  // else if (max_val < 128 && min_val >= -128)
58  // st = LS_CHAR;
59  // else if (max_val < 32768 && min_val >= -32768)
60  // st = LS_SHORT;
61  // else if (max_val <= 2147483647L && min_val >= -2147483647L)
62  // st = LS_INT;
63 
64  return st;
65 }
66 
68 get_save_type (float /* max_val */, float /* min_val */)
69 {
70  save_type st = LS_FLOAT;
71 
72  // Matlab doesn't seem to load the UINT32 type correctly, so let's
73  // avoid it (and the other unsigned types, even though they may not
74  // have the same problem. And apparently, there are problems with
75  // other smaller types as well. If we avoid them all, then maybe we
76  // will avoid problems. Unfortunately, we won't be able to save
77  // space...
78 
79  // if (max_val < 256 && min_val > -1)
80  // st = LS_U_CHAR;
81  // else if (max_val < 65536 && min_val > -1)
82  // st = LS_U_SHORT;
83  // else if (max_val < 4294967295UL && min_val > -1)
84  // st = LS_U_INT;
85  // else if (max_val < 128 && min_val >= -128)
86  // st = LS_CHAR;
87  // else if (max_val < 32768 && min_val >= -32768)
88  // st = LS_SHORT;
89  // else if (max_val <= 2147483647L && min_val >= -2147483647L)
90  // st = LS_INT;
91 
92  return st;
93 }
94 
96 
OCTAVE_END_NAMESPACE(octave)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
save_type
Definition: data-conv.h:87
@ LS_DOUBLE
Definition: data-conv.h:95
@ LS_FLOAT
Definition: data-conv.h:94
save_type get_save_type(double, double)
Definition: ls-utils.cc:40