octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #39838] str2double ('') gives [](0x1) instead


From: Philip Nienhuis
Subject: [Octave-bug-tracker] [bug #39838] str2double ('') gives [](0x1) instead of NaN
Date: Sat, 24 Aug 2013 10:29:08 +0000
User-agent: Mozilla/5.0 (X11; Linux i686; rv:20.0) Gecko/20100101 Firefox/20.0 Iceape/2.17

Follow-up Comment #2, bug #39838 (project octave):

Although IMO it's a bit close to the edge I agree with the str2double({})
outcome. At least that case makes sense.

For the other cases I tend to simply follow the help text's message that "all
output that str2double cannot parse" (after having detected input to be no
cell array) "gives a NaN".

In particular as to str2double (''), as shown below, str2double's current
behavior as regards arrays of strings can be deceptive:

>> str2double (['2'; ''; "1"])
ans =

   2
   1


...so in such a case str2double doesn't return an array equal in size as the
input array. I suppose that is (or should be) the very rationale that NaNs are
always needed to reflect any empty string input: to prevent str2double from
silently "post-resizing" its class double output.
In case of cell arrays str2double behaves correctly:

>> str2double ({'2'; ''; '1'})
ans =

    2.0000e+00
           NaN
    1.0000e+00


Anyway, after we have decided about ({}) input, at least the st2double help
text could be amended to better clarify its behavior (I'll do that then).
Something like:

1. Is it a cell array (optionally with empty cells?) 
..yes-> return equally sized array (see 3.)
..no->  go to 2
2. Is it a string or array of strings?
..yes-> return equally sized array (see 3.)
..no->  return NaN
3. For all unparsable individual cells str2double returns a NaN


    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?39838>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]