Skip to content

Fix Float.parse/1 inconsistent error handling for non-scientific no…#15157

Merged
josevalim merged 1 commit into
elixir-lang:mainfrom
pnezis:fix/float-parse-overflow-error-handling
Mar 9, 2026
Merged

Fix Float.parse/1 inconsistent error handling for non-scientific no…#15157
josevalim merged 1 commit into
elixir-lang:mainfrom
pnezis:fix/float-parse-overflow-error-handling

Conversation

@pnezis
Copy link
Copy Markdown
Contributor

@pnezis pnezis commented Mar 9, 2026

…tation overflow

Float.parse/1 was returning :error for overflow in scientific notation (e.g., "1.0e400") but raising ArgumentError for equivalent overflow in non-scientific notation (e.g., a 310-digit number). This violated the documented behavior that states Float.parse/1 should return :error when the float exceeds the maximum size.

Example:

iex> Float.parse(String.duplicate("9", 310) <> ".0")
** (ArgumentError) errors were found at the given arguments:

  * 1st argument: not a textual representation of a float

    :erlang.binary_to_float("9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999.0")
    (elixir 1.18.2) lib/float.ex:197: Float.parse_unsigned/4
    iex:1: (file)

Comment thread lib/elixir/lib/float.ex
…tation overflow

`Float.parse/1` was returning `:error` for overflow in scientific notation (e.g.,
"1.0e400") but raising `ArgumentError` for equivalent overflow in non-scientific
notation (e.g., a 310-digit number). This violated the documented behavior that
states `Float.parse/1` should return `:error` when the float exceeds the maximum
size.
@pnezis pnezis force-pushed the fix/float-parse-overflow-error-handling branch from 380c228 to c18e94e Compare March 9, 2026 16:39
@josevalim josevalim merged commit 5e7671a into elixir-lang:main Mar 9, 2026
15 checks passed
@josevalim
Copy link
Copy Markdown
Member

💚 💙 💜 💛 ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants