JuliaMath / Quadmath.jl

Float128 and libquadmath for the Julia language
Other
40 stars 11 forks source link

Display of Float128 values #66

Open nhabedi opened 1 year ago

nhabedi commented 1 year ago

The following two inputs result in the same number, i.e. x === y:

x = parse(Float128,"1e-33")
y = parse(Float128,"1.00000000000000000000000000000000005e-33")

But they are displayed as 1.00000000000000000000000000000000005e-33. Shouldn't the policy be to choose the simpler form 1e-33 for display if both are correct?

RalphAS commented 1 year ago

Yes, simpler forms would be preferable. However this is quite difficult in general (I'll refer you to the literature on the Dragon and Grisu algorithms for Float32 and Float64). We currently rely on the formatting provided by libquadmath; its maintainers may be able to say whether improvements are feasible.

nhabedi commented 1 year ago

Yes, I know this is tricky. I noticed this problem because I was testing my own implementation of the Burger/Dybvig algorithm which gives the correct answer in this particular case. It's not a big deal and it's fine with me if you close this issue. If I find enough time I might be tempted to port the algorithm to Julia, but I'm not very good at writing optimized Julia code yet and whatever I come up with will most likely be too slow for production code.