octave-maintainers
[Top][All Lists]
Advanced

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

Re: FIXME in str2double.cc


From: Rik
Subject: Re: FIXME in str2double.cc
Date: Thu, 27 Dec 2012 10:47:25 -0800

On 12/27/2012 10:00 AM, address@hidden wrote:
> Message: 1
> Date: Wed, 26 Dec 2012 13:40:00 -0600
> From: Daniel J Sebald <address@hidden>
> To: J?lio Hoffimann <address@hidden>
> Cc: "John W. Eaton" <address@hidden>, octave maintainers mailing list
>       <address@hidden>
> Subject: Re: Random questions
> Message-ID: <address@hidden>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> On 12/26/2012 09:36 AM, J?lio Hoffimann wrote:
>> > The attached diff is a microscopic change that makes the code more
>> > intuitive.
>> >
>> > J?lio.
>     // FIXME -- removing all commas does too much...
> -  std::string::iterator se = str.end ();
> -  se = std::remove (str.begin (), se, ',');
> -  str.erase (se, str.end ());
> +  str.erase (std::remove (str.begin (), str.end(), ','), str.end ());
>
> What is the FIXME about in this code hunk?  Can the code be fixed and 
> the comment removed?
str2double is supposed to accept the comma as a thousands separator. 
Octave is being lazy and removes all the commas from the string before
processing.  This works fine for legitimate input such as str2double
("1,234.56") but it masks errors when you try str2double ("1,2,3,4") and
get 1234 as a result.  I believe it has been verified that Matlab is
actually checking for proper use of the comma and will return a NaN in the
second case.

--Rik


reply via email to

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