kigubkur.mod.coerce
Modify: to coerce the number type of a number or all the elements (numbers) of a kigubkur© matrix (block included).
(require '[kigubkur.mod [coerce :refer [coerce-to]]])
Syntax
(coerce-to <number-type> <numeric-object>)
The <number-type>
can be any of the seven Clojure functions: int
, bigint
, long
, short
, float
, double
and bigdec
.
The <numeric-object>
can be a number or matrix (also row or column) or block.
Examples
=> (coerce-to bigint 2)
2N
=> (coerce-to float [[1 2 3 4 5]])
[[1.0 2.0 3.0 4.0 5.0]]
=> (coerce-to double [[1 2 3][4 5 6][7 8 9]])
[[1.0 2.0 3.0][4.0 5.0 6.0][7.0 8.0 9.0]]
=> (require '[kigubkur.construct [blocking :refer [block]]])
=> (def L [[1 2 3 4 5 6 7 8 9 10]
[1 2 3 4 5 6 7 8 9 10]
[1 2 3 4 5 6 7 8 9 10]
[1 2 3 4 5 6 7 8 9 10]
[1 2 3 4 5 6 7 8 9 10]
[1 2 3 4 5 6 7 8 9 10]
[1 2 3 4 5 6 7 8 9 10]])
=> (pprint (coerce-to bigdec (block L 5)))
[[{:A11 [[1M 2M 3M 4M 5M]
[1M 2M 3M 4M 5M]
[1M 2M 3M 4M 5M]
[1M 2M 3M 4M 5M]
[1M 2M 3M 4M 5M]],
:A12 [[6M 7M 8M 9M 10M]
[6M 7M 8M 9M 10M]
[6M 7M 8M 9M 10M]
[6M 7M 8M 9M 10M]
[6M 7M 8M 9M 10M]]}]
[{:A21 [[1M 2M 3M 4M 5M]
[1M 2M 3M 4M 5M]],
:A22 [[6M 7M 8M 9M 10M]
[6M 7M 8M 9M 10M]]}]]
coerce-to
(coerce-to numbtype x)
Function to coerce the type of a number or entries of a matrix or a block (i.e. element-wise).
Syntax: (coerce-to numb-type x)
The desired number type (to be coerced to) must be one of the seven: int
, bigint
, long
, short
, float
, double
and bigdec
.
Note: if x ∈ {##NaN
, ##Inf
, ##-Inf
}, returns ##NaN
.