Data.Quantity
- Package
- purescript-quantities
- Repository
- sharkdp/purescript-quantities
This module defines data types and functions to handle physical quantities.
#quantity Source
quantity :: Number -> DerivedUnit -> Quantity
Construct a physical quantity from a numerical value and the physical unit.
#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.
#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
- Modules
- Data.
Quantity - Data.
Quantity. Math - Data.
Quantity. Physics - Data.
Units - Data.
Units. Astronomical - Data.
Units. Bit - Data.
Units. CGS - Data.
Units. Currency - Data.
Units. Imperial - Data.
Units. Misc - Data.
Units. Nautical - Data.
Units. PartsPerX - Data.
Units. SI - Data.
Units. SI. Accepted - Data.
Units. SI. Derived - Data.
Units. Time - Data.
Units. USCustomary - Quantities