GNU Octave  6.2.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-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 "data-conv.h"
31 
32 #include "ls-utils.h"
33 
34 // MAX_VAL and MIN_VAL are assumed to have integral values even though
35 // they are stored in doubles.
36 
38 get_save_type (double /* max_val */, double /* min_val */)
39 {
40  save_type st = LS_DOUBLE;
41 
42  // Matlab doesn't seem to load the UINT32 type correctly, so let's
43  // avoid it (and the other unsigned types, even though they may not
44  // have the same problem. And apparently, there are problems with
45  // other smaller types as well. If we avoid them all, then maybe we
46  // will avoid problems. Unfortunately, we won't be able to save
47  // space...
48 
49  // if (max_val < 256 && min_val > -1)
50  // st = LS_U_CHAR;
51  // else if (max_val < 65536 && min_val > -1)
52  // st = LS_U_SHORT;
53  // else if (max_val < 4294967295UL && min_val > -1)
54  // st = LS_U_INT;
55  // else if (max_val < 128 && min_val >= -128)
56  // st = LS_CHAR;
57  // else if (max_val < 32768 && min_val >= -32768)
58  // st = LS_SHORT;
59  // else if (max_val <= 2147483647L && min_val >= -2147483647L)
60  // st = LS_INT;
61 
62  return st;
63 }
64 
66 get_save_type (float /* max_val */, float /* min_val */)
67 {
68  save_type st = LS_FLOAT;
69 
70  // Matlab doesn't seem to load the UINT32 type correctly, so let's
71  // avoid it (and the other unsigned types, even though they may not
72  // have the same problem. And apparently, there are problems with
73  // other smaller types as well. If we avoid them all, then maybe we
74  // will avoid problems. Unfortunately, we won't be able to save
75  // space...
76 
77  // if (max_val < 256 && min_val > -1)
78  // st = LS_U_CHAR;
79  // else if (max_val < 65536 && min_val > -1)
80  // st = LS_U_SHORT;
81  // else if (max_val < 4294967295UL && min_val > -1)
82  // st = LS_U_INT;
83  // else if (max_val < 128 && min_val >= -128)
84  // st = LS_CHAR;
85  // else if (max_val < 32768 && min_val >= -32768)
86  // st = LS_SHORT;
87  // else if (max_val <= 2147483647L && min_val >= -2147483647L)
88  // st = LS_INT;
89 
90  return st;
91 }
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:38