Contents    Page-10    Prev    Next    Page+10    Index   

Unit Checking

It is necessary to check that a unit conversion is correct: a length cannot be converted to a mass. Each unit has a corresponding abstract unit, which is a quotient of two products. For example, a force such as newton has an abstract unit:

(/ (* mass length) (* time time) )

If the abstract units for source and goal are divided, and corresponding units in numerator and denominator are cancelled, the result should be 1.

Symbolically, if the terms are collected into a quotient of two lists and the lists are sorted, the two lists should be equal.

For efficiency, the units can be encoded as 32-bit integers that are added and subtracted, giving a result of 0 for a correct conversion.