Back to index

python3.2  3.2.2
Classes | Functions | Variables
fractions Namespace Reference

Classes

class  Fraction

Functions

def gcd

Variables

list __all__ = ['Fraction', 'gcd']
 _PyHASH_MODULUS = sys.hash_info.modulus
 _PyHASH_INF = sys.hash_info.inf
tuple _RATIONAL_FORMAT = re.compile(r""" \A\s* # optional whitespace at the start, then (?P<sign>[-+]?) # an optional sign, then (?=\d|\.\d) # lookahead for digit or .digit (?P<num>\d*) # numerator (possibly empty) (?: # followed by (?:/(?P<denom>\d+))? # an optional denominator | # or (?:\.(?P<decimal>\d*))? # an optional fractional part (?:E(?P<exp>[-+]?\d+))? # and optional exponent ) \s*\Z # and optional whitespace to finish""", re.VERBOSE | re.IGNORECASE)

Function Documentation

def fractions.gcd (   a,
  b 
)
Calculate the Greatest Common Divisor of a and b.

Unless b==0, the result will have the same sign as b (so that when
b is divided by it, the result comes out positive).

Definition at line 17 of file fractions.py.

00017 
00018 def gcd(a, b):
00019     """Calculate the Greatest Common Divisor of a and b.
00020 
00021     Unless b==0, the result will have the same sign as b (so that when
00022     b is divided by it, the result comes out positive).
00023     """
00024     while b:
00025         a, b = b, a%b
00026     return a
00027 
00028 # Constants related to the hash implementation;  hash(x) is based
# on the reduction of x modulo the prime _PyHASH_MODULUS.

Variable Documentation

Definition at line 13 of file fractions.py.

fractions._PyHASH_INF = sys.hash_info.inf

Definition at line 32 of file fractions.py.

fractions._PyHASH_MODULUS = sys.hash_info.modulus

Definition at line 29 of file fractions.py.

tuple fractions._RATIONAL_FORMAT = re.compile(r""" \A\s* # optional whitespace at the start, then (?P<sign>[-+]?) # an optional sign, then (?=\d|\.\d) # lookahead for digit or .digit (?P<num>\d*) # numerator (possibly empty) (?: # followed by (?:/(?P<denom>\d+))? # an optional denominator | # or (?:\.(?P<decimal>\d*))? # an optional fractional part (?:E(?P<exp>[-+]?\d+))? # and optional exponent ) \s*\Z # and optional whitespace to finish""", re.VERBOSE | re.IGNORECASE)

Definition at line 34 of file fractions.py.