UnitFloat¶
UnitFloat ¶
An exact scalar value with a physical unit.
Supports unit-safe arithmetic, conversion, and comparison.
Dimensional compatibility is checked automatically on every
operation that combines two UnitFloat instances.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
Numeric value in the given unit. Must not be NaN. |
required |
unit
|
str or CompoundUnit
|
Unit expression string (e.g. |
required |
Raises:
| Type | Description |
|---|---|
UnknownUnitError
|
If |
UnitParseError
|
If |
ValueError
|
If |
Examples:
Basic arithmetic and conversion:
>>> import quantia as qu
>>> d = qu.Q(100.0, 'm')
>>> t = qu.Q(10.0, 's')
>>> v = d / t
>>> v.to('km/h')
UnitFloat(36.0, 'km/h')
Temperature conversion (affine):
Gauge to absolute pressure:
from_dict
classmethod
¶
Reconstruct from a dict produced by to_dict().
si_value ¶
Return the numeric SI value as a plain float.
Equivalent to self.to_si().value. Use this when you need a
dimensionless number for further computation or comparison.
Returns:
| Type | Description |
|---|---|
float
|
Numeric value in SI base units. |
Examples:
to ¶
Convert to a different unit of the same physical quantity.
Handles multiplicative units (m → km) and affine units
(°C → K, psig → psia, psig → Pa).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
str or CompoundUnit
|
Target unit. Must be dimensionally compatible with the current unit. |
required |
Returns:
| Type | Description |
|---|---|
UnitFloat
|
New instance with the value expressed in |
Raises:
| Type | Description |
|---|---|
IncompatibleUnitsError
|
If |
DimensionError
|
If mixing affine and non-affine units of incompatible
quantities (e.g. |
Examples:
to_si ¶
Convert to the SI base unit representation.
For affine units (temperature, gauge pressure) applies the full affine transformation including offset. For multiplicative units applies the scale factor only.
Returns:
| Type | Description |
|---|---|
UnitFloat
|
Value expressed in SI base units (e.g. |
Examples: