3 ms·
It doesn't have to lose performance; it's just the default representation. For instance, if you have a + 0.1 where a is of binary floating point type, the
by kazinator 11y ago
It doesn't have to lose performance; it's just the default representation. For instance, if you have
a + 0.1
where a is of binary floating point type, the 0.1 constant could denote an exact number. Because of the addition with a float, it gets coerced to the float's type. But that can be done at compile time. So effectively 0.1 is like a binary floating point constant in that situation.
But in another situation it remains exact, such as:
0.1 + 0.2
this gets folded by the compiler at compile time, and uses exact math producing an exact 0.3.
Exactness is just the default.
If your language has rationals expressed as digs/digs, you can imagine that those are used in their place:
a + 1/10;
1/10 + 2/10;
In other words, suppose that 0.1 is just another "spelling" for 1/10.
This will be no less performant than using integer constants in floating contexts, e.g:
double x;
// ...
x += 1; // not slower than x += 1.0!
- dnautics 11y agoHere's a question: How do you code an arbitrary-precision-result (i.e. not an interpolated pade approximant) BCD log10 function? The algorithm in binary is simple, because of special properties of two. It is harder for base-p, and base-composite, is very tough.