diff options
author | felipe stival <14948182+v0idpwn@users.noreply.github.com> | 2021-11-30 15:15:54 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-30 14:15:54 +0100 |
commit | 31dd59dbd1dcc5af86823efcf232980769cb37d1 (patch) | |
tree | 9a749a1fba6e4f30221ee6933e5a056948fcbffb | |
parent | a1e794fce583396c14ef21c384bcd7e43c076257 (diff) | |
download | elixir-31dd59dbd1dcc5af86823efcf232980769cb37d1.tar.gz |
Add note in Float.to_{string/charlist}/1 (#11359)
-rw-r--r-- | lib/elixir/lib/float.ex | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/lib/elixir/lib/float.ex b/lib/elixir/lib/float.ex index 8458f33a1..32112088a 100644 --- a/lib/elixir/lib/float.ex +++ b/lib/elixir/lib/float.ex @@ -509,13 +509,20 @@ defmodule Float do defp sign(1, num), do: -num @doc """ - Returns a charlist which corresponds to the text representation + Returns a charlist which corresponds to the shortest text representation of the given float. - It uses the shortest representation according to algorithm described - in "Printing Floating-Point Numbers Quickly and Accurately" in - Proceedings of the SIGPLAN '96 Conference on Programming Language - Design and Implementation. + The underlying algorithm changes depending on the Erlang/OTP version: + + * For OTP >= 24, it uses the algorithm presented in "Ryū: fast + float-to-string conversion" in Proceedings of the SIGPLAN '2018 + Conference on Programming Language Design and Implementation. + + * For OTP < 24, it uses the algorithm presented in "Printing Floating-Point + Numbers Quickly and Accurately" in Proceedings of the SIGPLAN '1996 + Conference on Programming Language Design and Implementation. + + For a configurable representation, use `:erlang.float_to_list/2`. ## Examples @@ -529,13 +536,20 @@ defmodule Float do end @doc """ - Returns a binary which corresponds to the text representation + Returns a binary which corresponds to the shortest text representation of the given float. - It uses the shortest representation according to algorithm described - in "Printing Floating-Point Numbers Quickly and Accurately" in - Proceedings of the SIGPLAN '96 Conference on Programming Language - Design and Implementation. + The underlying algorithm changes depending on the Erlang/OTP version: + + * For OTP >= 24, it uses the algorithm presented in "Ryū: fast + float-to-string conversion" in Proceedings of the SIGPLAN '2018 + Conference on Programming Language Design and Implementation. + + * For OTP < 24, it uses the algorithm presented in "Printing Floating-Point + Numbers Quickly and Accurately" in Proceedings of the SIGPLAN '1996 + Conference on Programming Language Design and Implementation. + + For a configurable representation, use `:erlang.float_to_binary/2`. ## Examples |