4 ms·
> When in doubt, stick a (double) in front of it If casting from an integer type, this loses precision. Why would this make tests pass? Are there any secondary
by spacehunt 10y ago
> When in doubt, stick a (double) in front of it
If casting from an integer type, this loses precision. Why would this make tests pass? Are there any secondary effects? The author apparently made no effort to find out.
- dllthomas 10y agoThis may lose precision. Depending on architecture & compiler & flags, your mantissa may be big enough to hold your whole int. An 80 bit extended double has 64 bits of significand. https://en.wikipedia.org/wiki/Extended_precision#x86_extended_precision_format https://en.wikipedia.org/wiki/Extended_precision#x86_extende...
- AstralStorm 10y agoThis will lose precision, as any floating point operation is only accurate to 1 unit in the last place (ULP). Even simple addition.
- deleted 10y ago[deleted]
- parenthephobia 10y agoThis conversion will not lose precision! With a 64-bit mantissa, ULP(x) is ≤ 1 for x in [-2e64, 2e64]. If you have the time you can count up to 2^64 by repeatedly incrementing a float80(0.0) by 1. Addition, subtraction and multiplication on float80s are perfectly stable provided the results stays within [-2e64, 2e64].
- AstralStorm 10y agoThere is no guarantee on stability of those ops. Intel and IEEE guarantees 1 ULP. Even if you use the 80 bit type. The error is not guaranteed to not be additive over multiple operations either. And for multiplication and division? Let's not even go there. This will mess up all kinds of sharp comparisons on the result of casted operations.