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
- Every function handles: int/float, UnitFloat, UnitArray, ProbUnitFloat, ProbUnitArray.
- Trig functions validate that UnitFloat / UnitArray carry an angle unit.
- log / log10 / exp produce dimensionless results.
- sqrt preserves unit exponents (e.g. sqrt(m^2) → m).
- Unknown types raise TypeError with a clear message.
round_ ¶
quantia-aware round — preserves unit. Named round_ to avoid shadowing builtin.