[Python-Dev] Re: PEP239 (Rational Numbers) Reference Implementation and new issues

Tim Peters tim.one@comcast.net
Mon, 07 Oct 2002 22:51:55 -0400


Noting that Scheme has two sets of optional numeric literal prefixes:

    #b #o #d #h  number is binary, octal, decimal (the default), or hex
    #e #i        number is exact or inexact

This avoids conflating exactness with representation, and, e.g.,

    #e#b1.001

is exactly 9/8 (although that Dr. Scheme allows a radix point in a binary
literal appears to be an extension of the Scheme std).  By default, a
numeric literal is inexect iff it contains a radix point or an exponent, but
#e or #i can override that.

> (exact? 2)
#t
> (exact? #i2)
#f


> (exact? 6.02e23)
#f
> (exact? #e6.02e23)
#t

I think this works very well.  The same rule about default exactness would
be appropriate for Python too, and an r suffix meaning what a #e prefix
means in Scheme would be a fine idea by my lights (the effect of an #i
prefix can be gotten via including a decimal point for decimal literals, and
inexact literals in other bases are rarely useful).