Skip to content

Commit

Permalink
mochinum:digits/1: fix handling of -0.0 for OTP-26.1/27.0
Browse files Browse the repository at this point in the history
Matching of floating-point zeroes will change in OTP-27 so that -0.0 will
no longer match a non-negative 0.0. OTP-26.1 warns about such constructs,
which in mochiweb results in:

src/mochinum.erl:47:8: Warning: matching on the float 0.0 will no longer also match -0.0 in OTP 27. If you specifically intend to match 0.0 alone, write +0.0 instead.

Fixed by switching from a match to a numerical comparison.
  • Loading branch information
mikpe committed Sep 22, 2023
1 parent cab4474 commit 1aa9ba1
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/mochinum.erl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
%% human-readable output, or compact ASCII serializations for floats.
digits(N) when is_integer(N) ->
integer_to_list(N);
digits(0.0) ->
digits(Float) when Float == 0.0 ->
"0.0";
digits(Float) ->
{Frac1, Exp1} = frexp_int(Float),
Expand Down Expand Up @@ -287,6 +287,8 @@ digits_test() ->
digits(0)),
?assertEqual("0.0",
digits(0.0)),
?assertEqual("0.0",
digits(-0.0)),
?assertEqual("1.0",
digits(1.0)),
?assertEqual("-1.0",
Expand Down

0 comments on commit 1aa9ba1

Please sign in to comment.