Mercurial > octave-nkf
annotate src/DLD-FUNCTIONS/str2double.cc @ 11586:12df7854fa7c
strip trailing whitespace from source files
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 20 Jan 2011 17:24:59 -0500 |
parents | 01f703952eff |
children | 1d13679b587e |
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 |
11523 | 3 Copyright (C) 2010-2011 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" |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
37 #include "defun-dld.h" |
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 |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
45 static std::istringstream& |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
46 single_num (std::istringstream& is, double& num) |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
47 { |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
48 char c = is.peek (); |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
49 if (c == 'I') |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
50 { |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
51 // It's infinity. |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
52 is.get (); |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
53 char c1 = is.get (), c2 = is.get (); |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
54 if (c1 == 'n' && c2 == 'f') |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
55 { |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
56 num = octave_Inf; |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
57 is.peek (); // Sets eof bit. |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
58 } |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
59 else |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
60 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
|
61 } |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
62 else if (c == 'N') |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
63 { |
11414
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
64 // It's NA or NaN |
10357
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
65 is.get (); |
11414
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
66 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
|
67 if (c1 == 'A') |
10357
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
68 { |
11414
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
69 num = octave_NA; |
10357
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
70 is.peek (); // Sets eof bit. |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
71 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
72 else |
11414
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
73 { |
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
74 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
|
75 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
|
76 { |
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
77 num = octave_NaN; |
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
78 is.peek (); // Sets eof bit. |
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
79 } |
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
80 else |
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
81 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
|
82 } |
10357
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
83 } |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
84 else |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
85 is >> num; |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
86 |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
87 return is; |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
88 } |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
89 |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
90 static std::istringstream& |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
91 extract_num (std::istringstream& is, double& num, bool& imag, bool& have_sign) |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
92 { |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
93 have_sign = imag = false; |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
94 |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
95 char c = is.peek (); |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
96 bool negative = false; |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
97 |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
98 // Accept leading sign. |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
99 if (c == '+' || c == '-') |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
100 { |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
101 negative = c == '-'; |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
102 is.get (); |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
103 c = is.peek (); |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
104 have_sign = true; |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
105 } |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
106 |
11414
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
107 // It's i*num or just i. |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
108 if (is_imag_unit (c)) |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
109 { |
10357
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
110 c = is.get (); |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
111 imag = true; |
10357
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
112 char cn = is.peek (); |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
113 if (cn == '*') |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
114 { |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
115 // Multiplier follows, we extract it as a number. |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
116 is.get (); |
10357
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
117 single_num (is, num); |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
118 } |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
119 else |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
120 num = 1.0; |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
121 } |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
122 else |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
123 { |
11414
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
124 // It's num, num*i, or numi. |
10357
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
125 single_num (is, num); |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
126 if (is.good ()) |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
127 { |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
128 c = is.peek (); |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
129 if (c == '*') |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
130 { |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
131 is.get (); |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
132 c = is.get (); |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
133 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
|
134 { |
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
135 imag = true; |
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
136 is.peek (); |
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
137 } |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
138 else |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
139 is.setstate (std::ios::failbit); // indicate that read has failed. |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
140 } |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
141 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
|
142 { |
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
143 imag = true; |
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
144 is.get (); |
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
145 is.peek (); |
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
146 } |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
147 } |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
148 } |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
149 |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
150 if (negative) |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
151 num = -num; |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
152 |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
153 return is; |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
154 } |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
155 |
10379
f578e6468d0c
use C++-0x code in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10378
diff
changeset
|
156 static inline void |
f578e6468d0c
use C++-0x code in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10378
diff
changeset
|
157 set_component (Complex& c, double num, bool imag) |
f578e6468d0c
use C++-0x code in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10378
diff
changeset
|
158 { |
10380
60acc47c203f
configure checks for complex element setter/reference accessor methods
John W. Eaton <jwe@octave.org>
parents:
10379
diff
changeset
|
159 #if defined (HAVE_CXX_COMPLEX_SETTERS) |
10379
f578e6468d0c
use C++-0x code in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10378
diff
changeset
|
160 if (imag) |
10380
60acc47c203f
configure checks for complex element setter/reference accessor methods
John W. Eaton <jwe@octave.org>
parents:
10379
diff
changeset
|
161 c.imag (num); |
10379
f578e6468d0c
use C++-0x code in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10378
diff
changeset
|
162 else |
10380
60acc47c203f
configure checks for complex element setter/reference accessor methods
John W. Eaton <jwe@octave.org>
parents:
10379
diff
changeset
|
163 c.real (num); |
60acc47c203f
configure checks for complex element setter/reference accessor methods
John W. Eaton <jwe@octave.org>
parents:
10379
diff
changeset
|
164 #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
|
165 if (imag) |
60acc47c203f
configure checks for complex element setter/reference accessor methods
John W. Eaton <jwe@octave.org>
parents:
10379
diff
changeset
|
166 c.imag () = num; |
60acc47c203f
configure checks for complex element setter/reference accessor methods
John W. Eaton <jwe@octave.org>
parents:
10379
diff
changeset
|
167 else |
60acc47c203f
configure checks for complex element setter/reference accessor methods
John W. Eaton <jwe@octave.org>
parents:
10379
diff
changeset
|
168 c.real () = num; |
10379
f578e6468d0c
use C++-0x code in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10378
diff
changeset
|
169 #else |
f578e6468d0c
use C++-0x code in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10378
diff
changeset
|
170 if (imag) |
f578e6468d0c
use C++-0x code in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10378
diff
changeset
|
171 c = Complex (c.real (), num); |
f578e6468d0c
use C++-0x code in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10378
diff
changeset
|
172 else |
f578e6468d0c
use C++-0x code in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10378
diff
changeset
|
173 c = Complex (num, c.imag ()); |
f578e6468d0c
use C++-0x code in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10378
diff
changeset
|
174 #endif |
f578e6468d0c
use C++-0x code in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10378
diff
changeset
|
175 } |
f578e6468d0c
use C++-0x code in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10378
diff
changeset
|
176 |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
177 static Complex |
10381 | 178 str2double1 (const std::string& str_arg) |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
179 { |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
180 Complex val (0.0, 0.0); |
10381 | 181 |
182 std::string str = str_arg; | |
183 | |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
184 std::string::iterator se = str.end (); |
10381 | 185 |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
186 // Remove commas (thousand separators) and spaces. |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
187 se = std::remove (str.begin (), se, ','); |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
188 se = std::remove (str.begin (), se, ' '); |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
189 str.erase (se, str.end ()); |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
190 |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
191 std::istringstream is (str); |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
192 double num; |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
193 bool i1, i2, s1, s2; |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
194 |
10357
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
195 if (is.eof ()) |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
196 val = octave_NaN; |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
197 else if (! extract_num (is, num, i1, s1)) |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
198 val = octave_NaN; |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
199 else |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
200 { |
10380
60acc47c203f
configure checks for complex element setter/reference accessor methods
John W. Eaton <jwe@octave.org>
parents:
10379
diff
changeset
|
201 set_component (val, num, i1); |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
202 |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
203 if (! is.eof ()) |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
204 { |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
205 if (! extract_num (is, num, i2, s2) || i1 == i2 || ! s2) |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
206 val = octave_NaN; |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
207 else |
10380
60acc47c203f
configure checks for complex element setter/reference accessor methods
John W. Eaton <jwe@octave.org>
parents:
10379
diff
changeset
|
208 set_component (val, num, i2); |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
209 } |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
210 } |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
211 |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
212 return val; |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
213 } |
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 DEFUN_DLD (str2double, args, , |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
216 "-*- texinfo -*-\n\ |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
217 @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
|
218 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
|
219 \n\ |
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
220 The string must be in one of the following formats where\n\ |
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
221 a and b are real numbers and the complex unit is 'i' or 'j':\n\ |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
222 \n\ |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
223 @itemize\n\ |
10840 | 224 @item a + bi\n\ |
225 \n\ | |
226 @item a + b*i\n\ | |
227 \n\ | |
228 @item a + i*b\n\ | |
229 \n\ | |
230 @item bi + a\n\ | |
231 \n\ | |
232 @item b*i + a\n\ | |
233 \n\ | |
234 @item i*b + a\n\ | |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
235 @end itemize\n\ |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
236 \n\ |
11414
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
237 If present, a and/or b are of the form [+-]d[,.]d[[eE][+-]d] where the\n\ |
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
238 brackets indicate optional arguments and 'd' indicates zero or more\n\ |
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
239 digits. The special input values @code{Inf}, @code{NaN}, and @code{NA} are\n\ |
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
240 also accepted.\n\ |
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
241 \n\ |
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
242 @var{s} may also be a character matrix, in which case the conversion is\n\ |
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
243 repeated for each row. Or @var{s} may be a cell array of strings, in which\n\ |
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
244 case each element is converted and an array of the same dimensions is\n\ |
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
245 returned.\n\ |
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
246 \n\ |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
247 @code{str2double} can replace @code{str2num}, and it avoids the use of\n\ |
11414
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
248 @code{eval} on unknown data.\n\ |
5e6ef42a2445
Overhaul str2double function fixing bug and docstring and adding 'NA' processing.
Rik <octave@nomad.inbox5.com>
parents:
10846
diff
changeset
|
249 @seealso{str2num}\n\ |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
250 @end deftypefn") |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
251 { |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
252 octave_value retval; |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
253 |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
254 if (args.length () == 1) |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
255 { |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
256 if (args(0).is_string ()) |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
257 { |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
258 if (args(0).rows () == 1 && args(0).ndims () == 2) |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
259 { |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
260 retval = str2double1 (args(0).string_value ()); |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
261 } |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
262 else |
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 const string_vector sv = args(0).all_strings (); |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
265 if (! error_state) |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
266 retval = sv.map<Complex> (str2double1); |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
267 } |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
268 } |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
269 else if (args(0).is_cellstr ()) |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
270 { |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
271 Array<std::string> sa = args(0).cellstr_value (); |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
272 retval = sa.map<Complex> (str2double1); |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
273 } |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
274 else |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
275 gripe_wrong_type_arg ("str2double", args(0)); |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
276 } |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
277 else |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
278 print_usage (); |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
279 |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
280 return retval; |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
281 } |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
282 |
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 |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
285 %!assert (str2double ("1"), 1) |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
286 %!assert (str2double ("-.1e-5"), -1e-6) |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
287 %!assert (str2double ("1,222.5"), 1222.5) |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
288 %!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
|
289 %!assert (str2double ("2j"), 2i) |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
290 %!assert (str2double ("2 + j"), 2+j) |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
291 %!assert (str2double ("i*2 + 3"), 3+2i) |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
292 %!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
|
293 %!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
|
294 %!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
|
295 %!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
|
296 %!assert (str2double ("Hello World"), NaN) |
10357
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
297 %!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
|
298 %!assert (str2double ("NA"), NA) |
10357
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
299 %!assert (str2double ("Inf"), Inf) |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
300 %!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
|
301 %!assert (str2double ("Inf*i"), complex (0, Inf)) |
10357
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
302 %!assert (str2double ("NaN + Inf*i"), complex (NaN, Inf)) |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
303 %!assert (str2double ("Inf - Inf*i"), complex (Inf, -Inf)) |
7658cd4bdcf2
handle Infs and NaNs in str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
10356
diff
changeset
|
304 %!assert (str2double ("-i*NaN - Inf"), complex (-Inf, -NaN)) |
10356
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
305 |
1d7930b77ab9
implement compiled str2double
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
306 */ |