Math.Units


Math.Units Namespace

Contents

Interval

Modules Description

Interval

These functions let you do math with Interval values, following the rules of interval arithmetic.

Module: Unit System

Modules Description

Acceleration

An Acceleration represents an acceleration in meters per second squared, feet per second squared or gees. It is stored as a number of meters per second squared.

Angle

An Angle represents an angle in degrees, radians, or turns. It is stored as a number of radians.

AngularAcceleration

An AngularAcceleration represents an angular acceleration in radians per second squared, degrees per second squared, and turns per second squared. It is stored as a number of radians per second squared.

AngularSpeed

An AngularSpeed represents a rotation rate in radians per second, degrees per second, turns (revolutions) per second or turns (revolutions) per minute. It is stored as a number of radians per second.

Area

An Area represents an area in square meters, square feet, acres, hectares etc. It is stored as a number of square meters. Note that you can construct an Area value directly using the functions in this module, but it also works to call Quantity.squared on a Length or Quantity.times on a pair of Lengths.

Capacitance

A Capacitance value represents an electrical capacitance in farads. Note that since Capacitance is defined as Rate<Coulombs, Volts> (charge per voltage) .

Charge

A Charge value represents an electrical charge in coulombs or ampere hours. It is stored as a number of coulombs.

Current

A Current value represents an electrical current in amperes.

Density

A Density value represents a density in grams per cubic centimeter, pounds per cubic inch, etc. It is stored as a number of kilograms per cubic meter.

Duration

A Duration refers to an elapsed time in seconds, milliseconds, hours etc., as opposed to a specific instant in time (which would generally be represented by a DateTime. value). It is stored as a number of seconds.

Energy

An Energy value represents an amount of energy (or work) in joules, kilowatt hours etc. It is stored as a number of joules.

Force

A Force value represents a force in newtons, pounds force etc. It is stored as a number of newtons.

Illuminance

Illuminance is a measure of how much light is striking a surface: luminous flux per unit area. It is measured in lux

Inductance

An Inductance value represents an electrical inductance in henries.

Length

A Length represents a length in meters, feet, centimeters, miles etc. It is stored as a number of meters.

Luminance

Luminance is luminous intensity per unit area or equivalently Illuminance per SolidAngle, and is measured in nits (or, to use standard SI terminology, candelas per square meter - the two terms are equivalent).

LuminousFlux

A LuminousFlux value represents the total amount of light emitted by a light source. You can think of it as roughly "photons per second", although it's a bit more complicated than that. Luminous flux is stored in lumens. It's often used to describe the total output of a light bulb; for example, a 50 watt incandescent bulb and a 6 watt LED bulb might each have an output of 400 lumens.

LuminousIntensity

Luminous intensity is a measure of the amount of light produced luminous flux per unit solid angle. Consider a light bulb that emits light in all directions and a spotlight that only emits light in a cone. If both lights had the same luminous flux (same total amount of light produced), then the spotlight would have higher luminous intensity since its light is concentrated into a smaller solid angle (and the light from the spotlight would appear brighter if viewed from the same distance).

On the other hand, if both lights had the same luminous intensity, then they would appear equally bright when viewed from the same distance (something lit by the spotlight would appear equally bright as the same object lit by the light bulb) but the spotlight would have lower luminous flux since its light covers a smaller solid angle.

Luminous intensity is measured in candelas.

Mass

A Mass represents a mass in kilograms, pounds, metric or imperial tons etc. It is stored as a number of kilograms.

Molarity

A Molarity value represents a concentration of substance in moles per cubic meter, moles per liter, millimoles per liter etc. It is stored as a number of moles per cubic meter.

Pixels

Although most of the focus of Math.Units is on physical/scientific units, it's often useful to be able to safely convert back and forth between (for example) Length values in the real world and on-screen lengths in pixels.

This module provides a standard Pixels units type and basic functions for constructing/converting values of type Quantity Int Pixels or Quantity Float Pixels, which allows you to do things like represent conversions between real-world and on-screen lengths as rates of change. This in turn means that all the normal Quantity functions can be used to convert between pixels and other units, or even do type-safe math directly on pixel values.

Power

A Power value represents power in watts or horsepower. It is stored as a number of watts.

Pressure

A Pressure value represents a pressure in kilopascals, pounds per square inch, atmospheres etc. It is stored as a number of pascals.

Quantity

Resistance

A Resistance value represents an electrical resistance in ohms.

SolidAngle

Solid angle is a tricky concept to explain, but roughly speaking solid angle is for 3D what angle is for 2D. It can be used to measure three-dimensional field of view and is stored in steradians. 2D angle can be thought of as how much circumference of the unit circle is covered. The unit circle (circle of radius 1) has a circumference of 2π, and an angle in radians corresponds to the corresponding amount of circumference covered. So an angle of 2π radians covers the entire circumference of the circle, π radians covers half the circle, π/2 radians covers a quarter, etc. Similarly, 3D solid angle can be thought of as how much surface area of the unit sphere is covered. The unit sphere has surface area of 4π, and a solid angle in steradians corresponds to the corresponding amount of surface area covered. So a solid angle of 4π steradians covers the entire sphere, 2π steradians covers half the sphere (one hemisphere), etc.

Speed

A Speed value represents a speed in meters per second, miles per hour etc. It is stored as a number of meters per second.

SubstanceAmount

A SubstanceAmount value represents a substance amount in moles.

Temperature

Unlike other modules in Math.Units, this module contains two different primary types:

  • Temperature, which is not actually a Quantity since temperatures don't really act like normal quantities. For example, it doesn't make sense to add two temperatures or find the ratio between them.
  • TemperatureDelta, which represents the difference between two temperatures. A TemperatureDeltais a Quantity since it does make sense to add two deltas to get a net delta, find the ratio between two deltas (one rise in temperature might be twice as much as another rise in temperature), etc.

Voltage

A Voltage value represents a voltage (electric potential difference, if we're being picky) in volts.

Volume

A Volume represents a volume in cubic meters, cubic feet, liters, US liquid gallons, imperial fluid ounces etc. It is stored as a number of cubic meters.

Other

Type/Module Description

Constants

All conversion factors sourced from National Institute of Standards and Technology unless otherwise specified.

Float (Module)

Float (Type)

A static class providing added features to the floating point number class.

Unit

Type Description

Amperes

Candelas

Candelas are a measure of LuminousIntensity measured in Lumens per Steradians.

CelsiusDegrees

Coulombs

CubicMeters

Farads

Henries

Joules

Kilograms

KilogramsPerCubicMeter

Lumens

Lux

Meters

MetersPerSecond

MetersPerSecondSquared

Moles

MolesPerCubicMeter

Newtons

Nits

Ohms

Pascals

Percentage

Pixel

PixelsPerSecond

PixelsPerSecondSquared

Radians

RadiansPerSecond

RadiansPerSecondSquared

Seconds

SquareMeters

SquarePixels

Steradians

Unitless

A special units type representing 'no units'. A Quantity Unitless value is interchangeable with a simple float. A generic number that doesn't undergo any type mutation.

Volts

Watts

Unit Relation

Type Description

Cubed<'Units>

Represents a units type that is the cube of some other units type; for example, Meters is one units type (the units type of a Length) and Cubed Meters is another (the units type of an Volume). See the Quantity.cubed and Quantity.cbrt functions for examples of use. This is a special case of the Product units type.

Interval<'Units>

A finite, closed interval with a minimum and maximum number. This can represent an interval of any type. For example...


     Interval float
     Interval int
     Interval Angle

Product<'Unit1, 'Unit2>

Represents a units type that is the product of two other units types. This is a more general form of Squared or Cubed. See Quantity.product, Quantity.times, Quantity.over and Quantity.over_ for how it can be used.

Rate<'DependentUnits, 'IndependentUnits>

Represents the units type of a rate or quotient such as a speed (Rate Meters Seconds) or a pressure (Rate Newtons SquareMeters).

Squared<'Units>

Represents a units type that is the square of some other units type; for example, Meters is one units type (the units type of a Length) and Squared Meters is another (the units type of an Area). See the squared and [sqrt](#sqrt) sqrt functions for examples of use. This is a special case of the Product units type.

Unit System

Type Description

Acceleration

Angle

AngularAcceleration

AngularSpeed

Area

Capacitance

Charge

Current

Density

Duration

Energy

Force

Illuminance

Inductance

Length

Luminance

LuminousFlux

LuminousIntensity

Mass

Molarity

Percent

A percentage value. The default range for percentages is 0 to 1 but can also be given in the range 0 to 100.

Pixels

Power

Pressure

Quantity<'Units>

A Quantity is effectively a number (an Int or Float) tagged with a units type. So a Quantity Float Meters is a Float number of Meters and a Quantity Int Pixels is an Int number of Pixels. When compiling with elm make --optimize the Quantity wrapper type will be compiled away, so the runtime performance should be comparable to using a raw Float or Int.

Resistance

SolidAngle

Speed

SubstanceAmount

Temperature

TemperatureDelta

Voltage

Volume