Quadmath.jl icon indicating copy to clipboard operation
Quadmath.jl copied to clipboard

Display of Float128 values

Open nhabedi opened this issue 2 years ago • 2 comments
trafficstars

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?

nhabedi avatar Aug 13 '23 11:08 nhabedi

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.

RalphAS avatar Aug 14 '23 02:08 RalphAS

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.

nhabedi avatar Aug 14 '23 10:08 nhabedi