Mercurial > octave
annotate libinterp/corefcn/ls-utils.cc @ 30006:75dff8f2de2e
move some load-save utilities to octave namespace
* ls-ascii-helper.h, ls-ascii-helper.cc (skip_until_newline,
read_until_newline, skip_preceeding_newline): Move inside octave
namespace. Change all uses as needed. Provide deprecated inline
wrapper functions to preserve old names.
* ls-utils.h, ls-utils.cc (get_save_type): Move inside octave
namespace. Change all uses as needed. Provide deprecated inline
wrapper functions to preserve old names.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 18 Aug 2021 15:47:29 -0400 |
parents | 0a5b15007766 |
children | 796f54d4ddbf |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
29358
0a5b15007766
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
3 // Copyright (C) 2003-2021 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
4634 | 25 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
27 # include "config.h" |
4634 | 28 #endif |
29 | |
30 #include "data-conv.h" | |
31 | |
32 #include "ls-utils.h" | |
33 | |
30006
75dff8f2de2e
move some load-save utilities to octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
34 OCTAVE_NAMESPACE_BEGIN |
75dff8f2de2e
move some load-save utilities to octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
35 |
4634 | 36 // MAX_VAL and MIN_VAL are assumed to have integral values even though |
37 // they are stored in doubles. | |
38 | |
39 save_type | |
4661 | 40 get_save_type (double /* max_val */, double /* min_val */) |
4634 | 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 } | |
11468
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
10160
diff
changeset
|
66 |
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
10160
diff
changeset
|
67 save_type |
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
10160
diff
changeset
|
68 get_save_type (float /* max_val */, float /* min_val */) |
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
10160
diff
changeset
|
69 { |
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
10160
diff
changeset
|
70 save_type st = LS_FLOAT; |
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
10160
diff
changeset
|
71 |
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
10160
diff
changeset
|
72 // Matlab doesn't seem to load the UINT32 type correctly, so let's |
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
10160
diff
changeset
|
73 // avoid it (and the other unsigned types, even though they may not |
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
10160
diff
changeset
|
74 // have the same problem. And apparently, there are problems with |
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
10160
diff
changeset
|
75 // other smaller types as well. If we avoid them all, then maybe we |
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
10160
diff
changeset
|
76 // will avoid problems. Unfortunately, we won't be able to save |
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
10160
diff
changeset
|
77 // space... |
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
10160
diff
changeset
|
78 |
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
10160
diff
changeset
|
79 // if (max_val < 256 && min_val > -1) |
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
10160
diff
changeset
|
80 // st = LS_U_CHAR; |
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
10160
diff
changeset
|
81 // else if (max_val < 65536 && min_val > -1) |
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
10160
diff
changeset
|
82 // st = LS_U_SHORT; |
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
10160
diff
changeset
|
83 // else if (max_val < 4294967295UL && min_val > -1) |
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
10160
diff
changeset
|
84 // st = LS_U_INT; |
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
10160
diff
changeset
|
85 // else if (max_val < 128 && min_val >= -128) |
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
10160
diff
changeset
|
86 // st = LS_CHAR; |
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
10160
diff
changeset
|
87 // else if (max_val < 32768 && min_val >= -32768) |
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
10160
diff
changeset
|
88 // st = LS_SHORT; |
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
10160
diff
changeset
|
89 // else if (max_val <= 2147483647L && min_val >= -2147483647L) |
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
10160
diff
changeset
|
90 // st = LS_INT; |
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
10160
diff
changeset
|
91 |
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
10160
diff
changeset
|
92 return st; |
e1edf0ba3bcb
Yet another single precision matlab file fix
David Bateman <dbateman@free.fr>
parents:
10160
diff
changeset
|
93 } |
30006
75dff8f2de2e
move some load-save utilities to octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
94 |
75dff8f2de2e
move some load-save utilities to octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
95 OCTAVE_NAMESPACE_END |
75dff8f2de2e
move some load-save utilities to octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
96 |