43 {
return c ==
'i' || c ==
'j'; }
59 if (std::toupper (c) ==
'I')
63 char c1 = is.get (), c2 = is.get ();
64 if (std::tolower (c1) ==
'n' && std::tolower (c2) ==
'f')
70 is.setstate (std::ios::failbit);
85 if (c1 ==
'a' && c2 ==
'N')
91 is.setstate (std::ios::failbit);
100 static std::istringstream&
103 have_sign = imag =
false;
114 bool negative =
false;
117 if (c ==
'+' || c ==
'-')
143 num = negative ? -1.0 : 1.0;
148 if (std::tolower (c) !=
'n')
213 is.setstate (std::ios::failbit);
243 #if defined (HAVE_CXX_COMPLEX_SETTERS)
248 #elif defined (HAVE_CXX_COMPLEX_REFERENCE_ACCESSORS)
266 std::string str = str_arg;
270 str.erase (std::remove (str.begin (), str.end(),
','), str.end ());
271 std::istringstream is (str);
286 if (!
extract_num (is, num, i2, s2) || i1 == i2 || ! s2)
296 DEFUN (str2double, args, ,
298 @deftypefn {Built-in Function} {} str2double (@var{s})\n\
299 Convert a string to a real or complex number.\n\
301 The string must be in one of the following formats where\n\
302 a and b are real numbers and the complex unit is @qcode{'i'} or @qcode{'j'}:\n\
318 If present, a and/or b are of the form @nospell{[+-]d[,.]d[[eE][+-]d]} where\n\
319 the brackets indicate optional arguments and @qcode{'d'} indicates zero or\n\
320 more digits. The special input values @code{Inf}, @code{NaN}, and @code{NA}\n\
321 are also accepted.\n\
323 @var{s} may be a character string, character matrix, or cell array.\n\
324 For character arrays the conversion is repeated for every row, and\n\
325 a double or complex array is returned. Empty rows in @var{s} are deleted\n\
326 and not returned in the numeric array. For cell arrays each character\n\
327 string element is processed and a double or complex array of the same\n\
328 dimensions as @var{s} is returned.\n\
330 For unconvertible scalar or character string input @code{str2double} returns\n\
331 a NaN@. Similarly, for character array input @code{str2double} returns a\n\
332 NaN for any row of @var{s} that could not be converted. For a cell array,\n\
333 @code{str2double} returns a NaN for any element of @var{s} for which\n\
334 conversion fails. Note that numeric elements in a mixed string/numeric\n\
335 cell array are not strings and the conversion will fail for these elements\n\
338 @code{str2double} can replace @code{str2num}, and it avoids the security\n\
339 risk of using @code{eval} on unknown data.\n\
345 if (args.length () != 1)
347 else if (args(0).is_string ())
349 if (args(0).rows () == 0 || args(0).columns () == 0)
353 else if (args(0).
rows () == 1 && args(0).
ndims () == 2)
364 else if (args(0).is_cell ())
366 const Cell cell = args(0).cell_value ();
373 if (cell(i).is_string ())