Nyquist / XLISP 2.0  -  Contents | Tutorials | Examples | Reference

acos


Type:   -   Lisp function (closure)
Source:   -  

Syntax

(acos flonum)
flonum - an integer or floating point expression
returns - the arc-cosine of the number

Note: the 'acos' function is not implemented in Nyquist. Here is a Lisp implementation of 'acos', using the atan function:

(defun acos (x)
  (cond ((not (numberp x)) (error "bad argument type" x))
        ((= x 1) 0.0)
        ((= x -1) pi)
        ((< -1 x 1) (+ (atan (/ (- x) (sqrt (1+ (* x (- (float x))))))) (/ pi 2.0)))
        (t (error "argument out of range" x))))

Description

The 'acos' function returns the arc-cosine of an integer or floating point expression. The result is a floating point number in radians. If the argument is less than -1 or greater than +1, the arc-cosine is a complex number. Complex numbers are not available in XLISP. In this case the 'acos' function signals an 'argument out of range' error.

Examples

(acos 0.0)   => 1.5708
(acos 1.0)   => 0.0
(acos -1.0)  => 3.14159

See also:

  Back to Top


Nyquist / XLISP 2.0  -  Contents | Tutorials | Examples | Reference