Skip to content

Should Float.parse/1 handle overflows gracefully? #3862

Description

@joshuap

When I call Float.parse/1 with an exponent that is too large, Erlang raises an ArgumentError:

iex(1)> Float.parse("12.345e308")
** (ArgumentError) argument error
             :erlang.binary_to_float("12.345e308")
    (elixir) lib/float.ex:67: Float.parse_unsigned/4

The error isn't communicative, and the documentation for Float.parse/1 does not mention it. Based on the current documentation I would expect :error to be returned instead, for example:

joshuap@89b65af

~/code/elixir ‹float_exponent_fix› » bin/elixir lib/elixir/test/elixir/float_test.exs                                                                  18 ↵
...

  1) test parse (FloatTest)
     lib/elixir/test/elixir/float_test.exs:6
     ** (ArgumentError) argument error
     stacktrace:
       :erlang.binary_to_float("12.345e308")
       (elixir) lib/float.ex:67: Float.parse_unsigned/4
       lib/elixir/test/elixir/float_test.exs:35

..

Finished in 0.2 seconds (0.2s on load, 0.00s on tests)
6 tests, 1 failure

Would this be desired behavior to add, or is the exception expected?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions