Module

Data.Quantity

Package
purescript-quantities
Repository
sharkdp/purescript-quantities

This module defines data types and functions to handle physical quantities.

#Quantity Source

data Quantity

Representation of a physical quantity as a (product of a) numerical value and a physical unit.

Instances

#quantity Source

quantity :: Number -> DerivedUnit -> Quantity

Construct a physical quantity from a numerical value and the physical unit.

#(.*) Source

Operator alias for Data.Quantity.quantity (non-associative / precedence 5)

#quantity' Source

quantity' :: Decimal -> DerivedUnit -> Quantity

Construct a physical quantity from a numerical value and the physical unit.

#prettyPrint' Source

prettyPrint' :: Quantity -> { number :: String, space :: Boolean, unit :: String }

Show a physical quantity in a human-readable form, value and unit separately.

#prettyPrint Source

prettyPrint :: Quantity -> String

Show a physical quantity in a human-readable form.

#showResult Source

showResult :: Either ConversionError Quantity -> String

Show the (possibly failed) result of a computation in human-readable form.

#derivedUnit Source

derivedUnit :: Quantity -> DerivedUnit

The unit of a physical quantity.

#toStandard Source

toStandard :: Quantity -> Quantity

Convert a quantity to its standard representation.

#fullSimplify Source

fullSimplify :: Quantity -> Quantity

Attempt to simplify the unit of a quantity.

#approximatelyEqual Source

approximatelyEqual :: Number -> Quantity -> Quantity -> Boolean

Check whether two quantities have matching units (or can be converted to the same representation) and test if the numerical values are approximately equal.

#ConversionError Source

data ConversionError

A unit conversion error that appears if two given units cannot be converted into each other.

Constructors

Instances

#errorMessage Source

errorMessage :: ConversionError -> String

Textual representation of a unit conversion error.

#scalar Source

scalar :: Number -> Quantity

Create a scalar (i.e. dimensionless) quantity from a number.

#scalar' Source

scalar' :: Decimal -> Quantity

Create a scalar (i.e. dimensionless) quantity from a number.

#convert Source

convert :: DerivedUnit -> Quantity -> Either ConversionError Quantity

Attempt to convert a physical quantity to a given target unit. Returns a ConversionError if the conversion fails.

#convertTo Source

convertTo :: Quantity -> DerivedUnit -> Either ConversionError Quantity

Flipped version of convert.

#asValueIn Source

asValueIn :: Quantity -> DerivedUnit -> Either ConversionError Number

Get the numerical value of a physical quantity in a given unit. Returns a ConversionError if the conversion fails.

#asValueIn' Source

asValueIn' :: Quantity -> DerivedUnit -> Either ConversionError Decimal

Get the numerical value of a physical quantity in a given unit. Returns a ConversionError if the conversion fails.

#toScalar Source

toScalar :: Quantity -> Either ConversionError Number

Try to convert a quantity to a scalar value

#toScalar' Source

toScalar' :: Quantity -> Either ConversionError Decimal

Try to convert a quantity to a scalar value

#isFinite Source

isFinite :: Quantity -> Boolean

Check if the numerical value of a quantity is finite.

#qNegate Source

qNegate :: Quantity -> Quantity

Negate the numerical value of a quantity.

#qAdd Source

qAdd :: Quantity -> Quantity -> Either ConversionError Quantity

Attempt to add two quantities. If the units can not be unified, an error is returned.

#(⊕) Source

Operator alias for Data.Quantity.qAdd (left-associative / precedence 3)

#qSubtract Source

qSubtract :: Quantity -> Quantity -> Either ConversionError Quantity

Attempt to subtract two quantities. If the units can not be unified, an error is returned.

#(⊖) Source

Operator alias for Data.Quantity.qSubtract (left-associative / precedence 3)

#qMultiply Source

qMultiply :: Quantity -> Quantity -> Quantity

Multiply two quantities.

#(⊗) Source

Operator alias for Data.Quantity.qMultiply (left-associative / precedence 4)

#qDivide Source

qDivide :: Quantity -> Quantity -> Quantity

Divide two quantities.

#(⊘) Source

Operator alias for Data.Quantity.qDivide (left-associative / precedence 4)

#pow Source

pow :: Quantity -> Decimal -> Quantity

Raise a quantity to a given power.

#abs Source

abs :: Quantity -> Quantity

The absolute value of a quantity.

#sqrt Source

sqrt :: Quantity -> Quantity

The square root of a quantity.