Units - lgwagner/SpeAR GitHub Wiki

The Units section is where measurable units, such as distance (meters), time (seconds), mass (kilograms), velocity (meters per second), and such can be defined. Units can be of two types: basic units (meters) which cannot be decomposed any further, and derived units (meters per second) which are a mathematical combination of existing units.

Both basic and derived units provides a capability to provide a textual description for the unit. This description is not used in analyses, but is provided as a convenient way to document the purpose of the unit for the user.

Example

This example shows how one can define basic units, such as meters or seconds, and then define units derived from those, such as meters per second. It also shows how the units are attached to types so that variables can be associated with a particular unit. Finally, it demonstrates how units can also be attached to literal values, such as 9.8 as shown in the example.

Usage

After a unit is defined and attached to a named type (such as time, distance, or velocity in the example) it can be used by typing variables using the named type with the attached units. Similarly, literal values (9.8 in the accompanying example) can also have units attached. Once units are expressed for a variable or literal expression, units analysis is performed as part of type-checking the specification. Mathematics between two variables of different units is accepted if the resulting unit from the arithmetic results in the correct unit for the assigned type. As illustrated in the accompanying example, the tool will identify units mismatches to the user as errors which allows users to efficiently identify and fix errors.

⚠️ **GitHub.com Fallback** ⚠️