Changeset 3610


Ignore:
Timestamp:
09/08/03 02:24:46 (19 years ago)
Author:
piso
Message:

PHASE

Location:
trunk/j/src/org/armedbear/lisp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/j/src/org/armedbear/lisp/autoloads.lisp

    r3586 r3610  
    22;;;
    33;;; Copyright (C) 2003 Peter Graves
    4 ;;; $Id: autoloads.lisp,v 1.16 2003-09-06 14:08:43 piso Exp $
     4;;; $Id: autoloads.lisp,v 1.17 2003-09-08 02:24:46 piso Exp $
    55;;;
    66;;; This program is free software; you can redistribute it and/or
     
    7474(autoload 'make-pathname)
    7575(autoload '(signum floor ceiling round rem mod ftruncate ffloor fceiling fround
    76             rational rationalize gcd isqrt)
     76            rational rationalize gcd isqrt phase)
    7777          "numbers.lisp")
  • trunk/j/src/org/armedbear/lisp/numbers.lisp

    r3586 r3610  
    22;;;
    33;;; Copyright (C) 2003 Peter Graves
    4 ;;; $Id: numbers.lisp,v 1.11 2003-09-06 14:08:25 piso Exp $
     4;;; $Id: numbers.lisp,v 1.12 2003-09-08 02:24:05 piso Exp $
    55;;;
    66;;; This program is free software; you can redistribute it and/or
     
    211211        (return init-value))
    212212      (setq init-value iterated-value))))))
     213
     214
     215(defun phase (number)
     216  "Returns the angle part of the polar representation of a complex number.
     217   For complex numbers, this is (atan (imagpart number) (realpart number)).
     218   For non-complex positive numbers, this is 0.  For non-complex negative
     219   numbers this is PI."
     220  (etypecase number
     221             (rational
     222              (if (minusp number)
     223                  (coerce pi 'single-float)
     224                  0.0f0))
     225             (single-float
     226              (if (minusp (float-sign number))
     227                  (coerce pi 'single-float)
     228                  0.0f0))
     229             (double-float
     230              (if (minusp (float-sign number))
     231                  (coerce pi 'double-float)
     232                  0.0d0))
     233             (complex
     234              (atan (imagpart number) (realpart number)))))
Note: See TracChangeset for help on using the changeset viewer.