Back to index

python3.2  3.2.2
Classes | Functions | Variables
test.test_long Namespace Reference

Classes

class  Frm
class  LongTest

Functions

def truediv
def test_main

Variables

 SHIFT = sys.int_info.bits_per_digit
int BASE = 2
int MASK = 1
int KARATSUBA_CUTOFF = 70
int MAXDIGITS = 15
list special = [0, 1, 2, BASE, BASE >> 1, 0x5555555555555555, 0xaaaaaaaaaaaaaaaa]
int p2 = 4
 DBL_MAX = sys.float_info.max
 DBL_MAX_EXP = sys.float_info.max_exp
 DBL_MIN_EXP = sys.float_info.min_exp
 DBL_MANT_DIG = sys.float_info.mant_dig
int DBL_MIN_OVERFLOW = 2

Function Documentation

Definition at line 1152 of file test_long.py.

01152 
01153 def test_main():
01154     support.run_unittest(LongTest)

def test.test_long.truediv (   a,
  b 
)
Correctly-rounded true division for integers.

Definition at line 47 of file test_long.py.

00047 
00048 def truediv(a, b):
00049     """Correctly-rounded true division for integers."""
00050     negative = a^b < 0
00051     a, b = abs(a), abs(b)
00052 
00053     # exceptions:  division by zero, overflow
00054     if not b:
00055         raise ZeroDivisionError("division by zero")
00056     if a >= DBL_MIN_OVERFLOW * b:
00057         raise OverflowError("int/int too large to represent as a float")
00058 
00059    # find integer d satisfying 2**(d - 1) <= a/b < 2**d
00060     d = a.bit_length() - b.bit_length()
00061     if d >= 0 and a >= 2**d * b or d < 0 and a * 2**-d >= b:
00062         d += 1
00063 
00064     # compute 2**-exp * a / b for suitable exp
00065     exp = max(d, DBL_MIN_EXP) - DBL_MANT_DIG
00066     a, b = a << max(-exp, 0), b << max(exp, 0)
00067     q, r = divmod(a, b)
00068 
00069     # round-half-to-even: fractional part is r/b, which is > 0.5 iff
00070     # 2*r > b, and == 0.5 iff 2*r == b.
00071     if 2*r > b or 2*r == b and q % 2 == 1:
00072         q += 1
00073 
00074     result = math.ldexp(q, exp)
00075     return -result if negative else result
00076 

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 21 of file test_long.py.

test.test_long.DBL_MANT_DIG = sys.float_info.mant_dig

Definition at line 43 of file test_long.py.

Definition at line 40 of file test_long.py.

test.test_long.DBL_MAX_EXP = sys.float_info.max_exp

Definition at line 41 of file test_long.py.

test.test_long.DBL_MIN_EXP = sys.float_info.min_exp

Definition at line 42 of file test_long.py.

Definition at line 44 of file test_long.py.

Definition at line 23 of file test_long.py.

Definition at line 22 of file test_long.py.

Definition at line 27 of file test_long.py.

Definition at line 32 of file test_long.py.

test.test_long.SHIFT = sys.int_info.bits_per_digit

Definition at line 20 of file test_long.py.

list test.test_long.special = [0, 1, 2, BASE, BASE >> 1, 0x5555555555555555, 0xaaaaaaaaaaaaaaaa]

Definition at line 30 of file test_long.py.