qunits logo qunits logo

A performant, verbose and generic physical unit system.

Static Badge Static Badge

© 2026 Patrick Müller. All rights reserved.

qunits.prefix

The qunits.prefix module contains the SI prefixes, the exponent maps of the units and the Context of the units.

Exponent maps

An exponent map (ExpMap) is a frozenset of (symbol, exponent) pairs, e.g. frozenset({("m", 1), ("s", -1)}) for m/s. It identifies a unit and is how the unit is printed. Units are multiplied and divided by merging their exponent maps with merge_exp_maps.

Type aliases:
ExpMapfrozenset[tuple[str, int]]

An exponent map, a frozenset of (symbol, exponent) pairs, e.g. frozenset({("m", 1), ("s", -1)}) for m/s. It identifies a unit and is how the unit is printed.

Contexts

The Context of a unit distinguishes quantities of the same dimension that must not be mixed, e.g. angles from other dimensionless quantities. CONTEXT_DICT maps each context to the symbol of its unit, CONTEXT_DICT_UNIT the other way around.

Prefixes

PREFIX_DICT maps the prefix symbols to their exponents, PREFIX_DICT_EXP the other way around. The prefixes are written in ASCII, micro is u. Only the prefixes for powers of 1000 are defined.

PrefixSymbolFactorPrefixSymbolFactor
quectoq$10^{-30}$kilok$10^{3}$
rontor$10^{-27}$megaM$10^{6}$
yoctoy$10^{-24}$gigaG$10^{9}$
zeptoz$10^{-21}$teraT$10^{12}$
attoa$10^{-18}$petaP$10^{15}$
femtof$10^{-15}$exaE$10^{18}$
picop$10^{-12}$zettaZ$10^{21}$
nanon$10^{-9}$yottaY$10^{24}$
microu$10^{-6}$ronnaR$10^{27}$
millim$10^{-3}$quettaQ$10^{30}$