Skip to content

Commit

Permalink
Handle isapprox 0 differently
Browse files Browse the repository at this point in the history
  • Loading branch information
rikhuijzer committed Apr 30, 2021
1 parent ca7465a commit 762fc81
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/ryu.jl
Expand Up @@ -7,9 +7,10 @@ function plain_precision_heuristic(xs::AbstractArray{<:AbstractFloat})
e10max = -(e10min = typemax(Int))
for y in ys
if isapprox(y, 0, atol=1e-16)
continue
e10 = min(e10min, 0)
else
_, e10 = Ryu.reduce_shortest(convert(Float32, y))
end
_, e10 = Ryu.reduce_shortest(convert(Float32, y))
e10min = min(e10min, e10)
e10max = max(e10max, e10)
end
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Expand Up @@ -49,6 +49,7 @@ end
@test showoff(x) == ["1.12345", "4.56780"]
@test showoff([0.0, 50000.0]) == (drops0s ? ["0", "5×10⁴"] : ["0", "5.0×10⁴"])
@test showoff(x, :plain) == ["1.12345", "4.56780"]
@test showoff([0.0], :plain) == ["0"]
@test showoff(x, :scientific) == (drops0s ? ["1.12345×10⁰", "4.56780×10⁰"] : ["1.123450×10⁰", "4.567800×10⁰"])
@test showoff(x, :engineering) == showoff(x, :scientific)
@test showoff([DateTime("2017-04-11", "yyyy-mm-dd")]) == ["Apr 11, 2017"]
Expand Down

0 comments on commit 762fc81

Please sign in to comment.