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 12:20:59 -0800

On 12/27/2012 10:53 AM, John W. Eaton wrote:
> On 27-Dec-2012, Rik wrote:
>
> | 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.
>
> Could we do a regexp replacement instead of simply stripping the
> commas?
s/(.),(\d{3})/$1$2/g (in Perl syntax) would mostly work.  It still wouldn't
correctly handle commas after the decimal point such as "1.234,456" which
is an error.

It might be overkill to invoke regular expressions for this though.  The
defining criterion is that a comma can't start a number, that a comma must
precede the decimal point, and that the comma must always be followed by 3
digits.  Instead of using std::remove we could use std::remove_if with a
test function which checks those criterion.

--Rik


reply via email to

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