[Python-checkins] CVS: python/nondist/peps pep-0239.txt,NONE,1.1

Barry Warsaw bwarsaw@users.sourceforge.net
2001年3月15日 20:24:19 -0800


Update of /cvsroot/python/python/nondist/peps
In directory usw-pr-cvs1:/tmp/cvs-serv3322
Added Files:
	pep-0239.txt 
Log Message:
PEP 239, Adding a Rational Type to Python, Moshe Zadka
[checking in for Moshe, after editorial, spell check, and formatting
passes by Barry]
--- NEW FILE: pep-0239.txt ---
PEP: 239
Title: Adding a Rational Type to Python
Version: $Revision: 1.1 $
Author: pep@zadka.site.co.il (Moshe Zadka)
Status: Draft
Type: Standards Track
Created: 11-Mar-2001
Python-Version: 2.2
Post-History:
Abstract
 Python has no numeric type with the semantics of an unboundedly
 precise rational number. This proposal explains the semantics of
 such a type, and suggests builtin functions and literals to
 support such a type. This PEP suggests no literals for rational
 numbers; that is left for another PEP[1].
Rationale
 While sometimes slower and more memory intensive (in general,
 unboundedly so) rational arithmetic captures more closely the
 mathematical ideal of numbers, and tends to have behavior which is
 less surprising to newbies. Though many Python implementations of
 rational numbers have been written, none of these exist in the
 core, or are documented in any way. This has made them much less
 accessible to people who are less Python-savvy.
RationalType
 There will be a new numeric type added called RationalType. Its
 unary operators will do the obvious thing. Binary operators will
 coerce integers and long integers to rationals, and rationals to
 floats and complexes.
 The following attributes will be supported: .numerator and
 .denominator. The language definition will not define these other
 then that:
 r.denominator * r == r.numerator
 In particular, no guarantees are made regarding the GCD or the
 sign of the denominator, even though in the proposed
 implementation, the GCD is always 1 and the denominator is always
 positive.
 The method r.trim(max_denominator) will return the closest
 rational s to r such that abs(s.denominator) <= max_denominator.
The rational() Builtin
 This function will have the signature rational(n, d=1). n and d
 must both be integers, long integers or rationals. A guarantee is
 made that
 rational(n, d) * d == n
References
 [1] PEP 240, Adding a Rational Literal to Python, Zadka,
 http://python.sourceforge.net/peps/pep-0240.html
Copyright
 This document has been placed in the public domain.

Local Variables:
mode: indented-text
indent-tabs-mode: nil
End:

AltStyle によって変換されたページ (->オリジナル) /