kigubkur.elfun.floor

Elementary Function: floor function, ⌊x⌋ = greatest integer ≤ x.

  • floor
(require '[kigubkur.mod [kigubkur.elfun.floor :refer [floor]]])

Examples

Floor of a number

=> (floor 1.6)
1

Floor of a vector

=> (def r [[1.2 2.4 3.5 4.7]])
=> (def c [[1.2][2.4][3.5][4.7]])
=> (view r)
[1.2 2.4 3.5 4.7]
Order -> 1 x 4
=> (floor r)
[[1 2 3 4]]
=> (view c)
[1.2]
[2.4]
[3.5]
[4.7]
Order -> 4 x 1
=> (floor c)
[[1] [2] [3] [4]]

Floor of a matrix

=> (def M [[1.0 2.1 3.2 4.3 5.4] [1.5 2.6 3.7 4.8 5.9] [1.0 2.1 3.2 4.3 5.4] [1.5 2.6 3.7 4.8 5.9]])
=> (view M)
[1.0 2.1 3.2 4.3 5.4]
[1.5 2.6 3.7 4.8 5.9]
[1.0 2.1 3.2 4.3 5.4]
[1.5 2.6 3.7 4.8 5.9]
Order -> 4 x 5
=> (view (floor M))
[1 2 3 4 5]
[1 2 3 4 5]
[1 2 3 4 5]
[1 2 3 4 5]
Order -> 4 x 5

Floor of a block

(require '[kigubkur.construct [blocking :refer [block]]])
=> (def L [[1.0 2.1 3.2 4.3 5.4 6.5 7.6 8.7 9.8 10.9]
           [1.9 2.8 3.7 4.6 5.5 6.4 7.3 8.2 9.1 10.0]
           [1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9 10.9]
           [1.9 2.8 3.7 4.6 5.5 6.4 7.3 8.2 9.1 10.9]])
=> (def B (block L 5))
=> (pprint B)
[[{:A11 [[1.0 2.1 3.2 4.3 ]
         [1.9 2.8 3.7 4.6]
         [1.1 2.2 3.3 4.4 ]
         [1.9 2.8 3.7 4.6]],
   :A12 [[5.4 6.5 7.6 8.7]
         [5.5 6.4 7.3 8.2]
         [5.5 6.6 7.7 8.8]
         [5.5 6.4 7.3 8.2]],
   :A13 [[9.8 10.9]
         [9.1 10.0]
         [9.9 10.9]
         [9.1 10.9]]}]]
=> (pprint (floor B))
[[{:A11 [[1 2 3 4]
         [1 2 3 4]
         [1 2 3 4]
         [1 2 3 4]],
   :A12 [[5 6 7 8]
         [5 6 7 8]
         [5 6 7 8]
         [5 6 7 8]],
   :A13 [[9 10]
         [9 10]
         [9 10]
         [9 10]]}]]

floor

(floor X)

Returns the floor of a number or every element of a matrix or a block (i.e. element-wise floor); floor of x, ⌊x⌋ ≝ greatest integer ≤ x.

Syntax: (floor X) s.t X is a scalar or a kigubkur© matrix (or both blocks)

Note: if x ∈ {##NaN, ##Inf, ##-Inf}, returns ##NaN.