Permalink
Browse files

Better inspect for floats

  • Loading branch information...
1 parent c5e19a3 commit ab4c9322cf402b1f2bc74a613b4b3cc3b981e82a @devinus committed Oct 15, 2012
Showing with 8 additions and 7 deletions.
  1. +3 −3 lib/elixir/lib/binary/inspect.ex
  2. +5 −4 lib/elixir/test/elixir/binary/inspect_test.exs
@@ -272,7 +272,7 @@ defimpl Binary.Inspect, for: List do
keywords?(thing) ->
"[" <> join_keywords(thing, opts) <> "]"
true ->
- container_join(thing, "[", "]", opts)
+ container_join(thing, "[", "]", opts)
end
end
@@ -285,7 +285,7 @@ defimpl Binary.Inspect, for: List do
keywords?(rest, key)
end
defp keywords?([], _prev), do: true
- defp keywords?(_other, _prev), do: false
+ defp keywords?(_other, _prev), do: false
defp join_keywords(thing, opts) do
Enum.join(lc {key, value} inlist thing do
@@ -416,7 +416,7 @@ defimpl Binary.Inspect, for: Number do
end
def inspect(thing, _) do
- list_to_binary float_to_list(thing)
+ list_to_binary :io_lib.format("~p", [thing])
end
end
@@ -84,9 +84,10 @@ defmodule Binary.Inspect.NumberTest do
end
test :float do
- assert inspect(1.0) == "1.00000000000000000000e+00"
- assert inspect(1.0e10) == "1.00000000000000000000e+10"
- assert inspect(1.0e+10) == "1.00000000000000000000e+10"
+ assert inspect(1.0) == "1.0"
+ assert inspect(1.0e10) == "1.0e10"
+ assert inspect(1.0e+10) == "1.0e10"
+ assert inspect(1.0e-10) == "1.0e-10"
end
end
@@ -155,7 +156,7 @@ defmodule Binary.Inspect.ListTest do
end
test :non_printable do
- assert inspect([{:b, 1},{:a,1}]) == "[{:b,1},{:a,1}]"
+ assert inspect([{:b, 1},{:a,1}]) == "[{:b,1},{:a,1}]"
end
test :unproper do

0 comments on commit ab4c932

Please sign in to comment.