Core Unit Class#
The Unit class is the foundation for all physical units in Quantium. Each Unit object
stores its name (symbol), its conversion factor to the equivalent base SI unit, and its
physical dimension.
- class quantium.core.quantity.Unit(name: str, scale_to_si: float, dim: Dim)[source]
Represents a physical unit. This class is generally not instantiated directly by users. Instead, users access predefined units from the default registry (see below) or create new units using the registry’s helper methods.
- Parameters:
name – The symbol or name of the unit (e.g., “m”, “kg”, “cm”).
scale_to_si – The multiplicative factor to convert 1 of this unit to its SI equivalent.
dim – The
Dimobject representing the unit’s physical dimension (L, M, T, I, Θ, N, J).
Attributes
- name: str
Symbol or name (e.g., “m”, “s”, “kg”, “cm”).
- scale_to_si: float
Multiplicative factor to convert 1 of this unit to SI for its dimension (e.g., m=1.0, cm=0.01, ft=0.3048).
- dim: quantium.core.dimensions.Dim
Dimension vector (L,M,T,I,Θ,N,J).
Unit Arithmetic
Unitobjects can be combined using arithmetic operators to create new, derived units.- __mul__(other: Unit) Unit[source]
Multiplies two units. (e.g.,
m * mreturnsUnit(name='m^2', ...))
- __truediv__(other: Unit) Unit[source]
Divides two units. (e.g.,
m / sreturnsUnit(name='m/s', ...))
- __rtruediv__(n: int | float) Unit[source]
Calculates the reciprocal of a unit. Only
1 / unitis supported (e.g.,1 / sreturnsUnit(name='s^-1', ...)).
- __pow__(n: int) Unit[source]
Raises a unit to an integer power (e.g.,
m ** 2returnsUnit(name='m^2', ...)).