mirror of
https://github.com/teo3300/rust-mal.git
synced 2026-01-12 01:05:32 +01:00
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:
45 lines
696 B
Plaintext
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))
|