SciNim / Unchained

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

Unit math with certain compounds #9

Closed Vindaar closed 2 years ago

Vindaar commented 3 years ago

A note on certain compounds like Liter, Acre (the only two compounds that have no UnitKind that is its base type).

Currently our implementation is confused by compound units that are not defined as their own actual unit. So Meter³, which is the base of Liter is not actually considered for auto conversion (only for type checking).

That means math like the following has a weird quirk:

block:
  let x = 1.Liter
  let y = 1.m³
  doAssert type(x + y) is Liter
  doAssert type(y + x) is Meter³

It wouldn't be too bad. The problem is the scale conversions are applied in both cases. So in the first case the actual number does just become 1.001. But it thinks it's liters!

Vindaar commented 2 years ago

This was fixed as part of the declarative unit / quantity rewrite in PR #24.