wparker.dimensional-math.core

*check-units*

dynamic

When bound to a false unit checking is disabled at runtime,
even if enabled at compile time.  Note that this also disables quantity creation.

*compile-with-unit-checks*

dynamic

Dynamic var that, when bound to true, causes quantity macro expansions to expand to
the unit-checked case.  This can be set to true with a Leiningen injection in any dev/testing profiles
in projects using unit checking to ensure that units are always checked in tests.

*unit-power-error*

dynamic

If bound to a number, two unit powers are considered equal to each other if they are within
that distance of each other.  For example, if bound to .01, then meters^1.001 and meters^1 would be considered
the same unit.

->checked-copy-fn

(->checked-copy-fn f)
Takes a function that copies a number in accordance with the
clone-number contract and wraps it with a test that the number was
successfully copied.

->quantities-equal-fn

(->quantities-equal-fn math-fn operation-description)
Returns a function that operates on two quantities with the same units and returns a new quantity with the same units.  If the two quantities
have different units an exception is thrown.

->quantity

macro

(->quantity q u)
Macro that expands to create a quantity from the given numeric magnitude and unit map if *compile-with-unit-checks* is true
and simply expands to the magnitude otherwise.

->quantity*

(->quantity* magnitude units)
Given a number, returns a new number instance that is associated with the given units.

->quantity-comparison-fn

(->quantity-comparison-fn compare-fn fn-desc)
Returns a function that compares two quantities that must have equal units.  This function will returns a boolean.
Takes a function to compare two numbers.

->quantity-operation-fn

(->quantity-operation-fn math-fn unit-fn operation-description)
Returns a function that takes an arbitrary number of quantities and returns a new quantity, with a magnitude determined by math-fn
and powers determined by unit-fn.  For example, in the case of multiplication,
the math-fn is * and the unit-fn is +, since the units of multiplied quantities are added when multiplied.  The first argument
to the unit-fn is a power of a unit in the first quantity and the second argument is the power of the same unit in the second quantity.
The unit-fn can assume that it will receive numeric arguments; if a unit is not present in a quantity its' power is 0.  If the underlying
unit operation is not commutative the creator may need to wrap the underlying function to ensure that arguments are received in the correct
order and number to ensure correct unit propagation.

CloneableNumber

protocol

members

clone-number

(clone-number x)

def-quantities-macro

macro

(def-quantities-macro macro-name macro-doc checked-fn unchecked-fn)
Defines a macro that inserts a quantity-checking function if *compile-with-unit-checks* is true and a plain math function otherwise.  Takes four arguments:
1. The name of the macro to define.
2. The docstring for the macro macro to define.
3. The fully-qualified checked function.
4. The fully-qualified equivalent unchecked function.

quantities-add

macro

(quantities-add & qs__458__auto__)
Macro that expands to add quantities if the global flag *compile-with-unit-checks* is true and expands to simple addition otherwise.

quantities-add*

Function that adds quantities.  It must be provided at least 1 argument.
Unlike clojure.core/+, this will throw an exception if no arguments are provided.

quantities-divide

macro

(quantities-divide & qs__458__auto__)
Macro that expands to divide quantities if the global flag *compile-with-unit-checks* is true and expands to simple division otherwise.

quantities-divide*

Function that divides an arbitrary positive number of quantities.

quantities-equal?

macro

(quantities-equal? & qs__458__auto__)
Macro that expands to check quantity equality if the global flag *compile-with-unit-checks* is true and expands to a simple equality check otherwise.

quantities-equal?*

Tests if an arbitrary positive number of quantities are equal.

quantities-greater-than?

macro

(quantities-greater-than? & qs__458__auto__)
Macro that expands to check a greater-than quantity inequality if *compile-with-unit-checks* is true
and expands to a simple greater-than check otherwise.

quantities-greater-than?*

Tests if an arbitrary positive number of quantities are greater than each other.

quantities-less-than?

macro

(quantities-less-than? & qs__458__auto__)
Macro that expands to check a less-than quantity inequality if *compile-with-unit-checks* is true
and expands to a simple less-than check otherwise.

quantities-less-than?*

Tests if an arbitrary positive number of quantities are less than each other.

quantities-multiply

macro

(quantities-multiply & qs__458__auto__)
Macro that expands to multiply quantities if the global flag *compile-with-unit-checks* is true and expands to simple multiplication otherwise.

quantities-multiply*

Function that multiplies an arbitrary number of quantities.

quantities-subtract

macro

(quantities-subtract & qs__458__auto__)
Macro that expands to subtract quantities if the global flag *compile-with-unit-checks* is true and expands to simple subtraction otherwise.

quantities-subtract*

Function that subtracts an arbitrary number of quantities.
It must be provided at least 1 argument.

quantity->str

(quantity->str quantity)
Returns a string representing a quantity with units.  Note that the standard str function just returns
the magnitude as a string, while this function includes units.  This follows because the library associates
units with a number, but the underlying object instance of the number is unchanged.

quantity->units

(quantity->units x)
Given a quantity, returns its units map.

quantity?

(quantity? x)
Returns true if its argument corresponds to a quantity and false otherwise.

units-equal?

(units-equal? & quantities)
Tests if an arbitrary number of quantities have the same units.

without-unit-checks

(without-unit-checks f)
Fixture that executes a zero-arity function with unit checking disabled.
Note that quantity creation is also disabled, so any quantities created in this scope
should not be used in unit-checked operations outside it.