A description of how to convert between units using a linear equation.

SDKs

- iOS 10.0+
- macOS 10.12+
- tvOS 10.0+
- watchOS 3.0+

Framework

- Foundation

## Overview

A linear equation for unit conversion takes the form `y = mx + b`

, such that:

**y**is the value in terms of the base unit of the dimension**m**is the known coefficient used for this unit's conversion**x**is the value in terms of the unit on which this method is called**b**is the known constant used for this unit's conversion

The `base`

method performs the conversion in the form of `y = mx + b`

, where `x`

represents the value passed in and `y`

represents the value returned. The `value`

method performs the inverse conversion in the form of `x = (y - b) / m`

, where `y`

represents the value passed in and `x`

represents the value returned.

For example, consider the `fahrenheit`

unit defined by `Unit`

: The `base`

method calculates the value in the base unit, `kelvin`

using the formula `K = (0`

, and the `value`

method calculates the value in `fahrenheit`

using the formula `°F = (K — 255`

, where the `coefficient`

is `(0`

and the `constant`

is `255`

.

Units that perform conversion using only a scale factor have a `coefficient`

equal to the scale factor and a `constant`

equal `0`

. For example, consider the `kilometers`

unit defined by `Unit`

: The `base`

method calculates the value in meters using the formula `value`

, and the `value`

calculates the value in kilometers using the formula `value`

, where the coefficient is `1000`

and the constant is `0`

.