[David Mertz]
Because the module implements http://speleotrove.com/decimal/decarith.html <http://speleotrove.com/decimal/decarith.html>
[Greg Ewing]
Well, yes, but someone made the decision to implement that particular standard rather than one of the ones with fixed precision. I'm asking why *that* decision was made.
Because Cowlishaw's spec isn't the only one in play. Essentially all of it was folded into a later revision of IEEE-754, which was generalized to specify base 10 floating point too. 754 utterly took over the world. Nobody wanted to bet against its successors. My own FixedPoint.py was adopted (& extended by others in various ways) by people who actually wanted fixed point in Python, but it remained a niche audience. Cowlishaw's spec _intended_ to subsume fixed point applications too, but I think he oversells the extent to which it succeeds at that. Yup, it can be done - but you're _forever_ doing manual rounding steps to maintain the illusion that you're actually using a fixed point system. Nevertheless, that's straightforward enough. Just tedious. And another reason: the idea that Python "supports 754" (even the original binary version) is just plain false. Not even close. 754 defines an elaborate numeric _enivonment_,(not just the results of arithmetic), and Python supports almost none of that. Supporting the elaborate signals and flags it requires is nearly impossible, because the C subsystems CPython builds on supply no portable ways to do so. But the `decimal` module intends to be a faithful implementation of _everything_ the relevant standards require. The behaviors of its signals and flags adhere to the standards, and regardless of platform. Which is feasible, because its implementation relies on its own code - not on HW primitives or platform C extensions - to handle all of that. A 754-conforming environment isn't really aimed at end users so much as at developers of mathematical libraries. All those "fiddly bits" can enormously simplify the lives of library developers, who know exactly what they're doing, and rejoice in having an environment that actively helps them instead of fighting them every bit of the way ("not defined", "no way to check that short of picking apart the platform-dependent bit representation", "na, the compiler has a different idea of which precision to use here - and _which_ idea may depend on how various compilation flags interact", "you asked for a trap on overflow? OK, but we may not raise it until billions of operations after an overflow occurs", "subnormal? na, we didn't bother implementing those", ad nauseum). The wholly conforming `decimal` environment can be a real joy to work in.