The first group are bounds checking functions. I have added alternate names to the math operator symbols to provide an alternate naming that is consistent with the naming pattern of the other boolean functions in NewLISP for those who are picky about consistency.
Code: Select all
;Command name alternates for naming consistency
(define-macro (less?)(apply < (args)))
(define-macro (greater?)(apply > (args)))
(define-macro (ge?)(apply >= (args)))
(define-macro (le?)(apply <= (args)))
(define-macro (e?)(apply = (args)))
(define-macro (ne?)(apply != (args)))
;These functions are shorthands for testing whether the number a lies within
; or without of various ranges of x and y
(define (lle? x a y)(and (< x a)(<= a y)))
(define (lel? x a y)(and (<= x a)(< a y)))
(define (gge? x a y)(and (> x a)(>= a y)))
(define (geg? x a y)(and (>= x a)(> a y)))
(define (lg? x a y)(or (< a x)(> a y)))
(define (lege? x a y)(or (<= a x)(>= a y)))
Code: Select all
;Strictly positive
(define (spos? x)(> x 0))
(define (pos? x)(>= x 0))
(define (neg? x)(<= x 0))
;Strictly negative
(define (sneg? x)(< x 0))
;Similar to the sgn function except that it returns 1 if x=0 rather than 0
(define (sgn2 x)(if (zero? x) 1 (sgn x)))
;Returns true if x and y have the same sign
(define (sgn=? x y)(= 1 (* (sgn2 x)(sgn2 y))))
;Returns y with the same sign as x
(define (sgncast x y)(if (sgn=? x y) y (sub y)))
Code: Select all
;; Sets the fuzz factor for functions that use it. (fuzzy) with no arguments resets *fuzz*
;; to its default value of 0.000001. If there is an integer argument then *fuzz* is set to
;; 10^n. If there is a real number as an argument then *fuzz* is set to that value.
(define (fuzzy (x 0.000001))
(setq *fuzz* (if (integer? x) (pow 10 x) x)))
;Return true if x=y to within +-fz
(define (approx? x (y 0)(fz *fuzz*))
(< (sub y fz) x (add y fz)))
;If x=y to within the fuzz factor then return y else return nil
(define (approx x (y 0)(fz *fuzz*))
(if (approx? x y fz) y))
I will soon post my own rational arithmetic set of functions that is more complete than the current library.