Skip to content

Math Functions

math

quantia/math.py

Drop-in replacement for the stdlib math module that auto-dispatches on UnitFloat, UnitArray, ProbUnitFloat, and ProbUnitArray.

Usage

import quantia.math as qmath

qmath.log10(x) # works for float, UnitFloat, ProbUnitFloat, UnitArray, ProbUnitArray qmath.exp(x) qmath.sqrt(x) qmath.log(x) qmath.sin(x) # expects angle unit on UnitFloat; plain float treated as radians qmath.cos(x) qmath.tan(x)

Falls through to stdlib math for plain int / float so existing code that does import quantia.math as math keeps working.

Design rules
  1. Every function handles: int/float, UnitFloat, UnitArray, ProbUnitFloat, ProbUnitArray.
  2. Trig functions validate that UnitFloat / UnitArray carry an angle unit.
  3. log / log10 / exp produce dimensionless results.
  4. sqrt preserves unit exponents (e.g. sqrt(m^2) → m).
  5. Unknown types raise TypeError with a clear message.

atan2

atan2(y, x)

quantia-aware atan2. Both args must be compatible units or plain floats.

cbrt

cbrt(x)

Cube root — preserves unit^(1/3).

ceil

ceil(x)

quantia-aware ceil — preserves unit.

fabs

fabs(x)

quantia-aware fabs() — preserves unit.

floor

floor(x)

quantia-aware floor — preserves unit.

pow

pow(base, exp_val)

quantia-aware pow(base, exp).

round_

round_(x, n=None)

quantia-aware round — preserves unit. Named round_ to avoid shadowing builtin.