Useful Math Function

For the Compleat Fan
Post Reply
Jeremy Dunn
Posts: 95
Joined: Wed Oct 13, 2004 8:02 pm
Location: Bellingham WA

Useful Math Function

Post by Jeremy Dunn »

This function is basically a counterpart to the SQRT function and serves a useful purpose. I originally had two separate functions but then realized that I could combine them both.

Code: Select all

;; This function takes one or more numbers as arguments. If there is a single
;; number the number is squared. If there is more than one number then the square
;; root of the sum of the squares (a^2 + b^2 + c^2 + ...)^1/2 is returned.
;; Example: (sq 3) -> 9
;;          (sq 2 3) -> 3.605551275
(define-macro (sq)
  (if (= (length (args)) 1)
      (mul (args 0)(args 0))
      (sqrt (apply add (map mul (args)(args))))))

Post Reply