Proposal to change default float type to decimal

Mark Hahn <[email protected]> Wed, 4 Aug 2004 23:05:47 -0700
Newsgroups gmane.comp.lang.prothon.user
Organization Hahn Creative Applications
Message-ID <[email protected]>
Most of the Python gotcha lists include the funny behavior of normal binary
floating point numbers as a gotcha.  Somthing like "print 1/10.0" giving
0.100000001 is confusing.

I have considered using a floating decimal type as the default type in
order to solve this problem in Prothon, but I didn't because I had no
access to an implementation of a floating decimal package in time for the
1.0 release.  The .net package does offer one as a standard type though.

A decimal type would also make a good money type also.

We would offer three built-in numeric types: integers which automatically
expand to longs (Int), floating decimals (Decimal), and regular floats for
performance which use the floating-point hardware of the CPU (Float).

I propose that we distinguish to two floating type constants as follows.
Anything with just a decimal point or any other Python Float format would
be a Decimal: 1.0, 1.E3, 1.34e-12, etc.  Floats would use the letter f,
which would stand for fast float or just float: 1.0f, 1.F3, 1.34f-12, etc.

Automatic coercion from Ints would default to Decimal.  Complex numbers
would default to tuples of Decimal components (a real Decimal and an
imaginary Decimal).

Comments?  Votes?