SciNim / Unchained

A fully type safe, compile time only units library.
https://scinim.github.io/Unchained
109 stars 0 forks source link

Division of (some?) units is broken #16

Closed Vindaar closed 2 years ago

Vindaar commented 3 years ago

Take the following code:

proc xrayEnergyToFreq(E: keV): s⁻¹ =
  ## converts the input energy in keV to a correct frequency
  result = E.to(Joule) / hp
echo 1.keV.xrayEnergyToFreq

it gives a CT error, because the resulting unit it computes is KiloGram²•Meter⁴•Second⁻³ instead of Second⁻¹.

The issue is that we are inverting both the power of the units as well as its base units for compounds. But the base units can never be inverted! That implies that the meaning of the compound unit was just changed.

The fix is easy. Just remove the inversion of the base powers in invert.

Vindaar commented 2 years ago

Closed in #17.