[erlang-bugs] float parsing bug

Alexander Borovsky alex.borovsky@REDACTED
Sun Jan 10 19:53:40 CET 2010


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


More information about the erlang-bugs mailing list