Skip to content

Commit 21032e8

Browse files
committed
dont use Ryu
1 parent 9c4561f commit 21032e8

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

src/Quadmath.jl

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -558,22 +558,24 @@ function parse(::Type{Float128}, s::AbstractString)
558558
Float128(@quad_ccall(libquadmath.strtoflt128(s::Cstring, C_NULL::Ptr{Ptr{Cchar}})::Cfloat128))
559559
end
560560

561-
using Base.Ryu: writeshortest
562561
function string(x::Float128)
563-
buf = Base.StringVector(64)
564-
pos = writeshortest(buf, 1, x)
565-
return String(resize!(buf, pos - 1))
562+
lng = 64
563+
buf = Array{UInt8}(undef, lng + 1)
564+
lng = @quad_ccall(libquadmath.quadmath_snprintf(buf::Ptr{UInt8}, (lng+1)::Csize_t, "%.35Qg"::Ptr{UInt8}, x::(Cfloat128...))::Cint)
565+
return String(resize!(buf, lng))
566566
end
567+
567568
function show(io::IO, x::Float128)
568-
buf = Base.StringVector(64)
569-
pos = writeshortest(buf, 1, x)
570569
if isfinite(x)
571570
write(io, "Float128(")
572-
write(io, resize!(buf, pos - 1))
571+
write(io, string(x))
573572
write(io, ')')
573+
elseif x==Inf128
574+
write(io, "Inf128")
575+
elseif x==-Inf128
576+
write(io, "-Inf128")
574577
else
575-
write(io, resize!(buf, pos - 1))
576-
write(io, "128")
578+
write(io, "NaN128")
577579
end
578580
return
579581
end

test/runtests.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,15 @@ end
186186
end
187187

188188
@testset "string conversion" begin
189-
for (f, s_expected) in [(3.0, "Float128(3.0)"),
189+
for (f, s_expected) in [(3.0, "Float128(3)"),
190190
(Inf, "Inf128"),
191-
(NaN, "NaN128"),]
191+
(NaN, "NaN128"),
192+
(1e300, "Float128(1.0000000000000000525047602552044202e+300)"),]
192193
iob = IOBuffer()
193194
show(iob, Float128(f))
194195
s = String(take!(iob))
195196
@test s == s_expected
196-
@test string(Float128(f)) == string(f)
197+
@test isequal(parse(Float128, string(Float128(f))), Float128(f))
197198
end
198199
@test parse(Float128,"3.0") == Float128(3.0)
199200
end

0 commit comments

Comments
 (0)