atan.lsp 4.17 KB
Newer Older
1 2 3 4 5 6 7 8
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Wed Feb 11 06:01:55 2004
;;;; Contains: Tests of ATAN

(in-package :cl-test)

(deftest atan.1
pfdietz's avatar
pfdietz committed
9 10
  (let ((result (atan 0)))
    (or (eqlt result 0)
sds's avatar
sds committed
11
        (eqlt result 0.0)))
pfdietz's avatar
pfdietz committed
12
  t)
13 14 15

(deftest atan.2
  (loop for type in '(short-float single-float double-float long-float)
sds's avatar
sds committed
16 17 18
        for zero = (coerce 0 type)
        unless (eql (atan zero) zero)
        collect type)
19 20 21 22
  nil)

(deftest atan.3
  (loop for type in '(short-float single-float double-float long-float)
sds's avatar
sds committed
23 24 25
        for zero = (coerce 0 type)
        unless (eql (atan zero 1) zero)
        collect type)
26 27 28 29
  nil)

(deftest atan.4
  (loop for type in '(short-float single-float double-float long-float)
sds's avatar
sds committed
30 31 32 33
        for zero = (coerce 0 type)
        for one = (coerce 1 type)
        unless (eql (atan 0 one) zero)
        collect type)
34 35 36 37
  nil)

(deftest atan.5
  (loop for type in '(short-float single-float double-float long-float)
sds's avatar
sds committed
38 39 40 41
        for zero = (coerce 0 type)
        for one = (coerce 1 type)
        unless (eql (atan zero one) zero)
        collect type)
42 43 44 45
  nil)

(deftest atan.6
  (loop for type in '(short-float single-float double-float long-float)
sds's avatar
sds committed
46 47 48 49 50 51 52 53 54 55
        for a = (coerce 2000 type)
        for b = (coerce -1000 type)
        collect
        (loop for x = (- (random a) b)
              for rlist = (multiple-value-list (atan x))
              for y = (car rlist)
              repeat 1000
              unless (and (null (cdr rlist))
                          (typep y type))
              collect (list x rlist)))
56 57 58 59
  (nil nil nil nil))

(deftest atan.7
  (loop for type in '(short-float single-float double-float long-float)
sds's avatar
sds committed
60 61 62 63 64 65 66 67 68 69 70
        for a = (coerce 2000 type)
        for b = (coerce -1000 type)
        for zero = (coerce 0 type)
        collect
        (loop for x = (- (random a) b)
              for rlist = (multiple-value-list (atan (complex x zero)))
              for y = (car rlist)
              repeat 1000
              unless (and (null (cdr rlist))
                          (typep y `(complex ,type)))
              collect (list x rlist)))
71 72 73 74
  (nil nil nil nil))

(deftest atan.8
  (loop for type in '(short-float single-float double-float long-float)
sds's avatar
sds committed
75 76 77 78 79 80 81 82 83 84 85
        for a = (coerce 2000 type)
        for b = (coerce -1000 type)
        for zero = (coerce 0 type)
        collect
        (loop for x = (- (random a) b)
              for rlist = (multiple-value-list (atan (complex zero x)))
              for y = (car rlist)
              repeat 1000
              unless (and (null (cdr rlist))
                          (typep y `(complex ,type)))
              collect (list x rlist)))
86 87 88 89
  (nil nil nil nil))

(deftest atan.9
  (loop for type in '(short-float single-float double-float long-float)
sds's avatar
sds committed
90 91 92 93 94 95 96 97 98 99 100 101
        for a = (coerce 2000 type)
        for b = (coerce -1000 type)
        for zero = (coerce 0 type)
        collect
        (loop for x1 = (- (random a) b)
              for x2 = (- (random a) b)
              for rlist = (multiple-value-list (atan (complex x1 x2)))
              for y = (car rlist)
              repeat 1000
              unless (and (null (cdr rlist))
                          (typep y `(complex ,type)))
              collect (list x1 x2 rlist)))
102 103 104 105 106 107 108 109
  (nil nil nil nil))

(deftest atan.10
  (approx= (atan 1) (coerce (/ pi 4) 'single-float))
  t)

(deftest atan.11
  (loop for type in '(short-float single-float double-float long-float)
sds's avatar
sds committed
110
        collect (approx= (atan (coerce 1 type)) (coerce (/ pi 4) type)))
111 112 113 114 115 116 117 118
  (t t t t))

(deftest atan.12
  (approx= (atan -1) (coerce (/ pi -4) 'single-float))
  t)

(deftest atan.13
  (loop for type in '(short-float single-float double-float long-float)
sds's avatar
sds committed
119
        collect (approx= (atan (coerce -1 type)) (coerce (/ pi -4) type)))
120 121
  (t t t t))

pfdietz's avatar
pfdietz committed
122 123 124 125
(deftest atan.14
  (macrolet ((%m (z) z)) (atan (expand-in-current-env (%m 0.0))))
  0.0)

126 127 128 129 130 131 132 133 134 135 136 137 138 139
;;; FIXME
;;; More accuracy tests here

;;; Error tests

(deftest atan.error.1
  (signals-error (atan) program-error)
  t)

(deftest atan.error.2
  (signals-error (atan 1 1 1) program-error)
  t)

(deftest atan.error.3
140
  (check-type-error #'atan #'numberp)
141 142 143
  nil)

(deftest atan.error.4
144
  (check-type-error #'(lambda (x) (atan x 1)) #'realp)
145 146 147
  nil)

(deftest atan.error.5
148
  (check-type-error #'(lambda (x) (atan 1 x)) #'realp)
149 150 151 152 153
  nil)