octave-maintainers
[Top][All Lists]
Advanced

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

Re: str2double behavior


From: PhilipNienhuis
Subject: Re: str2double behavior
Date: Tue, 1 Nov 2011 01:47:40 -0700 (PDT)

Rik wrote:
> 
> On 10/31/2011 10:00 AM, octave-maintainers-request@ wrote:
>> Message: 2
>> Date: Mon, 31 Oct 2011 07:19:18 -0400
>> From: Ben Abbott <bpabbott@>
>> To: PhilipNienhuis <pr.nienhuis@>
>> Cc: "octave-maintainers@" <octave-maintainers@>
>> Subject: Re: Question about str2double
>> Message-ID: <76E897EC-D03A-4611-8914-3FBAD27A4384@>
>> Content-Type: text/plain; CHARSET=US-ASCII
>>
>> On Oct 30, 2011, at 10:26 AM, PhilipNienhuis &lt;pr.nienhuis@&gt; wrote:
>>
>>> > octave:11> str2double ('1 2 3 4')
>>> > ans =  1234
>>> > 
>>> > Is it intended behaviour that str2double ignores spaces?
>> Matlab returns NaN. Octave's behavior appears to be buggy. 
>>
>> Ben
> 10/31/11
> 
> Yes, this is buggy.  Octave takes a shortcut at the beginning of parsing. 
> See the code segment below from str2double.cc in src/DLD-FUNCTIONS:
> 
> --- CODE ---
>   std::string::iterator se = str.end ();
> 
>   // Remove commas (thousand separators) and spaces.
>   se = std::remove (str.begin (), se, ',');
>   se = std::remove (str.begin (), se, ' ');
>   str.erase (se, str.end ());
> --- END CODE ---
> 
> This code collapses the unwanted characters instead of discarding them
> during the parsing loop.  The result is that not only "1 2 3 4" but also
> "1,2,3,4" will be converted to 1234.  I don't think this is what is
> desired
> when the documentation says it accepts the comma as a thousands separator.
> 
> --Rik
> 

OK, I filed a bug report (https://savannah.gnu.org/bugs/index.php?34713)

P.

--
View this message in context: 
http://octave.1599824.n4.nabble.com/Re-str2double-behavior-tp3956523p3962834.html
Sent from the Octave - Maintainers mailing list archive at Nabble.com.


reply via email to

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