Bankster library, scalable protocol with implementation.
Bankster library, scalable protocol with implementation.
Enables re-scaling after each consecutive operation.
Enables re-scaling after each consecutive operation.
(->double n)(->double n scale)(->double n rounding-mode)(->double n scale rounding-mode)Converts to a double with optional rescaling and rounding. If the precision of double is to small to express the value, rounding must be provided (either explicitly or using rounding-mode), otherwise an exception will be thrown.
Converts to a double with optional rescaling and rounding. If the precision of double is to small to express the value, rounding must be provided (either explicitly or using *rounding-mode*), otherwise an exception will be thrown.
(->float n)(->float n scale)(->float n rounding-mode)(->float n scale rounding-mode)Converts to a float with optional rescaling and rounding. If the precision of float is to small to express the value, rounding must be provided (either explicitly or using rounding-mode), otherwise an exception will be thrown.
Converts to a float with optional rescaling and rounding. If the precision of float is to small to express the value, rounding must be provided (either explicitly or using *rounding-mode*), otherwise an exception will be thrown.
(->int n)(->int n rounding-mode)Converts to an int (may cast to long on call boundaries) with optional rounding.
Converts to an int (may cast to long on call boundaries) with optional rounding.
(->long n)(->long n rounding-mode)Converts to a long with optional rounding.
Converts to a long with optional rounding.
Represents the scale of a currency that is automatic and not limited to specific decimal places. Used to indicate that the scale should be determined by the actual precision of the amount, not by a fixed currency scale.
Represents the scale of a currency that is automatic and not limited to specific decimal places. Used to indicate that the scale should be determined by the actual precision of the amount, not by a fixed currency scale.
(auto-scaled*? scale)Macro version of auto-scaled?. Returns true if the given scale equals the
auto-scaled sentinel value (-1). Inlines the comparison for performance.
Macro version of `auto-scaled?`. Returns `true` if the given scale equals the auto-scaled sentinel value (-1). Inlines the comparison for performance.
(auto-scaled? scale)Returns true if the given scale equals the auto-scaled sentinel value (-1).
Returns `true` if the given scale equals the auto-scaled sentinel value (-1).
(div-math-context a b)(div-math-context a b rounding-mode)Returns the MathContext set to handle the possible precision for the operation of dividing two BigDecimal numbers. Optional rounding mode may be provided.
Returns the MathContext set to handle the possible precision for the operation of dividing two BigDecimal numbers. Optional rounding mode may be provided.
(div-max-precision a b)Returns the maximum possible precision for the operation of dividing two BigDecimal numbers.
Returns the maximum possible precision for the operation of dividing two BigDecimal numbers.
(each & body)Enables re-scaling on some consecutive operations which support it and sets the rounding mode for operations on scaled values. Internally sets rescale-each to true and rounding-mode to the given value.
Practically, in most cases it is better to use the with-rescaling macro which also sets rounding mode.
Enables re-scaling on some consecutive operations which support it and sets the rounding mode for operations on scaled values. Internally sets *rescale-each* to true and *rounding-mode* to the given value. Practically, in most cases it is better to use the with-rescaling macro which also sets rounding mode.
(fractional n)(fractional n scale)(fractional n scale rounding-mode)Returns the fractional part of the given number, converted to decimal if required. Optional scale and rounding mode can be given. Makes use of rounding-mode if it's set.
Returns the fractional part of the given number, converted to decimal if required. Optional scale and rounding mode can be given. Makes use of *rounding-mode* if it's set.
(integer n)(integer n scale)(integer n scale rounding-mode)Returns the integer part of the given number, converted to decimal if required. Optional scale and rounding mode can be given. Makes use of rounding-mode if it's set.
Returns the integer part of the given number, converted to decimal if required. Optional scale and rounding mode can be given. Makes use of *rounding-mode* if it's set.
(monetary-scale n sc)(monetary-scale n sc rm)Applies monetary scaling rules to a BigDecimal-like value n and a currency scale.
When the scale indicates auto-scaling (equals auto-scaled, i.e., -1), the value
is returned as-is (converted to BigDecimal if necessary). Otherwise, the value is
scaled to the given number of decimal places.
This function is locale-independent and strict - it will throw ArithmeticException (wrapped in ExceptionInfo) if rounding is needed but no rounding mode is available.
Arguments:
n - a value convertible to BigDecimal (number, string, BigDecimal)sc - target scale (long); -1 means auto-scaled (no rescaling)rm - optional RoundingMode for downscalingReturns BigDecimal.
Applies monetary scaling rules to a BigDecimal-like value `n` and a currency scale. When the scale indicates auto-scaling (equals `auto-scaled`, i.e., -1), the value is returned as-is (converted to BigDecimal if necessary). Otherwise, the value is scaled to the given number of decimal places. This function is locale-independent and strict - it will throw ArithmeticException (wrapped in ExceptionInfo) if rounding is needed but no rounding mode is available. Arguments: - `n` - a value convertible to BigDecimal (number, string, BigDecimal) - `sc` - target scale (long); -1 means auto-scaled (no rescaling) - `rm` - optional RoundingMode for downscaling Returns BigDecimal.
Rounding mode to round towards positive infinity.
Rounding mode to round towards positive infinity.
Rounding mode to round towards zero.
Rounding mode to round towards zero.
Rounding mode to round towards negative infinity.
Rounding mode to round towards negative infinity.
Rounding mode to round towards nearest neighbor, unless neighbors are equidistant, in which case round down.
Rounding mode to round towards nearest neighbor, unless neighbors are equidistant, in which case round down.
Rounding mode to round towards nearest neighbor, unless neighbors are equidistant, in which case round towards the nearest one.
Rounding mode to round towards nearest neighbor, unless neighbors are equidistant, in which case round towards the nearest one.
Rounding mode to round towards nearest neighbor, unless neighbors are equidistant, in which case round up.
Rounding mode to round towards nearest neighbor, unless neighbors are equidistant, in which case round up.
Indication that no rounding is necessary.
Indication that no rounding is necessary.
Rounding mode to round away from zero.
Rounding mode to round away from zero.
The Scalable protocol describes values that can be scaled.
The Scalable protocol describes values that can be scaled.
(amount num)(amount num scale)(amount num scale rounding-mode)Returns the amount of a scalable as a BigDecimal number. Some scalables may not be purely numeric so this function is to get the actual, calculable value out of them.
Returns the amount of a scalable as a BigDecimal number. Some scalables may not be purely numeric so this function is to get the actual, calculable value out of them.
(applied? num)Returns true if the value is of a type that contains scaling information.
Returns true if the value is of a type that contains scaling information.
(apply num)(apply num scale)(apply num scale rounding-mode)Converts the given value to a scalable with or without changing its scale. For values that already are scalable it changes their scales if called with a second argument. The third argument, rounding-mode, must be present when downscaling and rounding is needed. For compound values (like monetary amounts) it will rescale the amount but will NOT update scale information of the unit (e.g. currency component).
When operating on Money objects and called with a single argument, it reapplies the nominal currency scale.
Converts the given value to a scalable with or without changing its scale. For values that already are scalable it changes their scales if called with a second argument. The third argument, rounding-mode, must be present when downscaling and rounding is needed. For compound values (like monetary amounts) it will rescale the amount but will NOT update scale information of the unit (e.g. currency component). When operating on Money objects and called with a single argument, it reapplies the nominal currency scale.
(of num)Returns a scale. If the given value is not of type that scales (or is used to produce scaled types) it will be converted to such.
Returns a scale. If the given value is not of type that scales (or is used to produce scaled types) it will be converted to such.
(scalable? num)Returns true if the value can be converted to a scalable.
Returns true if the value can be converted to a scalable.
(to-clojure-string n)Converts the amount to a plain string, adding the M suffix when needed.
Converts the amount to a plain string, adding the M suffix when needed.
(to-clojure-symbol n)Converts the amount to a symbol, adding the M suffix when needed.
Converts the amount to a symbol, adding the M suffix when needed.
(to-plain-string n)Converts the amount to a plain string.
Converts the amount to a plain string.
(to-symbol n)Converts the amount to a symbol.
Converts the amount to a symbol.
MathContext indicating auto-scaling and no rounding.
MathContext indicating auto-scaling and no rounding.
(with num)(with num scale)(with num scale rounding-mode)Alias for scale/apply.
Alias for scale/apply.
(with-rescaling rounding-mode & body)Enables re-scaling on some consecutive operations which support it and sets the
rounding mode for operations on scaled values. Internally sets *each* to true and
*rounding-mode* to the given value.
The first argument should be a valid rounding (from io.randomseed.bankster.scale
or java.math.RoundingMode) or one of the following:
CEILING - rounds towards positive infinity. DOWN - rounds towards zero. FLOOR - rounds towards negative infinity. HALF_DOWN - rounds towards nearest neighbor unless both neighbors are equidistant, in which case rounds down. HALF_EVEN - rounds towards the nearest neighbor unless both neighbors are equidistant, and if so, rounds towards the even. HALF_UP - rounds towards the nearest neighbor unless both neighbors are equidistant, and if so, rounds up. UP – rounds away from zero UNNECESSARY - asserts that the requested operation has an exact result, hence no rounding is necessary.
Enables re-scaling on some consecutive operations which support it and sets the rounding mode for operations on scaled values. Internally sets `*each*` to true and `*rounding-mode*` to the given value. The first argument should be a valid rounding (from `io.randomseed.bankster.scale` or `java.math.RoundingMode`) or one of the following: CEILING - rounds towards positive infinity. DOWN - rounds towards zero. FLOOR - rounds towards negative infinity. HALF_DOWN - rounds towards nearest neighbor unless both neighbors are equidistant, in which case rounds down. HALF_EVEN - rounds towards the nearest neighbor unless both neighbors are equidistant, and if so, rounds towards the even. HALF_UP - rounds towards the nearest neighbor unless both neighbors are equidistant, and if so, rounds up. UP – rounds away from zero UNNECESSARY - asserts that the requested operation has an exact result, hence no rounding is necessary.
(with-rounding rounding-mode & body)Sets the rounding mode for operations on scaled values.
The first argument should be a valid rounding (from io.randomseed.bankster.scale
or java.math.RoundingMode) or one of the following:
CEILING - rounds towards positive infinity. DOWN - rounds towards zero. FLOOR - rounds towards negative infinity. HALF_DOWN - rounds towards nearest neighbor unless both neighbors are equidistant, in which case rounds down. HALF_EVEN - rounds towards the nearest neighbor unless both neighbors are equidistant, and if so, rounds towards the even. HALF_UP - rounds towards the nearest neighbor unless both neighbors are equidistant, and if so, rounds up. UP – rounds away from zero UNNECESSARY - asserts that the requested operation has an exact result, hence no rounding is necessary.
Sets the rounding mode for operations on scaled values. The first argument should be a valid rounding (from `io.randomseed.bankster.scale` or `java.math.RoundingMode`) or one of the following: CEILING - rounds towards positive infinity. DOWN - rounds towards zero. FLOOR - rounds towards negative infinity. HALF_DOWN - rounds towards nearest neighbor unless both neighbors are equidistant, in which case rounds down. HALF_EVEN - rounds towards the nearest neighbor unless both neighbors are equidistant, and if so, rounds towards the even. HALF_UP - rounds towards the nearest neighbor unless both neighbors are equidistant, and if so, rounds up. UP – rounds away from zero UNNECESSARY - asserts that the requested operation has an exact result, hence no rounding is necessary.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |