Skip to content

Commit

Permalink
feat(koan): add a koan about rounding pitfalls
Browse files Browse the repository at this point in the history
The solution is 2.67

This is because 2.675 is actually approximated in IEE754:
2.67499999999999982236431605997495353221893310546875

Close, but no cigar.

Fixes elixirkoans#268

/spend 30m
  • Loading branch information
Goutte committed Jul 15, 2024
1 parent 2921a74 commit 0436be0
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/koans/03_numbers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ defmodule Numbers do
assert Float.round(-5.5674, 3) === ___
end

koan "But beware of floating dragons" do
assert Float.round(2.675, 2) == ___
end

koan "I want the first and last in the range" do
first..last = Range.new(1, 10)

Expand Down

0 comments on commit 0436be0

Please sign in to comment.