4 ms·
Avoiding floating point doesn't imply BCD. Any representation for integers would do fine, including binary. There are two reasons for BCD, (1) to avoid the cos
by pflanze 4y ago
Avoiding floating point doesn't imply BCD. Any representation for integers would do fine, including binary.
There are two reasons for BCD, (1) to avoid the cost of division for conversion to human readable representation as implied in the OP, (2) when used to represent floating point, to avoid "odd" representations in the human format resulting from the conversion (like 1/10 not shown as 0.1). (2) implies floating point.
Eben in floating point represented using BCD you'd have rounding errors when doing number calculations, that's independent of the conversion to human readable formats; so I don't see any reason to think that BCD would have avoided any disasters unless humans were involved. BCD or not is all about talking to humans, not to physics.
- coldtea 4y ago>Avoiding floating point doesn't imply BCD Parent didn't say it's a logical necessity, as in "avoid floating point ==> MUST use BCD". Just casually mentioned that one reason BCD got popular to sidestep such issues in floating point. (I'm not saying that's the reason, or that it's the best such option. It might even be historically untrue that this was the reason - just saying the parent's statements can and probably should be read like that).
- pflanze 4y agoSidestep which issue? The one of human representation, or the problems with floating point? If they just want to side step problems with floating point rounding targetting the physical world, they need to go with integers. Choosing BCD to represent those integers makes no sense at all for that purpose. All I sense is a conflation of issues. Also, thinking about it from a different angle, avoiding issues with the physical world is one of properly calculating so that rounding errors become no issues. Choosing integers probably helps with that more in the sense that it is making the programmer aware. Integers are still discrete and you'll have rounding issues. Higher precision can hide risks from rounding errors becoming relevant, which is why f64 is often chosen over f32. Going with an explicit resolution and range will presumably (I'm not a specialist in this area) make issues more upfront. Maybe at the risk of missing some others (like with the Ariane rocket that blew up because of a range overflow on integer numbers -- Edit: that didn't happen on the integer numbers though, but when converting to them). A BCD number representation helps over the binary representation when humans are involved who shouldn't be surprised by the machine having different rounding than what the human is used to from base 10. And maybe historically the cost of conversion. That's all. (Pocket calculators, and finance are the only areas I'm aware of where that matters.) PS. danbruc (https://news.ycombinator.com/item?id=35057850 https://news.ycombinator.com/item?id=35057850) says it better than me.