From 5eb6e9f311a80f4c7811dee7a5f02aaf4d3d2db6 Mon Sep 17 00:00:00 2001 From: pnezis Date: Fri, 10 Jul 2026 19:44:34 +0300 Subject: [PATCH] Reject integer 0 in `Float.round/2` 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. --- lib/elixir/lib/float.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/elixir/lib/float.ex b/lib/elixir/lib/float.ex index 080a33a6a8..3c530b978f 100644 --- a/lib/elixir/lib/float.ex +++ b/lib/elixir/lib/float.ex @@ -346,7 +346,7 @@ defmodule Float do @spec round(float, precision_range) :: float def round(float, precision \\ 0) - def round(float, 0) when float == 0.0, do: float + def round(float, 0) when float === 0.0 or float === -0.0, do: float def round(float, 0) when is_float(float) do case :erlang.round(float) * 1.0 do