Mercurial > hg > octave-jordi
annotate libinterp/corefcn/str2double.cc @ 17516:21656a949661
Add hook function to handle missing Octave components
* __gripe_missing_component__.m: New internal function to handle errors due
to missing Octave components.
* scripts/help/module.mk (help_FCN_FILES): Add __gripe_missing_component__.m.
* variables.cc (Vmissing_component_hook): New internal variable.
* doc.m, mkoctfile.m, configure_make.m: Call __gripe_missing_component__
if required files are not found.
* NEWS: Mention missing_component_hook.
author | Mike Miller <mtmiller@ieee.org> |
---|---|
date | Sun, 29 Sep 2013 16:06:41 -0400 |
parents | f47cfca56eb9 |
children | d63878346099 |
rev | line source |
---|---|
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
1 /* |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
2 |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
14091
diff
changeset
|
3 Copyright (C) 2010-2012 Jaroslav Hajek |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
4 Copyright (C) 2010 VZLU Prague |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
5 |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
6 This file is part of Octave. |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
7 |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
8 Octave is free software; you can redistribute it and/or modify it |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
9 under the terms of the GNU General Public License as published by the |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
10 Free Software Foundation; either version 3 of the License, or (at your |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
11 option) any later version. |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
12 |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
16 for more details. |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
17 |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
18 You should have received a copy of the GNU General Public License |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
19 along with Octave; see the file COPYING. If not, see |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
20 <http://www.gnu.org/licenses/>. |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
21 |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
22 */ |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
23 |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
24 #ifdef HAVE_CONFIG_H |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
25 #include <config.h> |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
26 #endif |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
27 |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
28 #include <string> |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
29 #include <cctype> |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
30 #include <sstream> |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
31 #include <algorithm> |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
32 |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
33 #include "lo-ieee.h" |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
34 |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
35 #include "Cell.h" |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
36 #include "ov.h" |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
37 #include "defun.h" |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
38 #include "gripes.h" |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
39 #include "utils.h" |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
40 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
41 static inline bool |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
42 is_imag_unit (int c) |
10357
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
43 { return c == 'i' || c == 'j'; } |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
44 |
17379
b91f29f021a3
str2double.cc: miscellaneous simplifications to code.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
45 static double |
b91f29f021a3
str2double.cc: miscellaneous simplifications to code.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
46 single_num (std::istringstream& is) |
10357
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
47 { |
17379
b91f29f021a3
str2double.cc: miscellaneous simplifications to code.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
48 double num; |
b91f29f021a3
str2double.cc: miscellaneous simplifications to code.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
49 |
10357
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
50 char c = is.peek (); |
14077
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
51 |
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
52 // Skip spaces. |
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
53 while (isspace (c)) |
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
54 { |
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
55 is.get (); |
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
56 c = is.peek (); |
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
57 } |
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
58 |
14702
a08f6e17336e
str2double.cc: Case-insensitive detection of 'Inf' (Bug #36536).
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
59 if (std::toupper (c) == 'I') |
10357
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
60 { |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
61 // It's infinity. |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
62 is.get (); |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
63 char c1 = is.get (), c2 = is.get (); |
14702
a08f6e17336e
str2double.cc: Case-insensitive detection of 'Inf' (Bug #36536).
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
64 if (std::tolower (c1) == 'n' && std::tolower (c2) == 'f') |
10357
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
65 { |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
66 num = octave_Inf; |
14702
a08f6e17336e
str2double.cc: Case-insensitive detection of 'Inf' (Bug #36536).
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
67 is.peek (); // May set EOF bit. |
10357
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
68 } |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
69 else |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
70 is.setstate (std::ios::failbit); // indicate that read has failed. |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
71 } |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
72 else if (c == 'N') |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
73 { |
11414
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
74 // It's NA or NaN |
10357
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
75 is.get (); |
11414
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
76 char c1 = is.get (); |
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
77 if (c1 == 'A') |
10357
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
78 { |
11414
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
79 num = octave_NA; |
14091
c3ea07298af4
str2double: correctly handle things like ["1"; "2 3"; "4i"]
John W. Eaton <jwe@octave.org>
parents:
14077
diff
changeset
|
80 is.peek (); // May set EOF bit. |
10357
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
81 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
82 else |
11414
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
83 { |
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
84 char c2 = is.get (); |
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
85 if (c1 == 'a' && c2 == 'N') |
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
86 { |
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
87 num = octave_NaN; |
14091
c3ea07298af4
str2double: correctly handle things like ["1"; "2 3"; "4i"]
John W. Eaton <jwe@octave.org>
parents:
14077
diff
changeset
|
88 is.peek (); // May set EOF bit. |
11414
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
89 } |
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
90 else |
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
91 is.setstate (std::ios::failbit); // indicate that read has failed. |
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
92 } |
10357
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
93 } |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
94 else |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
95 is >> num; |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
96 |
17379
b91f29f021a3
str2double.cc: miscellaneous simplifications to code.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
97 return num; |
10357
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
98 } |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
99 |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
100 static std::istringstream& |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
101 extract_num (std::istringstream& is, double& num, bool& imag, bool& have_sign) |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
102 { |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
103 have_sign = imag = false; |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
104 |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
105 char c = is.peek (); |
14077
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
106 |
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
107 // Skip leading spaces. |
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
108 while (isspace (c)) |
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
109 { |
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
110 is.get (); |
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
111 c = is.peek (); |
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
112 } |
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
113 |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
114 bool negative = false; |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
115 |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
116 // Accept leading sign. |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
117 if (c == '+' || c == '-') |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
118 { |
17379
b91f29f021a3
str2double.cc: miscellaneous simplifications to code.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
119 have_sign = true; |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
120 negative = c == '-'; |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
121 is.get (); |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
122 c = is.peek (); |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
123 } |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
124 |
14077
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
125 // Skip spaces after sign. |
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
126 while (isspace (c)) |
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
127 { |
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
128 is.get (); |
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
129 c = is.peek (); |
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
130 } |
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
131 |
14702
a08f6e17336e
str2double.cc: Case-insensitive detection of 'Inf' (Bug #36536).
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
132 // Imaginary number (i*num or just i), or maybe 'inf'. |
a08f6e17336e
str2double.cc: Case-insensitive detection of 'Inf' (Bug #36536).
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
133 if (c == 'i') |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
134 { |
14702
a08f6e17336e
str2double.cc: Case-insensitive detection of 'Inf' (Bug #36536).
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
135 // possible infinity. |
14091
c3ea07298af4
str2double: correctly handle things like ["1"; "2 3"; "4i"]
John W. Eaton <jwe@octave.org>
parents:
14077
diff
changeset
|
136 is.get (); |
c3ea07298af4
str2double: correctly handle things like ["1"; "2 3"; "4i"]
John W. Eaton <jwe@octave.org>
parents:
14077
diff
changeset
|
137 c = is.peek (); |
14077
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
138 |
14702
a08f6e17336e
str2double.cc: Case-insensitive detection of 'Inf' (Bug #36536).
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
139 if (is.eof ()) |
a08f6e17336e
str2double.cc: Case-insensitive detection of 'Inf' (Bug #36536).
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
140 { |
a08f6e17336e
str2double.cc: Case-insensitive detection of 'Inf' (Bug #36536).
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
141 // just 'i' and string is finished. Return immediately. |
a08f6e17336e
str2double.cc: Case-insensitive detection of 'Inf' (Bug #36536).
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
142 imag = true; |
17379
b91f29f021a3
str2double.cc: miscellaneous simplifications to code.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
143 num = negative ? -1.0 : 1.0; |
14702
a08f6e17336e
str2double.cc: Case-insensitive detection of 'Inf' (Bug #36536).
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
144 return is; |
a08f6e17336e
str2double.cc: Case-insensitive detection of 'Inf' (Bug #36536).
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
145 } |
a08f6e17336e
str2double.cc: Case-insensitive detection of 'Inf' (Bug #36536).
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
146 else |
17379
b91f29f021a3
str2double.cc: miscellaneous simplifications to code.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
147 { |
14702
a08f6e17336e
str2double.cc: Case-insensitive detection of 'Inf' (Bug #36536).
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
148 if (std::tolower (c) != 'n') |
a08f6e17336e
str2double.cc: Case-insensitive detection of 'Inf' (Bug #36536).
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
149 imag = true; |
a08f6e17336e
str2double.cc: Case-insensitive detection of 'Inf' (Bug #36536).
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
150 is.unget (); |
a08f6e17336e
str2double.cc: Case-insensitive detection of 'Inf' (Bug #36536).
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
151 } |
a08f6e17336e
str2double.cc: Case-insensitive detection of 'Inf' (Bug #36536).
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
152 } |
a08f6e17336e
str2double.cc: Case-insensitive detection of 'Inf' (Bug #36536).
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
153 else if (c == 'j') |
a08f6e17336e
str2double.cc: Case-insensitive detection of 'Inf' (Bug #36536).
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
154 imag = true; |
17379
b91f29f021a3
str2double.cc: miscellaneous simplifications to code.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
155 |
14702
a08f6e17336e
str2double.cc: Case-insensitive detection of 'Inf' (Bug #36536).
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
156 // It's i*num or just i |
a08f6e17336e
str2double.cc: Case-insensitive detection of 'Inf' (Bug #36536).
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
157 if (imag) |
a08f6e17336e
str2double.cc: Case-insensitive detection of 'Inf' (Bug #36536).
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
158 { |
a08f6e17336e
str2double.cc: Case-insensitive detection of 'Inf' (Bug #36536).
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
159 is.get (); |
a08f6e17336e
str2double.cc: Case-insensitive detection of 'Inf' (Bug #36536).
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
160 c = is.peek (); |
14077
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
161 // Skip spaces after imaginary unit. |
14091
c3ea07298af4
str2double: correctly handle things like ["1"; "2 3"; "4i"]
John W. Eaton <jwe@octave.org>
parents:
14077
diff
changeset
|
162 while (isspace (c)) |
14077
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
163 { |
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
164 is.get (); |
14091
c3ea07298af4
str2double: correctly handle things like ["1"; "2 3"; "4i"]
John W. Eaton <jwe@octave.org>
parents:
14077
diff
changeset
|
165 c = is.peek (); |
14077
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
166 } |
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
167 |
14091
c3ea07298af4
str2double: correctly handle things like ["1"; "2 3"; "4i"]
John W. Eaton <jwe@octave.org>
parents:
14077
diff
changeset
|
168 if (c == '*') |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
169 { |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
170 // Multiplier follows, we extract it as a number. |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
171 is.get (); |
17379
b91f29f021a3
str2double.cc: miscellaneous simplifications to code.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
172 num = single_num (is); |
14091
c3ea07298af4
str2double: correctly handle things like ["1"; "2 3"; "4i"]
John W. Eaton <jwe@octave.org>
parents:
14077
diff
changeset
|
173 if (is.good ()) |
c3ea07298af4
str2double: correctly handle things like ["1"; "2 3"; "4i"]
John W. Eaton <jwe@octave.org>
parents:
14077
diff
changeset
|
174 c = is.peek (); |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
175 } |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
176 else |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
177 num = 1.0; |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
178 } |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
179 else |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
180 { |
11414
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
181 // It's num, num*i, or numi. |
17379
b91f29f021a3
str2double.cc: miscellaneous simplifications to code.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
182 num = single_num (is); |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
183 if (is.good ()) |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
184 { |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
185 c = is.peek (); |
14077
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
186 |
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
187 // Skip spaces after number. |
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
188 while (isspace (c)) |
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
189 { |
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
190 is.get (); |
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
191 c = is.peek (); |
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
192 } |
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
193 |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
194 if (c == '*') |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
195 { |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
196 is.get (); |
14077
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
197 c = is.peek (); |
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
198 |
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
199 // Skip spaces after operator. |
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
200 while (isspace (c)) |
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
201 { |
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
202 is.get (); |
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
203 c = is.peek (); |
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
204 } |
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
205 |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
206 if (is_imag_unit (c)) |
11414
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
207 { |
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
208 imag = true; |
14077
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
209 is.get (); |
14091
c3ea07298af4
str2double: correctly handle things like ["1"; "2 3"; "4i"]
John W. Eaton <jwe@octave.org>
parents:
14077
diff
changeset
|
210 c = is.peek (); |
11414
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
211 } |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
212 else |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
213 is.setstate (std::ios::failbit); // indicate that read has failed. |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
214 } |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
215 else if (is_imag_unit (c)) |
11414
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
216 { |
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
217 imag = true; |
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
218 is.get (); |
14091
c3ea07298af4
str2double: correctly handle things like ["1"; "2 3"; "4i"]
John W. Eaton <jwe@octave.org>
parents:
14077
diff
changeset
|
219 c = is.peek (); |
11414
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
220 } |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
221 } |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
222 } |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
223 |
14091
c3ea07298af4
str2double: correctly handle things like ["1"; "2 3"; "4i"]
John W. Eaton <jwe@octave.org>
parents:
14077
diff
changeset
|
224 if (is.good ()) |
c3ea07298af4
str2double: correctly handle things like ["1"; "2 3"; "4i"]
John W. Eaton <jwe@octave.org>
parents:
14077
diff
changeset
|
225 { |
c3ea07298af4
str2double: correctly handle things like ["1"; "2 3"; "4i"]
John W. Eaton <jwe@octave.org>
parents:
14077
diff
changeset
|
226 // Skip trailing spaces. |
c3ea07298af4
str2double: correctly handle things like ["1"; "2 3"; "4i"]
John W. Eaton <jwe@octave.org>
parents:
14077
diff
changeset
|
227 while (isspace (c)) |
c3ea07298af4
str2double: correctly handle things like ["1"; "2 3"; "4i"]
John W. Eaton <jwe@octave.org>
parents:
14077
diff
changeset
|
228 { |
c3ea07298af4
str2double: correctly handle things like ["1"; "2 3"; "4i"]
John W. Eaton <jwe@octave.org>
parents:
14077
diff
changeset
|
229 is.get (); |
c3ea07298af4
str2double: correctly handle things like ["1"; "2 3"; "4i"]
John W. Eaton <jwe@octave.org>
parents:
14077
diff
changeset
|
230 c = is.peek (); |
c3ea07298af4
str2double: correctly handle things like ["1"; "2 3"; "4i"]
John W. Eaton <jwe@octave.org>
parents:
14077
diff
changeset
|
231 } |
c3ea07298af4
str2double: correctly handle things like ["1"; "2 3"; "4i"]
John W. Eaton <jwe@octave.org>
parents:
14077
diff
changeset
|
232 } |
c3ea07298af4
str2double: correctly handle things like ["1"; "2 3"; "4i"]
John W. Eaton <jwe@octave.org>
parents:
14077
diff
changeset
|
233 |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
234 if (negative) |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
235 num = -num; |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
236 |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
237 return is; |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
238 } |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
239 |
10379
f578e6468d0c
use C++-0x code in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10378
diff
changeset
|
240 static inline void |
f578e6468d0c
use C++-0x code in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10378
diff
changeset
|
241 set_component (Complex& c, double num, bool imag) |
f578e6468d0c
use C++-0x code in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10378
diff
changeset
|
242 { |
10380
60acc47c203f
configure checks for complex element setter/reference accessor methods
John W. Eaton <jwe@octave.org>
parents:
10379
diff
changeset
|
243 #if defined (HAVE_CXX_COMPLEX_SETTERS) |
10379
f578e6468d0c
use C++-0x code in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10378
diff
changeset
|
244 if (imag) |
10380
60acc47c203f
configure checks for complex element setter/reference accessor methods
John W. Eaton <jwe@octave.org>
parents:
10379
diff
changeset
|
245 c.imag (num); |
10379
f578e6468d0c
use C++-0x code in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10378
diff
changeset
|
246 else |
10380
60acc47c203f
configure checks for complex element setter/reference accessor methods
John W. Eaton <jwe@octave.org>
parents:
10379
diff
changeset
|
247 c.real (num); |
60acc47c203f
configure checks for complex element setter/reference accessor methods
John W. Eaton <jwe@octave.org>
parents:
10379
diff
changeset
|
248 #elif defined (HAVE_CXX_COMPLEX_REFERENCE_ACCESSORS) |
60acc47c203f
configure checks for complex element setter/reference accessor methods
John W. Eaton <jwe@octave.org>
parents:
10379
diff
changeset
|
249 if (imag) |
60acc47c203f
configure checks for complex element setter/reference accessor methods
John W. Eaton <jwe@octave.org>
parents:
10379
diff
changeset
|
250 c.imag () = num; |
60acc47c203f
configure checks for complex element setter/reference accessor methods
John W. Eaton <jwe@octave.org>
parents:
10379
diff
changeset
|
251 else |
60acc47c203f
configure checks for complex element setter/reference accessor methods
John W. Eaton <jwe@octave.org>
parents:
10379
diff
changeset
|
252 c.real () = num; |
10379
f578e6468d0c
use C++-0x code in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10378
diff
changeset
|
253 #else |
f578e6468d0c
use C++-0x code in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10378
diff
changeset
|
254 if (imag) |
f578e6468d0c
use C++-0x code in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10378
diff
changeset
|
255 c = Complex (c.real (), num); |
f578e6468d0c
use C++-0x code in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10378
diff
changeset
|
256 else |
f578e6468d0c
use C++-0x code in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10378
diff
changeset
|
257 c = Complex (num, c.imag ()); |
f578e6468d0c
use C++-0x code in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10378
diff
changeset
|
258 #endif |
f578e6468d0c
use C++-0x code in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10378
diff
changeset
|
259 } |
f578e6468d0c
use C++-0x code in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10378
diff
changeset
|
260 |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
261 static Complex |
10381 | 262 str2double1 (const std::string& str_arg) |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
263 { |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
264 Complex val (0.0, 0.0); |
10381 | 265 |
266 std::string str = str_arg; | |
267 | |
17379
b91f29f021a3
str2double.cc: miscellaneous simplifications to code.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
268 // FIXME: removing all commas doesn't allow actual parsing. |
b91f29f021a3
str2double.cc: miscellaneous simplifications to code.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
269 // Example: "1,23.45" is wrong, but passes Octave. |
b91f29f021a3
str2double.cc: miscellaneous simplifications to code.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
270 str.erase (std::remove (str.begin (), str.end(), ','), str.end ()); |
14077
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
271 std::istringstream is (str); |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
272 |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
273 double num; |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
274 bool i1, i2, s1, s2; |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
275 |
10357
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
276 if (is.eof ()) |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
277 val = octave_NaN; |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
278 else if (! extract_num (is, num, i1, s1)) |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
279 val = octave_NaN; |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
280 else |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
281 { |
10380
60acc47c203f
configure checks for complex element setter/reference accessor methods
John W. Eaton <jwe@octave.org>
parents:
10379
diff
changeset
|
282 set_component (val, num, i1); |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
283 |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
284 if (! is.eof ()) |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
285 { |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
286 if (! extract_num (is, num, i2, s2) || i1 == i2 || ! s2) |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
287 val = octave_NaN; |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
288 else |
10380
60acc47c203f
configure checks for complex element setter/reference accessor methods
John W. Eaton <jwe@octave.org>
parents:
10379
diff
changeset
|
289 set_component (val, num, i2); |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
290 } |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
291 } |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
292 |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
293 return val; |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
294 } |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
295 |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
296 DEFUN (str2double, args, , |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
297 "-*- texinfo -*-\n\ |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
298 @deftypefn {Built-in Function} {} str2double (@var{s})\n\ |
11414
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
299 Convert a string to a real or complex number.\n\ |
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
300 \n\ |
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
301 The string must be in one of the following formats where\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
302 a and b are real numbers and the complex unit is @qcode{'i'} or @qcode{'j'}:\n\ |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
303 \n\ |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
304 @itemize\n\ |
10840 | 305 @item a + bi\n\ |
306 \n\ | |
307 @item a + b*i\n\ | |
308 \n\ | |
309 @item a + i*b\n\ | |
310 \n\ | |
311 @item bi + a\n\ | |
312 \n\ | |
313 @item b*i + a\n\ | |
314 \n\ | |
315 @item i*b + a\n\ | |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
316 @end itemize\n\ |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
317 \n\ |
11591
1d13679b587e
Use @nospell macro on certain words in docstrings.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
318 If present, a and/or b are of the form @nospell{[+-]d[,.]d[[eE][+-]d]} where\n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
319 the brackets indicate optional arguments and @qcode{'d'} indicates zero or\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
320 more digits. The special input values @code{Inf}, @code{NaN}, and @code{NA}\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
15195
diff
changeset
|
321 are also accepted.\n\ |
11414
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
322 \n\ |
17410
f47cfca56eb9
doc: Rephrase a few sentences in str2double docstring.
Rik <rik@octave.org>
parents:
17409
diff
changeset
|
323 @var{s} may be a character string, character matrix, or cell array.\n\ |
17409
3baf8e7ec3dd
str2double.cc: make output more consistent and ML-compatible, update help text, add tests (bug #39838)
Ben Kurtz <hidden email>
parents:
17379
diff
changeset
|
324 For character arrays the conversion is repeated for every row, and\n\ |
17410
f47cfca56eb9
doc: Rephrase a few sentences in str2double docstring.
Rik <rik@octave.org>
parents:
17409
diff
changeset
|
325 a double or complex array is returned. Empty rows in @var{s} are deleted\n\ |
f47cfca56eb9
doc: Rephrase a few sentences in str2double docstring.
Rik <rik@octave.org>
parents:
17409
diff
changeset
|
326 and not returned in the numeric array. For cell arrays each character\n\ |
f47cfca56eb9
doc: Rephrase a few sentences in str2double docstring.
Rik <rik@octave.org>
parents:
17409
diff
changeset
|
327 string element is processed and a double or complex array of the same\n\ |
f47cfca56eb9
doc: Rephrase a few sentences in str2double docstring.
Rik <rik@octave.org>
parents:
17409
diff
changeset
|
328 dimensions as @var{s} is returned.\n\ |
11414
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
329 \n\ |
17409
3baf8e7ec3dd
str2double.cc: make output more consistent and ML-compatible, update help text, add tests (bug #39838)
Ben Kurtz <hidden email>
parents:
17379
diff
changeset
|
330 For unconvertible scalar or character string input @code{str2double} returns\n\ |
17410
f47cfca56eb9
doc: Rephrase a few sentences in str2double docstring.
Rik <rik@octave.org>
parents:
17409
diff
changeset
|
331 a NaN@. Similarly, for character array input @code{str2double} returns a\n\ |
f47cfca56eb9
doc: Rephrase a few sentences in str2double docstring.
Rik <rik@octave.org>
parents:
17409
diff
changeset
|
332 NaN for any row of @var{s} that could not be converted. For a cell array,\n\ |
17409
3baf8e7ec3dd
str2double.cc: make output more consistent and ML-compatible, update help text, add tests (bug #39838)
Ben Kurtz <hidden email>
parents:
17379
diff
changeset
|
333 @code{str2double} returns a NaN for any element of @var{s} for which\n\ |
17410
f47cfca56eb9
doc: Rephrase a few sentences in str2double docstring.
Rik <rik@octave.org>
parents:
17409
diff
changeset
|
334 conversion fails. Note that numeric elements in a mixed string/numeric\n\ |
f47cfca56eb9
doc: Rephrase a few sentences in str2double docstring.
Rik <rik@octave.org>
parents:
17409
diff
changeset
|
335 cell array are not strings and the conversion will fail for these elements\n\ |
f47cfca56eb9
doc: Rephrase a few sentences in str2double docstring.
Rik <rik@octave.org>
parents:
17409
diff
changeset
|
336 and return NaN.\n\ |
12703
d326be468b13
doc: str2double() inputs which cannot be parsed return NaN.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
337 \n\ |
d326be468b13
doc: str2double() inputs which cannot be parsed return NaN.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
338 @code{str2double} can replace @code{str2num}, and it avoids the security\n\ |
d326be468b13
doc: str2double() inputs which cannot be parsed return NaN.
Rik <octave@nomad.inbox5.com>
parents:
11591
diff
changeset
|
339 risk of using @code{eval} on unknown data.\n\ |
11414
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
340 @seealso{str2num}\n\ |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
341 @end deftypefn") |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
342 { |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
343 octave_value retval; |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
344 |
12735
76e2c55906de
str2double.cc: Return NaN for invalid inputs rather than printing error.
Rik <octave@nomad.inbox5.com>
parents:
12703
diff
changeset
|
345 if (args.length () != 1) |
76e2c55906de
str2double.cc: Return NaN for invalid inputs rather than printing error.
Rik <octave@nomad.inbox5.com>
parents:
12703
diff
changeset
|
346 print_usage (); |
76e2c55906de
str2double.cc: Return NaN for invalid inputs rather than printing error.
Rik <octave@nomad.inbox5.com>
parents:
12703
diff
changeset
|
347 else if (args(0).is_string ()) |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
348 { |
17409
3baf8e7ec3dd
str2double.cc: make output more consistent and ML-compatible, update help text, add tests (bug #39838)
Ben Kurtz <hidden email>
parents:
17379
diff
changeset
|
349 if (args(0).rows () == 0 || args(0).columns () == 0) |
3baf8e7ec3dd
str2double.cc: make output more consistent and ML-compatible, update help text, add tests (bug #39838)
Ben Kurtz <hidden email>
parents:
17379
diff
changeset
|
350 { |
3baf8e7ec3dd
str2double.cc: make output more consistent and ML-compatible, update help text, add tests (bug #39838)
Ben Kurtz <hidden email>
parents:
17379
diff
changeset
|
351 retval = Matrix (1, 1, octave_NaN); |
3baf8e7ec3dd
str2double.cc: make output more consistent and ML-compatible, update help text, add tests (bug #39838)
Ben Kurtz <hidden email>
parents:
17379
diff
changeset
|
352 } |
3baf8e7ec3dd
str2double.cc: make output more consistent and ML-compatible, update help text, add tests (bug #39838)
Ben Kurtz <hidden email>
parents:
17379
diff
changeset
|
353 else if (args(0).rows () == 1 && args(0).ndims () == 2) |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
354 { |
12735
76e2c55906de
str2double.cc: Return NaN for invalid inputs rather than printing error.
Rik <octave@nomad.inbox5.com>
parents:
12703
diff
changeset
|
355 retval = str2double1 (args(0).string_value ()); |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
356 } |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
357 else |
12735
76e2c55906de
str2double.cc: Return NaN for invalid inputs rather than printing error.
Rik <octave@nomad.inbox5.com>
parents:
12703
diff
changeset
|
358 { |
76e2c55906de
str2double.cc: Return NaN for invalid inputs rather than printing error.
Rik <octave@nomad.inbox5.com>
parents:
12703
diff
changeset
|
359 const string_vector sv = args(0).all_strings (); |
76e2c55906de
str2double.cc: Return NaN for invalid inputs rather than printing error.
Rik <octave@nomad.inbox5.com>
parents:
12703
diff
changeset
|
360 if (! error_state) |
76e2c55906de
str2double.cc: Return NaN for invalid inputs rather than printing error.
Rik <octave@nomad.inbox5.com>
parents:
12703
diff
changeset
|
361 retval = sv.map<Complex> (str2double1); |
76e2c55906de
str2double.cc: Return NaN for invalid inputs rather than printing error.
Rik <octave@nomad.inbox5.com>
parents:
12703
diff
changeset
|
362 } |
76e2c55906de
str2double.cc: Return NaN for invalid inputs rather than printing error.
Rik <octave@nomad.inbox5.com>
parents:
12703
diff
changeset
|
363 } |
76e2c55906de
str2double.cc: Return NaN for invalid inputs rather than printing error.
Rik <octave@nomad.inbox5.com>
parents:
12703
diff
changeset
|
364 else if (args(0).is_cell ()) |
76e2c55906de
str2double.cc: Return NaN for invalid inputs rather than printing error.
Rik <octave@nomad.inbox5.com>
parents:
12703
diff
changeset
|
365 { |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12735
diff
changeset
|
366 const Cell cell = args(0).cell_value (); |
12735
76e2c55906de
str2double.cc: Return NaN for invalid inputs rather than printing error.
Rik <octave@nomad.inbox5.com>
parents:
12703
diff
changeset
|
367 |
76e2c55906de
str2double.cc: Return NaN for invalid inputs rather than printing error.
Rik <octave@nomad.inbox5.com>
parents:
12703
diff
changeset
|
368 if (! error_state) |
76e2c55906de
str2double.cc: Return NaN for invalid inputs rather than printing error.
Rik <octave@nomad.inbox5.com>
parents:
12703
diff
changeset
|
369 { |
76e2c55906de
str2double.cc: Return NaN for invalid inputs rather than printing error.
Rik <octave@nomad.inbox5.com>
parents:
12703
diff
changeset
|
370 ComplexNDArray output (cell.dims (), octave_NaN); |
76e2c55906de
str2double.cc: Return NaN for invalid inputs rather than printing error.
Rik <octave@nomad.inbox5.com>
parents:
12703
diff
changeset
|
371 for (octave_idx_type i = 0; i < cell.numel (); i++) |
76e2c55906de
str2double.cc: Return NaN for invalid inputs rather than printing error.
Rik <octave@nomad.inbox5.com>
parents:
12703
diff
changeset
|
372 { |
76e2c55906de
str2double.cc: Return NaN for invalid inputs rather than printing error.
Rik <octave@nomad.inbox5.com>
parents:
12703
diff
changeset
|
373 if (cell(i).is_string ()) |
76e2c55906de
str2double.cc: Return NaN for invalid inputs rather than printing error.
Rik <octave@nomad.inbox5.com>
parents:
12703
diff
changeset
|
374 output(i) = str2double1 (cell(i).string_value ()); |
76e2c55906de
str2double.cc: Return NaN for invalid inputs rather than printing error.
Rik <octave@nomad.inbox5.com>
parents:
12703
diff
changeset
|
375 } |
76e2c55906de
str2double.cc: Return NaN for invalid inputs rather than printing error.
Rik <octave@nomad.inbox5.com>
parents:
12703
diff
changeset
|
376 retval = output; |
76e2c55906de
str2double.cc: Return NaN for invalid inputs rather than printing error.
Rik <octave@nomad.inbox5.com>
parents:
12703
diff
changeset
|
377 } |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
378 } |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
379 else |
17409
3baf8e7ec3dd
str2double.cc: make output more consistent and ML-compatible, update help text, add tests (bug #39838)
Ben Kurtz <hidden email>
parents:
17379
diff
changeset
|
380 retval = Matrix (1, 1, octave_NaN); |
13141
e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
12735
diff
changeset
|
381 |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
382 |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
383 return retval; |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
384 } |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
385 |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
386 /* |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
387 %!assert (str2double ("1"), 1) |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
388 %!assert (str2double ("-.1e-5"), -1e-6) |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
389 %!assert (str2double (char ("1", "2 3", "4i")), [1; NaN; 4i]) |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
390 %!assert (str2double ("1,222.5"), 1222.5) |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
391 %!assert (str2double ("i"), i) |
11414
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
392 %!assert (str2double ("2j"), 2i) |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
393 %!assert (str2double ("2 + j"), 2+j) |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
394 %!assert (str2double ("i*2 + 3"), 3+2i) |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
395 %!assert (str2double (".5*i + 3.5"), 3.5+0.5i) |
11414
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
396 %!assert (str2double ("1e-3 + i*.25"), 1e-3 + 0.25i) |
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
397 %!assert (str2double (["2 + j";"1.25e-3";"-05"]), [2+i; 1.25e-3; -5]) |
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
398 %!assert (str2double ({"2 + j","1.25e-3","-05"}), [2+i, 1.25e-3, -5]) |
12735
76e2c55906de
str2double.cc: Return NaN for invalid inputs rather than printing error.
Rik <octave@nomad.inbox5.com>
parents:
12703
diff
changeset
|
399 %!assert (str2double (1), NaN) |
14077
b6eeeb67fa3f
str2double: return NaN for things like "1 2 3 4" (bug #34713).
John W. Eaton <jwe@octave.org>
parents:
13141
diff
changeset
|
400 %!assert (str2double ("1 2 3 4"), NaN) |
11414
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
401 %!assert (str2double ("Hello World"), NaN) |
10357
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
402 %!assert (str2double ("NaN"), NaN) |
11414
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
403 %!assert (str2double ("NA"), NA) |
10357
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
404 %!assert (str2double ("Inf"), Inf) |
14702
a08f6e17336e
str2double.cc: Case-insensitive detection of 'Inf' (Bug #36536).
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
405 %!assert (str2double ("iNF"), Inf) |
10357
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
406 %!assert (str2double ("-Inf"), -Inf) |
11414
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
407 %!assert (str2double ("Inf*i"), complex (0, Inf)) |
14702
a08f6e17336e
str2double.cc: Case-insensitive detection of 'Inf' (Bug #36536).
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
408 %!assert (str2double ("iNF*i"), complex (0, Inf)) |
10357
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
409 %!assert (str2double ("NaN + Inf*i"), complex (NaN, Inf)) |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
410 %!assert (str2double ("Inf - Inf*i"), complex (Inf, -Inf)) |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
411 %!assert (str2double ("-i*NaN - Inf"), complex (-Inf, -NaN)) |
12735
76e2c55906de
str2double.cc: Return NaN for invalid inputs rather than printing error.
Rik <octave@nomad.inbox5.com>
parents:
12703
diff
changeset
|
412 %!assert (str2double ({"abc", "4i"}), [NaN + 0i, 4i]) |
76e2c55906de
str2double.cc: Return NaN for invalid inputs rather than printing error.
Rik <octave@nomad.inbox5.com>
parents:
12703
diff
changeset
|
413 %!assert (str2double ({2, "4i"}), [NaN + 0i, 4i]) |
17409
3baf8e7ec3dd
str2double.cc: make output more consistent and ML-compatible, update help text, add tests (bug #39838)
Ben Kurtz <hidden email>
parents:
17379
diff
changeset
|
414 %!assert (str2double (zeros (3,1,2)), NaN) |
3baf8e7ec3dd
str2double.cc: make output more consistent and ML-compatible, update help text, add tests (bug #39838)
Ben Kurtz <hidden email>
parents:
17379
diff
changeset
|
415 %!assert (str2double (''), NaN) |
3baf8e7ec3dd
str2double.cc: make output more consistent and ML-compatible, update help text, add tests (bug #39838)
Ben Kurtz <hidden email>
parents:
17379
diff
changeset
|
416 %!assert (str2double ([]), NaN) |
3baf8e7ec3dd
str2double.cc: make output more consistent and ML-compatible, update help text, add tests (bug #39838)
Ben Kurtz <hidden email>
parents:
17379
diff
changeset
|
417 %!assert (str2double (char(zeros(3,0))), NaN) |
3baf8e7ec3dd
str2double.cc: make output more consistent and ML-compatible, update help text, add tests (bug #39838)
Ben Kurtz <hidden email>
parents:
17379
diff
changeset
|
418 */ |