Module measurement

Measurement ADT for Erlang.

Description

Measurement ADT for Erlang.

This module implements an abstract data type in Erlang which represents a measurement taken from the observed world. These measurements have, as part of their make-up, both a scalar component which determines their magnitude, and a units of measurement (UoM) component which determines their dimensionality (and may further determine their magnitude within that dimensionality.)

Simple arithmetic may be done on measurements, including all the usual operations (addition, subtraction, multiplication, division, and exponentiation,) and during these operations both the scalar component and the UoM component are handled correctly.

This module is by no means complete. Many features must be added to it in order to make this ADT reasonably versatile. These include:

Function Index

add/2Yields the sum of two measurements.
divide/2Yields the ratio between two measurements.
equal/2Determines whether two measurements are equal.
exponent/2Raises a measurement to the power of another measurement.
format/1Render a measurement in human-readable form.
fwrite/2Wrapper for io:fwrite which is sensitive to measurements.
greater_than/2Determines whether the first measurement is greater than the second.
greater_than_or_equal/2Determines whether the first measurement is greater than or equal to the second.
less_than/2Determines whether the first measurement is less than the second.
less_than_or_equal/2Determines whether the first measurement is less than or equal to the second.
multiply/2Yields the product of two measurements.
new/1Creates and returns a new measurement object, either a scalar if a number is given, or a measurement of one unit if a unit is given.
new/2Creates and returns a new measurement object with both a scalar and a unit component.
scalar/1Extracts the scalar portion of a measurement.
subtract/2Yields the difference between two measurements.
unequal/2Determines whether two measurements are not equal.
unit/1Extracts the unit of a measurement (another measurement whose scalar is one).

Function Details

add/2

add(M1::measurement(), M2::measurement()) -> measurement() | {error, Reason}

Yields the sum of two measurements.

divide/2

divide(M1::measurement(), M2::measurement()) -> measurement() | {error, Reason}

Yields the ratio between two measurements.

equal/2

equal(M1::measurement(), M2::measurement()) -> true | false | {error, Reason}

Determines whether two measurements are equal.

exponent/2

exponent(M1::measurement(), M2::measurement()) -> measurement() | {error, Reason}

Raises a measurement to the power of another measurement. This only produces a sensible result if the second measurement is a scalar and an integer.

format/1

format(M::measurement()) -> string()

Render a measurement in human-readable form.

fwrite/2

fwrite(Format::string(), List::[term()]) -> ok

Wrapper for io:fwrite which is sensitive to measurements.

greater_than/2

greater_than(M1::measurement(), M2::measurement()) -> true | false | {error, Reason}

Determines whether the first measurement is greater than the second.

greater_than_or_equal/2

greater_than_or_equal(M1::measurement(), M2::measurement()) -> true | false | {error, Reason}

Determines whether the first measurement is greater than or equal to the second.

less_than/2

less_than(M1::measurement(), M2::measurement()) -> true | false | {error, Reason}

Determines whether the first measurement is less than the second.

less_than_or_equal/2

less_than_or_equal(M1::measurement(), M2::measurement()) -> true | false | {error, Reason}

Determines whether the first measurement is less than or equal to the second.

multiply/2

multiply(M1::measurement(), M2::measurement()) -> measurement() | {error, Reason}

Yields the product of two measurements.

new/1

new(S::number() | unit()) -> measurement()

Creates and returns a new measurement object, either a scalar if a number is given, or a measurement of one unit if a unit is given.

new/2

new(S::number(), L::[{unit(), dimension()}]) -> measurement()

Creates and returns a new measurement object with both a scalar and a unit component.

scalar/1

scalar(M::measurement()) -> number()

Extracts the scalar portion of a measurement.

subtract/2

subtract(M1::measurement(), M2::measurement()) -> measurement() | {error, Reason}

Yields the difference between two measurements.

unequal/2

unequal(M1::measurement(), M2::measurement()) -> true | false | {error, Reason}

Determines whether two measurements are not equal.

unit/1

unit(M::measurement()) -> measurement()

Extracts the unit of a measurement (another measurement whose scalar is one).


Generated by EDoc, Dec 25 2007, 02:42:05.