A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://python.github.io/peps/pep-0239/ below:

PEP 239 – Adding a Rational Type to Python

PEP 239 – Adding a Rational Type to Python
Author:
Christopher A. Craig <python-pep at ccraig.org>, Moshe Zadka <moshez at zadka.site.co.il>
Status:
Rejected
Type:
Standards Track
Created:
11-Mar-2001
Python-Version:
2.2
Post-History:
16-Mar-2001
Table of Contents 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.

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 promise that:

r.denominator * r == r.numerator

that the GCD of the numerator and the denominator is 1 and that the denominator is 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:

Open Issues References Copyright

This document has been placed in the public domain.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4