Skip to content

Reject integer 0 in Float.round/2#15585

Merged
josevalim merged 1 commit into
elixir-lang:mainfrom
pnezis:fix-float-round-integer-zero
Jul 10, 2026
Merged

Reject integer 0 in Float.round/2#15585
josevalim merged 1 commit into
elixir-lang:mainfrom
pnezis:fix-float-round-integer-zero

Conversation

@pnezis

@pnezis pnezis commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

The zero shortcut clause guarded only on float == 0.0, and 0 == 0.0 is true under ==, so Float.round(0) and Float.round(0, 0) returned the integer 0 instead of raising, contradicting both the spec and the doc statement that the function only accepts floats and always returns a float. Float.round(1) and every other Float function already raised.

iex(5)> Float.round(0)
0
iex(6)> Float.round(1)
** (FunctionClauseError) no function clause matching in Float.round/2

    The following arguments were given to Float.round/2:

        # 1
        1

        # 2
        0

I am evaluating claude fable on code review tasks and this was one of the findings - more to follow

Comment thread lib/elixir/lib/float.ex Outdated
@pnezis pnezis force-pushed the fix-float-round-integer-zero branch from 53c5950 to 3a58598 Compare July 10, 2026 17:18
The zero shortcut clause guarded only on `float == 0.0`, and `0 == 0.0` is
true under ==, so `Float.round(0)` and `Float.round(0, 0)` returned the
integer 0 instead of raising, contradicting both the spec and the doc
statement that the function only accepts floats and always returns a
float. `Float.round(1)` and every other `Float` function already raised.
@pnezis pnezis force-pushed the fix-float-round-integer-zero branch from 3a58598 to 5eb6e9f Compare July 10, 2026 19:56
@josevalim josevalim merged commit 8fcf677 into elixir-lang:main Jul 10, 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