Skip to content

Commit

Permalink
Don't convert to Float64 in Printf
Browse files Browse the repository at this point in the history
  • Loading branch information
jmkuhn committed Feb 22, 2024
1 parent 1de2856 commit e9515e9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/DecFP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,8 @@ promote_rule(::Type{Irrational{s}}, T::Type{Complex{F}}) where {s,F<:DecimalFloa
Base.widen(::Type{Dec32}) = Dec64
Base.widen(::Type{Dec64}) = Dec128

Printf.tofloat(x::DecimalFloatingPoint) = BigFloat(x)

macro d_str(s, flags...) parse(Dec64, s) end
macro d32_str(s, flags...) parse(Dec32, s) end
macro d64_str(s, flags...) parse(Dec64, s) end
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ for T in (Dec32, Dec64, Dec128)

@test @sprintf("%.2f %.4f", T("12.34567"), 9.87) == "12.35 9.8700"

# issue #178
@test @sprintf("%.36f", T("0.1")) == "0.100000000000000000000000000000000000"

x,y,z = 1.5, -3.25, 0.0625 # exactly represented in binary
xd = T(x); yd = T(y); zd = T(z)

Expand Down

0 comments on commit e9515e9

Please sign in to comment.