3 ms·
Defaulting to a Binary Encoded Decimal is also silly because its not as performant and loses compactness. Fundamentally. (Having a composite base comes with p
by dnautics 11y ago
Defaulting to a Binary Encoded Decimal is also silly because its not as performant and loses compactness. Fundamentally. (Having a composite base comes with problems). What is your suggestion, having a default floating point have a Binary or hexadecimal representation for literals? Let's say I want to input a planet's mass as 6e24 kg - quick what is that in your literals?
- dragonwriter 11y ago> Defaulting to a Binary Encoded Decimal is also silly because its not as performant and loses compactness. Defaulting to correctness makes a lot more sense than often premature time and space optimizations by default. > What is your suggestion, having a default floating point have a Binary or hexadecimal representation for literals? There's lots of good solutions (Scheme's, of having a numeric tower with literals using the minimal-scope exact representation -- e.g., integer if there is no fractional part, decimal if its a decimal literal, rational if it is rational literal not expressed as a decimal -- by default unless they have an modifier specifying intent to use an inexact representation) is the best.
- dnautics 11y agothe point is, there are still unrepresentables (1/3 e.g.) in binary encoded decimal. If it's all about literals, just make the user put the correct literal in, and make them understand that floats are imperfect anyways. If you're doing anything remotely useful with Binary Coded Decimal, probably about two or three operations in, you're going to lose resolution on your exactness. It doesn't buy you much. GIGO.
- kazinator 11y agoIt 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.