Files
rust-mal/tests/arithmetic.mal
teo3300 1af7d68261 feat(types.rs): Implemented fractional numbers
Fracional numbers as extension of integernumbers, with Euclid's algorithm for fractional simplification, added functions "floor" "num" "den", added syntax [+/-]<num>/<den> to define fractional numbers

BREAKING CHANGE:
2025-07-22 11:49:19 +09:00

45 lines
696 B
Plaintext

; +
(assert-eq (+ 1 -4) -3)
(assert-eq (+ 1 1) 2)
; -
(assert-eq (- 2 1) 1)
(assert-eq (- 1 2) -1)
; *
(assert-eq (* 2 3) 6)
(assert-eq (* -2 3) -6)
(assert-eq (* -2 -3) 6)
; /
(assert-eq (/ 3 2) 3/2)
(assert-eq (floor (/ 3 2)) 1)
(assert-eq (/ 2 3) 2/3)
(assert-eq (floor (/ 2 3)) 0)
(assert-eq (/ -10 2) -5)
(assert-eq (/ -10 -2) 5)
(assert (not (ok? (/ 12 0))))
; frac rart
(assert-eq (num 3/2) 3)
(assert-eq (den 3/2) 2)
; >
(assert (> 3 2))
(assert (not (> 1 2)))
(assert (not (> 1 1)))
; <
(assert (< 1 3))
(assert (not (< 3 2)))
(assert (not (< 1 1)))
; >=
(assert (>= 3 1))
(assert (not (>= 1 2)))
(assert (>= 1 1))
; <=
(assert (<= 1 3))
(assert (not (<= 3 2)))
(assert (<= 1 1))