Files
dotfiles/cabal/share/x86_64-osx-ghc-7.8.4/zepto-0.6.0/stdlib/math.scm
2015-04-05 17:47:08 +02:00

28 lines
919 B
Scheme

(define exact? integer?)
(define (inexact? x) "is inexact number" (and (real? x) (not (integer? x))))
(define (even? n) "is even" (= (remainder n 2) 0))
(define (odd? n) "is odd" (not (= (remainder n 2) 0)))
(define (zero? n) "is zero" (= n 0))
(define (positive? n) "is positive" (> n 0))
(define (negative? n) "is negative" (< n 0))
(define complex? number?)
(define (abs n) "absolute value of number" (if (>= n 0) n (- n)))
(define (exact->inexact n) "make inexact number from exact" (* n 1.0))
(define (<> n1 n2) "not equal" (not (= n1 n2)))
(define (succ x) "next number" (+ x 1))
(define (pred x) "previous number" (- x 1))
(define (gcd a b) "Greatest Common Divisor"
(let ((aa (abs a))
(bb (abs b)))
(if (= bb 0)
aa
(gcd bb (remainder aa bb)))))
(define (lcm a b) "Least Common Multiple"
(if (or (= a 0) (= b 0))
0
(abs (* (quotient a (gcd a b)) b))))