This is not a full specification of the edge cases, the thrown errors, etc. Think of it as the API-lite or the Getting-Started-API.
Protocol
Method | arguments | output | description |
---|---|---|---|
AsUnit | amount | unit | Returns a new unit in which the given amount is unity. |
getUnit | amount | unit | Returns the unit associated to the given amount. |
getValue | amount, unit | double | Returns the value of the given amount in the given unit as a double (if possible). |
to | amount, unit | amount | Converts the given amount to the given unit (if possible) and returns it. See also IFnUnit . |
For all x
and all units U
for which (to x U)
is well-defined, we should have (getValue (to x U) U) ==> x
.
Protocol
Method | arguments | output | description |
---|---|---|---|
compatible? | unit1, unit2 | boolean | Returns true when conversions between the two units are possible. |
from | unit | fn: amount -> number | Returns a function #(getValue % unit) . |
offset | unit, amount | unit | Returns a unit offset by the given amount (if possible). |
rescale | unit, number | unit | Returns a unit linearly rescaled by the given factor. |
Type
Implementation of Dimensionful
. See also IFnUnit
.
Function
arguments | output |
---|---|
map | unit |
alist | unit |
string | unit |
Returns a composite unit from a map of units and integer powers.
Function (Predicate)
Returns true
when given an units2.core.amount
object carrying a unit that is Unitlike
, and false
otherwise.
Type
Implementation of Unitlike
and of IFn
.
arguments | output |
---|---|
number | amount |
amount | amount |
Applying an IFnUnit
on a regular clojure number returns an units2.core.amount
with this unit. Applying an IFnUnit
on such an amount returns that amount converted into this unit.
Macro
arguments | output |
---|---|
var, unit | var |
def
the given var to hold the given unit, and change that unit's printed representation to that var. Returns the given var for consistency with def
, defn
, defmacro
.
Function (Constructor)
arguments | output |
---|---|
string | unit |
Returns a new (anonymous) unit at the base of a new dimension. See also defbaseunit
.
Macro
A hybrid between defunit
and makebaseunit
.
Macro
arguments | output |
---|---|
var, unit | var |
A defunit
that also defunits all SI/IEC prefixed units. Returns the given var for consistency with def
, defn
, defmacro
.
Macros
Rebind (lexically shadow) various clojure.core and java.lang.Math functions to unit-aware equivalents within the macro's scope.
Functions
Functions
Functions
Function
arguments | output |
---|---|
amount, amount | double |
Returns the ratio of two compatible units as a double (if possible).
Functions
These exponentiation functions are inspired by methods of java.lang.Math
. They should only be defined on dimensionless quantities (to see why, just imagine Maclaurin-expanding the exp
or ln
functions).
We define them over ratios of amounts using the ages-old "atan2
" convention atan2(a,b) == atan(a/b)
. For instance,
(exp a) ; ==> (Math/exp a)
(exp a b) ; ==> (Math/exp (divide-into-double a b))
(pow a n) ; ==> (Math/pow a n)
(pow a b n) ; ==> (Math/pow (divide-into-double a b) n)
Function
Returns the given amount raised to the given integer power.
Functions
These modular arithmetic functions are inspired by methods of java.lang.Math
.
Functions
Functions
Higher-order functions for wrapping the algebra of units around pre-existing differentiation and integration schemes.
Name | arguments | output | description |
---|---|---|---|
decorate-differentiator | fn : f(number), number , arglist -> number | fn* | Decorate a differentiation scheme |
decorate-integrator | fn : f(number), [number number] , arglist -> number | fn* | Decorate an integration scheme |
where the shape of a decorated fn* is illustrated below.
Functions
Decorated versions of naive differentiation and integration schemes that can deal with units. These are provided for convenience/prototyping, and should be replaced by better (user-provided) schemes in production.
In what follows, let "amount(X)" denote "an amount
carrying units of X
".
Name | arguments | output | description |
---|---|---|---|
differentiate | fn: amount(A) -> amount(B), amount(A) , [amount(A)] | amount(B/A) | Returns the (first-order-forward) derivative of a function |
fn: amount(A) -> number, amount(A) , [amount(A)] | amount(1/A) | Returns the (first-order-forward) derivative of a function | |
fn: number -> amount(A), number , [number] | amount(A) | Returns the (first-order-forward) derivative of a function | |
fn: number -> number, number , [number] | number | Returns the (first-order-forward) derivative of a function | |
integrate | fn: amount(A) -> amount(B), [amount(A) amount(A)] , [number] | amount(BA) | Returns the definite integral of a function over an interval |
fn: amount(A) -> number, [amount(A) amount(A)] , [number] | amount(A) | Returns the definite integral of a function over an interval | |
fn: number -> amount(A), [number number] , [number] | amount(A) | Returns the definite integral of a function over an interval | |
fn: number -> number, [number number], [number] | number | Returns the definite integral of a function over an interval |