atanh.lsp 3.13 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Wed Feb 11 19:26:25 2004
;;;; Contains: Tests of ATANH

(in-package :cl-test)

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

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

(deftest atanh.3
  (loop for type in '(short-float single-float double-float long-float)
sds's avatar
sds committed
24 25 26 27
        for zero = (coerce 0 `(complex ,type))
        unless (equal (multiple-value-list (atanh zero))
                      (list zero))
        collect type)
28 29 30 31
  nil)

(deftest atanh.4
  (loop for den = (1+ (random 10000))
sds's avatar
sds committed
32 33 34 35 36 37 38 39
        for num = (random den)
        for x = (/ num den)
        for rlist = (multiple-value-list (atanh x))
        for y = (car rlist)
        repeat 1000
        unless (and (null (cdr rlist))
                    (numberp y))
        collect (list x rlist))
40 41 42 43
  nil)

(deftest atanh.5
  (loop for type in '(short-float single-float double-float long-float)
sds's avatar
sds committed
44 45 46 47 48 49 50 51 52 53 54
        nconc
        (loop
         for x = (if (eql (random 2) 0)
                     (+ 2 (random (coerce 1000 type)))
                   (- -2 (random (coerce 1000 type))))
         for rlist = (multiple-value-list (atanh x))
         for y = (car rlist)
         repeat 1000
         unless (and (null (cdr rlist))
                     (typep y `(complex ,type)))
         collect (list x rlist)))
55 56 57 58
  nil)

(deftest atanh.5a
  (loop for type in '(short-float single-float double-float long-float)
sds's avatar
sds committed
59 60 61 62 63 64 65 66 67
        nconc
        (loop
         for x = (- (random (coerce 1.9998s0 type)) 0.9999s0)
         for rlist = (multiple-value-list (atanh x))
         for y = (car rlist)
         repeat 1000
         unless (and (null (cdr rlist))
                     (typep y type))
         collect (list x rlist)))
68 69 70 71
  nil)

(deftest atanh.6
  (loop for type in '(short-float single-float double-float long-float)
sds's avatar
sds committed
72 73 74 75 76 77 78 79 80
        nconc
        (loop
         for x1 = (- (random (coerce 1.9998s0 type)) 0.9999s0)
         for rlist = (multiple-value-list (atanh (complex x1 0.0s0)))
         for y = (car rlist)
         repeat 1000
         unless (and (null (cdr rlist))
                     (typep y `(complex ,type)))
         collect (list x1 rlist)))
81 82 83 84
  nil)

(deftest atanh.7
  (loop for type in '(short-float single-float double-float long-float)
sds's avatar
sds committed
85 86 87 88 89 90 91 92 93
        nconc
        (loop
         for x1 = (- (random (coerce 1.9998s0 type)) 0.9999s0)
         for rlist = (multiple-value-list (atanh (complex 0.0s0 x1)))
         for y = (car rlist)
         repeat 1000
         unless (and (null (cdr rlist))
                     (typep y `(complex ,type)))
         collect (list x1 rlist)))
94 95
  nil)

pfdietz's avatar
pfdietz committed
96 97 98
(deftest atanh.8
  (macrolet ((%m (z) z)) (atanh (expand-in-current-env (%m 0.0))))
  0.0)
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114


;;; FIXME
;;; Add accuracy tests here

;;; Error tests

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

(deftest atanh.error.2
  (signals-error (atanh 1.0 1.0) program-error)
  t)

(deftest atanh.error.3
115
  (check-type-error #'atanh #'numberp)
116
  nil)