[erlang-bugs] float parsing bug

Fredrik Svahn fredrik.svahn@REDACTED
Sun Jan 10 20:29:04 CET 2010


See: http://old.nabble.com/list_to_float%28%29-td19309221.html

BR /Fredrik

On Sun, Jan 10, 2010 at 7:53 PM, Alexander Borovsky
<alex.borovsky@REDACTED> wrote:
> On Sun, Jan 10, 2010 at 19:58, Ulf Wiger wrote:
>
>> Alexander Borovsky wrote:
>>> Release: R13B03
>>>
>>> Steps to reproduce:
>>> 1) erlang:list_to_float("42")
>>>
>>> Expected result:
>>> 42.0 (float)
>>>
>>> Actual result:
>>> error:badarg
>>
>> Arguably, this is in line with the documented behaviour:
>>
>> "list_to_float(String) -> float()
>>
>> Types:
>> String = string()
>>
>> Returns the float whose text representation is String.
>>
>>> list_to_float("2.2017764e+0").
>> 2.2017764
>>
>> Failure: badarg if String contains a bad representation of a float."
>>
>>
>> There is no float that has the text representation "42".
>
> 42.0 could have text representation "42".
>
> In most languages (C, Java, Ruby, etc) "42" parsed to float with no errors.
>
> Also in some cases float values could be outputted with no decimal point:
>
> In C:
> #include<stdio.h>
>
> int main() {
>  double d = 42;
>  printf("%g\n", d);
>  return 0;
> }
>
> will print "42"
>
> So integers should be properly parsed by list_to_float() function (as
> corresponding float value)
>
> --
> With best regards,
> Alexander Borovsky
>
> ________________________________________________________________
> erlang-bugs mailing list. See http://www.erlang.org/faq.html
> erlang-bugs (at) erlang.org
>
>


More information about the erlang-bugs mailing list