There is a standard for hex flaot literals: 0x1.13A173Ep26 instead of e you use p to separate the exponent and the exponent is in base 10mrvn wrote:It's actually quite trivial to implement. All it takes is to tell the compiler to use strict ieee floating point math and the right format string when printing them. The downside is that strict float behaviour disables a bunch of optimizations and has to constantly fix the x86s extra precision. So you would loose ups. On the plus side though you would gain cross architecture compatibility. E.g. if fatorio ever is ported to arm or powerpc or such then that becomes essential.golfmiketango wrote:Is there? I don't know if factorio really uses bare C++ floating point types (and kinda doubt it), but either way, I'm sure it's easy to come close, but hard to truly nail this. And presumably, factorio needs (or at least wants) to really nail this, to avoid desyncs.mrvn wrote:Also there is a standard for floating point numbers that dictate strict rounding rules and allow you to convert to decimal and back without any loss of precision. You just have to do it right and not simply cut of floats after 5 digits.
Cross-platform architecture-variant-independent round-trippable floating-point pretty-printing is hard AF to implement perfectly. Not saying it's an insurmountable problem, just wonder if maybe you're not quite aware of what a profound clusterfuck floats are in x86. I could easily see it taking a competent-man-month, or something in that ballpark (0.999999999999999999999999999999997 x 10⁰ competent-man-months? ), and a non-negligible hardware budget, to nail down 100% perfectly.
That stated, some liberally-licensed prior art surely exists, somewhere, from which the really tricky bits could be stolen.
Personally where I needed to save/load floats in my microkernel for an RaspberryPI (no ieee conform printf()/scanf() for floats) I've decided to print them out in hexadezimal notation. That way you can print the exact bit pattern of the mantisse without the base 10 throwing in rounding errors. Neatly avoids the whole issue. E.g. 0x13a173E+1a. Saddly there is no standard for that.
Version 0.16.32
-
- Filter Inserter
- Posts: 952
- Joined: Sat May 23, 2015 12:10 pm
- Contact:
Re: Version 0.16.32
Re: Version 0.16.32
I stand corrected. It's actually supported in GNU printf. How did I miss that.ratchetfreak wrote:There is a standard for hex flaot literals: 0x1.13A173Ep26 instead of e you use p to separate the exponent and the exponent is in base 10mrvn wrote: Personally where I needed to save/load floats in my microkernel for an RaspberryPI (no ieee conform printf()/scanf() for floats) I've decided to print them out in hexadezimal notation. That way you can print the exact bit pattern of the mantisse without the base 10 throwing in rounding errors. Neatly avoids the whole issue. E.g. 0x13a173E+1a. Saddly there is no standard for that.
Code: Select all
% printf "%f %s\n" "0x1.13A173Ep26" "0x1.13A173Ep26"
72254927.500000 0x1.13A173Ep26