Skip to content

Commit

Permalink
FloatPrinter: remove -NaN test, fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
will committed Apr 25, 2017
1 parent c0dee22 commit c0de4b0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion spec/std/float_printer_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe "#print" do

it { test_str "Infinity" }

it { test_str "NaN" }
it { test_pair Float64::NAN, "NaN" }

it { test_str "0.01" }
it { test_str "0.1" }
Expand Down
7 changes: 3 additions & 4 deletions src/float_printer.cr
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ module FloatPrinter
# add integer part digits
if decimal_exponent > 0 && !exp_mode
# whole number but not big enough to be exp form
io.write_utf8 buffer.to_slice[i, length-i]
io.write_utf8 buffer.to_slice[i, length - i]
i = length
(point - length).times { io << '0' }
elsif i < point
io.write_utf8 buffer.to_slice[i, point-i]
io.write_utf8 buffer.to_slice[i, point - i]
i = point
end

Expand All @@ -75,10 +75,9 @@ module FloatPrinter
end

# add fractional part digits
io.write_utf8 buffer.to_slice[i, length-i]
io.write_utf8 buffer.to_slice[i, length - i]
i = length


# print trailing 0 if whole number or exp notation of power of ten
if (decimal_exponent >= 0 && !exp_mode) || (exp != point && length == 1)
io << '0'
Expand Down

0 comments on commit c0de4b0

Please sign in to comment.