erlang / otp

Erlang/OTP
http://erlang.org
Apache License 2.0
11.4k stars 2.95k forks source link

binary_to_float doesn't correctly handle scientific notation with no decimal places specified, such as "1e0" #9061

Open Peter-Searby opened 5 days ago

Peter-Searby commented 5 days ago

Describe the bug The binary_to_float built in function should support numbers in scientific notation without decimal places specified.

To Reproduce The following raises a badarg error: binary_to_float(<<"1e0">>).

Expected behavior 1 = binary_to_float(<<"1e0">>).

Affected versions OTP 27 and all prior versions with this function.

Additional context Other languages, such as C++ and Golang will use this format when all decimal places are 0, so support for this format is important for cross-compatibility.

michalmuskala commented 3 days ago

Native support for this format could slightly speed up json - it does support the "dotless" format and today we have to re-allocate the float string before parsing to support that

https://github.com/erlang/otp/blob/2b23f5bc4c5ea327739ea9c08ed97c4581b3201c/lib/stdlib/src/json.erl#L1167