Skip to content

Commit 84d317c

Browse files
committed
Inline Float.to_charlist/1 and Float.to_string/1
1 parent 1b604f5 commit 84d317c

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/elixir/lib/float.ex

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,14 +589,16 @@ defmodule Float do
589589
590590
For a configurable representation, use `:erlang.float_to_list/2`.
591591
592+
Inlined by the compiler.
593+
592594
## Examples
593595
594596
iex> Float.to_charlist(7.0)
595597
~c"7.0"
596598
597599
"""
598600
@spec to_charlist(float) :: charlist
599-
def to_charlist(float) when is_float(float) do
601+
def to_charlist(float) do
600602
:erlang.float_to_list(float, [:short])
601603
end
602604

@@ -616,14 +618,16 @@ defmodule Float do
616618
617619
For a configurable representation, use `:erlang.float_to_binary/2`.
618620
621+
Inlined by the compiler.
622+
619623
## Examples
620624
621625
iex> Float.to_string(7.0)
622626
"7.0"
623627
624628
"""
625629
@spec to_string(float) :: String.t()
626-
def to_string(float) when is_float(float) do
630+
def to_string(float) do
627631
:erlang.float_to_binary(float, [:short])
628632
end
629633

lib/elixir/src/elixir_rewrite.erl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
-define(atom, 'Elixir.Atom').
99
-define(bitwise, 'Elixir.Bitwise').
1010
-define(enum, 'Elixir.Enum').
11+
-define(float, 'Elixir.Float').
1112
-define(function, 'Elixir.Function').
1213
-define(integer, 'Elixir.Integer').
1314
-define(io, 'Elixir.IO').
@@ -239,6 +240,8 @@ rewrite(Receiver, DotMeta, Right, Meta, Args) ->
239240
{EReceiver, ERight, EArgs} = inner_rewrite(ex_to_erl, DotMeta, Receiver, Right, Args),
240241
{{'.', DotMeta, [EReceiver, ERight]}, Meta, EArgs}.
241242

243+
?rewrite(?float, to_charlist, [Arg], erlang, float_to_list, [Arg, [short]]);
244+
?rewrite(?float, to_string, [Arg], erlang, float_to_binary, [Arg, [short]]);
242245
?rewrite(?kernel, is_map_key, [Map, Key], erlang, is_map_key, [Key, Map]);
243246
?rewrite(?map, delete, [Map, Key], maps, remove, [Key, Map]);
244247
?rewrite(?map, fetch, [Map, Key], maps, find, [Key, Map]);

0 commit comments

Comments
 (0)