Error codes

E0290: mismatched units in an operator

In a terminal: auk explain E0290 prints this page.

On this page

+, -, %, the comparisons, min, max and sort need both sides in the same unit: adding metres to seconds is a bug. * and / combine units instead (m / s is m/s). A plain number has no unit, so it can scale a value (2.0 * d) but not be added to one; a literal 0 or 0.0 fits any unit.

Wrong#

auk
fn total(d: float<m>, t: float<s>): float<m> = d + t

Fixed#

auk
fn total(d: float<m>, t: float<s>, v: float<m/s>): float<m> = d + v * t

Common causes#

  • Adding values in different units (m and km): convert with a factor, x * 1000.0<m/km>.
  • Adding a plain number to a unit value: write the unit on the literal, d + 1.0<m>.
  • Units that differ only by an exponent (m vs m^2): an area was used as a length.

Stuck on a word? Try the glossary. Got a compiler error? Look up its code. Improve this page