Skip to content

Affine and Cross-System Conversions

Latest

Choose a tag to compare

@paulkorir paulkorir released this 14 May 05:02
· 2 commits to master since this release

v0.5.0 - Affine and Cross-System Conversions

0.5.0 adds affine and cross-system conversions while preserving the package’s strict explicit-conversion model. Conversions now cover offset-based temperature scales, common imperial and US customary units, familiar composite target-unit rendering, and pico-prefixed SI units.

Added

  • Affine conversion metadata on unit definitions.
  • Explicit Celsius, Fahrenheit, and Kelvin conversions through:
    • Quantity.to(...)
    • convert(...)
  • New units.imperial namespace with:
    • length: inch, foot, yard, mile
    • mass: ounce, pound
    • temperature: fahrenheit
  • Display metadata for anonymous composite target units, so explicit conversions can render requested units such as km·h^-1.
  • Pico-prefixed SI units:
    • picometre
    • picogram
    • picosecond

Changed

  • degree_celcius now converts explicitly to and from kelvin.
  • Affine units are rejected from multiplicative arithmetic where offsets would make the result ambiguous.
  • Float noise is cleaned up during rendering without changing stored numeric values.
  • Package version bumped to 0.5.0.

Examples

from units import convert
from units.imperial import fahrenheit, mile
from units.si import degree_celcius, hour, kelvin, kilometre

print(convert(0 * degree_celcius, kelvin))       # 273.15 K
print(convert(32 * fahrenheit, degree_celcius))  # 0 °C

speed = 60 * mile / hour
print(convert(speed, kilometre / hour))          # 96.56064 km·h^-1