Skip to content

Commit 26373ce

Browse files
author
Fabien Zoccola
committed
feat(Math): adding math:floordiv, returns the euclidian division's quotient
1 parent 524b6fb commit 26373ce

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Math.ark

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,15 @@
129129
# =end
130130
##
131131
(let math:log10 (fun (x) {
132-
(math:log x 10)}))
132+
(math:log x 10)}))
133+
134+
###
135+
# @brief Returns the quotient of the euclidian division of a and b
136+
# @param a the dividend
137+
# @param b the divisor
138+
# @author https://github.com/fabien-zoccola
139+
# =begin
140+
# (math:floordiv 14 6) # Returns 2
141+
# =end
142+
##
143+
(let math:floordiv (fun (a b) (math:floor (/ a b))))

tests/math-tests.ark

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
(set tests (assert-eq (math:log2 128) 7 "math:log2" tests))
3333
(set tests (assert-eq (math:log2 2048) 11 "math:log2" tests))
3434
(set tests (assert-eq (math:log10 1000) 3 "math:log10" tests))
35+
(set tests (assert-eq (math:floordiv 14 6) 2 "math:floordiv" tests))
36+
(set tests (assert-eq (math:floordiv 14 14) 1 "math:floordiv" tests))
37+
(set tests (assert-eq (math:floordiv 14 15) 0 "math:floordiv" tests))
3538

3639
(recap "Math tests passed" tests (- (time) start-time))
3740

0 commit comments

Comments
 (0)