≈ the.bay.news

Public, allocation-free way to write a `Float64` as `print` does?

Julia Programming Language
Public, allocation-free way to write a `Float64` as `print` does?
I’m writing large XML files (XLSX.jl’s streaming writer) and need to write millions of Float64s into an IO or a byte buffer. The text has to be what print gives: the shortest decimal that reads back as the same value, e.g. 0.1 rather than 0.10000000000000001. print(io, x) produces the right text, but it allocates on every call: julia> io = IOBuffer(); f(io, xs) = foreach(x -> print(io, x), xs); julia> xs = rand(10^5); f(io, xs); take!(io); julia> @allocated(f(io, xs)) / length(xs) # bytes ...

0 comments

Sign in to join the discussion — your thebay.events account works here.

No comments yet.