Skip to main content

math

Mathematical functions defined by the C standard, plus extras (comb, isqrt, prod, dist). All functions take and return float unless documented as int.

Source-of-record: Modules/mathmodule.c, math docs.

Constants

NameValue
pi3.141592653589793.
e2.718281828459045.
tau2*pi.
infPositive infinity.
nanIEEE NaN.

Number-theoretic and representation

FunctionReturns
ceil(x) / floor(x) / trunc(x)int.
fabs(x)float absolute value.
factorial(n)int.
gcd(*ints) / lcm(*ints)int.
copysign(x, y)x with sign of y.
fmod(x, y)C-style fmod.
frexp(x)(m, e) with x = m * 2**e.
ldexp(x, i)x * 2**i.
modf(x)(frac, int) both float.
remainder(x, y)IEEE 754 remainder.
isclose(a, b, *, rel_tol=1e-9, abs_tol=0.0)Relative tolerance check.
isfinite(x) / isinf(x) / isnan(x)Predicates.
nextafter(x, y, steps=1)Next representable float.
ulp(x)Unit in last place.
comb(n, k) / perm(n, k=None)Combinatorial counts (3.8+).
isqrt(n)Integer sqrt.
prod(iterable, *, start=1)Product.
sumprod(p, q)Dot product (3.12+).

Power and logarithm

exp(x), expm1(x), log(x[, base]), log1p(x), log2(x), log10(x), pow(x, y), sqrt(x), cbrt(x).

Trigonometry

sin, cos, tan, asin, acos, atan, atan2(y, x), hypot(*coordinates).

Hyperbolic

sinh, cosh, tanh, asinh, acosh, atanh.

Angular conversion

degrees(x), radians(x).

Special functions

erf(x), erfc(x), gamma(x), lgamma(x), dist(p, q), fsum(iterable) (Neumaier exact sum), floor/ceil round to int.

Gopy status

AreaState
All functions and constantsComplete.
fsum, isqrt, comb, perm, sumprodComplete.
Domain / range errors raise ValueError / OverflowErrorComplete.

Reference

  • CPython 3.14: math.
  • Modules/mathmodule.c.
  • module/math/. gopy port.