Re: Decimal type question [Prothon] (was: Re: Re: Decimal type question [Prothon])
Mark Hahn <[email protected]> Mon, 9 Aug 2004 14:05:19 -0700
| Newsgroups | gmane.comp.lang.prothon.user,gmane.comp.python.devel |
|---|---|
| Organization | Hahn Creative Applications |
| Message-ID | <[email protected]> |
On Mon, 9 Aug 2004 12:46:41 -0700, Andrew P. Lentvorski, Jr. wrote: >> On Mon, 9 Aug 2004 14:20:15 -0400, Tim Peters wrote: >>> >>> It depends on your goals for Prothon, and also on the relative >>> performance of the various numeric implementations. Semantically, it >>> would be nicest if Python used the IBM decimal type for everything by >>> default (whether spelled 123, 123.0, or 123e0). >> >> Are you sure you mean that? I have been assuming that there is a >> fundamental need for an integer type that has no fraction. > > Sure, but both binary floating point and Decimal happily inhabit > that space. The issue in Days Gone By(tm) was the fact that > a single precision float tended to be the default type and > only had about 24 bits of precision (somewhere around 8-9 > decimal digits). Consequently, people would often get surprised > when accumulating small integers ceased to work around 10^8 or 10^9. > > With binary FP doubles, this is less of an issue as it has about 54 bits > of precision (about 18 decimal digits or so). However, it still places > an artificial restriction on maximum precision. > > Besides, the only reason programmers write loops as integers is > because accumulating floats "doesn't work". With Decimal, that > is no longer the case. I already have Prothon switching automatically from a basic fixed-sized integer to a bigint internally on overflow. I guess I could have a single numeric type and convert between fixed integers, bigints, and decimals automatically internally when there is no loss of precision. It would steal the Python implementation of bigint and decimal. I would still need to have a separate binary floating point type that the programmer would manually specify when he knows he wants the performance of the hardware and is willing to live with the binary limitations. How about a basic built-in numeric default type called Decimal with all the default numeric constant formats (123, 123.0, & 123e0) and a separate binary double hardware type called Float with the constant format of 0f0, 1f0, -1.3f-34, etc. where the letter "f" replaces the letter "e"?