From 0a6b8c12ff7ecc668173c694b9f90d81db58416e Mon Sep 17 00:00:00 2001 From: wlott <wlott> Date: Sat, 21 Jul 1990 15:33:08 +0000 Subject: [PATCH] Moved phase, cis, and abs here from numbers. Commented out defconstant of e, because other code uses e as a local. I guess single letter constants are kind of stupid. --- code/irrat.lisp | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/code/irrat.lisp b/code/irrat.lisp index 8d9e4d22c..1f0fdd7d8 100644 --- a/code/irrat.lisp +++ b/code/irrat.lisp @@ -7,7 +7,7 @@ ;;; Scott Fahlman (FAHLMAN@CMUC). ;;; ********************************************************************** ;;; -;;; $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/irrat.lisp,v 1.1 1990/07/20 23:52:13 wlott Exp $ +;;; $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/code/irrat.lisp,v 1.2 1990/07/21 15:33:08 wlott Exp $ ;;; ;;; This file contains all the irrational functions. Actually, most of the ;;; work is done by calling out to C... @@ -21,7 +21,7 @@ ;;;; Random constants, utility functions, and macros. (defconstant pi 3.14159265358979323846264338327950288419716939937511L0) -(defconstant e 2.71828182845904523536028747135266249775724709369996L0) +;(defconstant e 2.71828182845904523536028747135266249775724709369996L0) (defmacro def-math-rtn (name num-args) (let ((function (intern (concatenate 'simple-string @@ -187,7 +187,23 @@ ;;;; Trigonometic and Related Functions -;;; ABS is in numbers.lisp +(defun abs (number) + "Returns the absolute value of the number." + (number-dispatch ((number number)) + (((foreach single-float double-float fixnum rational)) + (abs number)) + ((complex) + (let ((rx (realpart number)) + (ix (imagpart number))) + (etypecase rx + (rational + (sqrt (+ (* rx rx) (* ix ix)))) + (single-float + (coerce (%hypot (coerce rx 'double-float) + (coerce ix 'double-float)) + 'single-float)) + (double-float + (%hypot rx ix))))))) (defun phase (number) "Returns the angle part of the polar representation of a complex number. @@ -236,7 +252,11 @@ (if (zerop denom) (error "~S undefined tangent." number) (/ num denom)))))) -;;; CIS is in numbers.lisp +(defun cis (theta) + "Return cos(Theta) + i sin(Theta), aka exp(i Theta)." + (if (complexp theta) + (error "Argument to CIS is complex: ~S" theta) + (complex (cos theta) (sin theta)))) #+nil (defun in-asin-domain (z) -- GitLab