9. Numeric and Mathematical Modules¶
The modules described in this chapter provide numeric and math-related functions
and data types. The numbers
module defines an abstract hierarchy of
numeric types. The math
and cmath
modules contain various
mathematical functions for floating-point and complex numbers. For users more
interested in decimal accuracy than in speed, the decimal
module supports
exact representations of decimal numbers.
The following modules are documented in this chapter:
- 9.1.
numbers
— Numeric abstract base classes - 9.2.
math
— Mathematical functions - 9.3.
cmath
— Mathematical functions for complex numbers - 9.4.
decimal
— Decimal fixed point and floating point arithmetic- 9.4.1. Quick-start Tutorial
- 9.4.2. Decimal objects
Decimal
Decimal.adjusted()
Decimal.as_tuple()
Decimal.canonical()
Decimal.compare()
Decimal.compare_signal()
Decimal.compare_total()
Decimal.compare_total_mag()
Decimal.conjugate()
Decimal.copy_abs()
Decimal.copy_negate()
Decimal.copy_sign()
Decimal.exp()
Decimal.from_float()
Decimal.fma()
Decimal.is_canonical()
Decimal.is_finite()
Decimal.is_infinite()
Decimal.is_nan()
Decimal.is_normal()
Decimal.is_qnan()
Decimal.is_signed()
Decimal.is_snan()
Decimal.is_subnormal()
Decimal.is_zero()
Decimal.ln()
Decimal.log10()
Decimal.logb()
Decimal.logical_and()
Decimal.logical_invert()
Decimal.logical_or()
Decimal.logical_xor()
Decimal.max()
Decimal.max_mag()
Decimal.min()
Decimal.min_mag()
Decimal.next_minus()
Decimal.next_plus()
Decimal.next_toward()
Decimal.normalize()
Decimal.number_class()
Decimal.quantize()
Decimal.radix()
Decimal.remainder_near()
Decimal.rotate()
Decimal.same_quantum()
Decimal.scaleb()
Decimal.shift()
Decimal.sqrt()
Decimal.to_eng_string()
Decimal.to_integral()
Decimal.to_integral_exact()
Decimal.to_integral_value()
- 9.4.2.1. Logical operands
- 9.4.3. Context objects
getcontext()
setcontext()
localcontext()
BasicContext
ExtendedContext
DefaultContext
Context
Context.clear_flags()
Context.copy()
Context.copy_decimal()
Context.create_decimal()
Context.create_decimal_from_float()
Context.Etiny()
Context.Etop()
Context.abs()
Context.add()
Context.canonical()
Context.compare()
Context.compare_signal()
Context.compare_total()
Context.compare_total_mag()
Context.copy_abs()
Context.copy_negate()
Context.copy_sign()
Context.divide()
Context.divide_int()
Context.divmod()
Context.exp()
Context.fma()
Context.is_canonical()
Context.is_finite()
Context.is_infinite()
Context.is_nan()
Context.is_normal()
Context.is_qnan()
Context.is_signed()
Context.is_snan()
Context.is_subnormal()
Context.is_zero()
Context.ln()
Context.log10()
Context.logb()
Context.logical_and()
Context.logical_invert()
Context.logical_or()
Context.logical_xor()
Context.max()
Context.max_mag()
Context.min()
Context.min_mag()
Context.minus()
Context.multiply()
Context.next_minus()
Context.next_plus()
Context.next_toward()
Context.normalize()
Context.number_class()
Context.plus()
Context.power()
Context.quantize()
Context.radix()
Context.remainder()
Context.remainder_near()
Context.rotate()
Context.same_quantum()
Context.scaleb()
Context.shift()
Context.sqrt()
Context.subtract()
Context.to_eng_string()
Context.to_integral_exact()
Context.to_sci_string()
- 9.4.4. Signals
- 9.4.5. Floating Point Notes
- 9.4.6. Working with threads
- 9.4.7. Recipes
- 9.4.8. Decimal FAQ
- 9.5.
fractions
— Rational numbers - 9.6.
random
— Generate pseudo-random numbersseed()
getstate()
setstate()
jumpahead()
getrandbits()
randrange()
randint()
choice()
shuffle()
sample()
random()
uniform()
triangular()
betavariate()
expovariate()
gammavariate()
gauss()
lognormvariate()
normalvariate()
vonmisesvariate()
paretovariate()
weibullvariate()
WichmannHill
whseed()
SystemRandom
- 9.7.
itertools
— Functions creating iterators for efficient looping - 9.8.
functools
— Higher-order functions and operations on callable objects - 9.9.
operator
— Standard operators as functionslt()
le()
eq()
ne()
ge()
gt()
__lt__()
__le__()
__eq__()
__ne__()
__ge__()
__gt__()
not_()
__not__()
truth()
is_()
is_not()
abs()
__abs__()
add()
__add__()
and_()
__and__()
div()
__div__()
floordiv()
__floordiv__()
index()
__index__()
inv()
invert()
__inv__()
__invert__()
lshift()
__lshift__()
mod()
__mod__()
mul()
__mul__()
neg()
__neg__()
or_()
__or__()
pos()
__pos__()
pow()
__pow__()
rshift()
__rshift__()
sub()
__sub__()
truediv()
__truediv__()
xor()
__xor__()
concat()
__concat__()
contains()
__contains__()
countOf()
delitem()
__delitem__()
delslice()
__delslice__()
getitem()
__getitem__()
getslice()
__getslice__()
indexOf()
repeat()
__repeat__()
sequenceIncludes()
setitem()
__setitem__()
setslice()
__setslice__()
iadd()
__iadd__()
iand()
__iand__()
iconcat()
__iconcat__()
idiv()
__idiv__()
ifloordiv()
__ifloordiv__()
ilshift()
__ilshift__()
imod()
__imod__()
imul()
__imul__()
ior()
__ior__()
ipow()
__ipow__()
irepeat()
__irepeat__()
irshift()
__irshift__()
isub()
__isub__()
itruediv()
__itruediv__()
ixor()
__ixor__()
isCallable()
isMappingType()
isNumberType()
isSequenceType()
attrgetter()
itemgetter()
methodcaller()
- 9.9.1. Mapping Operators to Functions