proposed language change to int/int==float (was: PEP0238 lament)

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Tue Jul 24 13:50:46 EDT 2001


Tue, 24 Jul 2001 09:44:57 -0600, Bjorn Pettersen <BPettersen at NAREX.com> pisze:

> I think perhaps an equally interesting example is something like:
> 
>   2L**128/2
> 
> which currently gives an exact result, but under the proposed new
> semantics would give an approximation...

That's why I propose rationals.

> If we're going to change basic behaviors it would be better if we
> had a consistent semantic model first.

In my model there are four builtin numeric types: int, rational,
float, and complex. The intent is that floats approximate real numbers.

There are explicit conversions from any to any among int, rational and
float. Conversion of rational and float to int truncates as currently.

+, -, * work for arguments of any two types from these and return
the result in the broader type wrt. the order above.

div, mod, divmod similarly, except that complex arguments are
disallowed.

/ similarly, except that ints are changed to rationals first.

sqrt, sin, cos, exp etc. similarly, except that ints and rationals
are changed to float first.

The behavior of ** depends on the exponent which determines the
narrowest type to which base is converted first. If it's a nonnegative
int, the result has the same type as the base. If it's a negative
int, the base is converted from int to rational. If it's a rational
or float, the base is converted from int or rational to float. If
it's a complex, the base is converted to complex.

-- 
 __("<  Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/
 \__/
  ^^                      SYGNATURA ZASTĘPCZA
QRCZAK



More information about the Python-list mailing list