Skip to content

Commit 3b28783

Browse files
jmkuhnstevengj
authored andcommitted
Improve show method
1 parent 5462da6 commit 3b28783

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/DecFP.jl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ function isnanstr(s::AbstractString)
7979
return true
8080
end
8181

82+
function Base.show(io::IO, x::DecimalFloatingPoint)
83+
s = @sprintf("%g", x)
84+
if ismatch(r"^-?\d+$", s)
85+
s *= ".0"
86+
end
87+
print(io, s)
88+
end
89+
8290
for w in (32,64,128)
8391
BID = Symbol(string("Dec",w))
8492
Ti = eval(Symbol(string("UInt",w)))
@@ -105,11 +113,6 @@ for w in (32,64,128)
105113

106114
$BID(x::AbstractString) = parse($BID, x)
107115

108-
function Base.show(io::IO, x::$BID)
109-
ccall(($(bidsym(w,"to_string")), libbid), Void, (Ptr{UInt8}, $BID), _buffer, x)
110-
unsafe_write(io, pointer(_buffer), ccall(:strlen, Csize_t, (Ptr{UInt8},), _buffer))
111-
end
112-
113116
function Base.Printf.fix_dec(x::$BID, n::Int)
114117
if n > length(DIGITS) - 1
115118
n = length(DIGITS) - 1

0 commit comments

Comments
 (0)