Skip to content

Commit

Permalink
Document limits of Float.parse/1.
Browse files Browse the repository at this point in the history
This commit clarifies the documentation for `Float.parse/1` as well as
adds test assertions to demonstrate the limits enforced by erlang/IEEE
754-1985 double precision floats. See elixir-lang#3862 for more context.
  • Loading branch information
Joshua Wood committed Oct 13, 2015
1 parent 71e5acc commit c4fe362
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/elixir/lib/float.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ defmodule Float do
Parses a binary into a float.
If successful, returns a tuple of the form `{float, remainder_of_binary}`;
otherwise, `:error`.
when the binary cannot be coerced into a valid float, the atom `:error` is
returned; otherwise, the exception `ArgumentError` is raised by erlang (for
example, when the size of the float exceeds the maximum size of
`1.7976931348623157e+308`).
If a float formatted string wants to be directly converted to a float,
`String.to_float/1` can be used instead.
Expand Down
4 changes: 4 additions & 0 deletions lib/elixir/test/elixir/float_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ defmodule FloatTest do
assert Float.parse("--1.2") === :error
assert Float.parse("++1.2") === :error
assert Float.parse("pi") === :error
assert Float.parse("1.7976931348623157e308") === {1.7976931348623157e308, ""}
assert_raise ArgumentError, fn ->
Float.parse("1.7976931348623159e308")
end
end

test "floor" do
Expand Down

0 comments on commit c4fe362

Please sign in to comment.