epsilons.lsp 3.68 KB
Newer Older
1 2 3 4 5 6 7
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Wed Aug 20 22:05:20 2003
;;;; Contains: Tests of the EPSILON constants

(in-package :cl-test)

8 9
(compile-and-load "numbers-aux.lsp")

10 11
(deftest epsilons.1
  (loop for e in (list short-float-epsilon single-float-epsilon
sds's avatar
sds committed
12 13 14
                       double-float-epsilon long-float-epsilon)
        when (= (float 1 e) (+ (float 1 e) e))
        collect e)
15 16 17 18
  nil)

(deftest epsilons.2
  (loop for e in (list short-float-negative-epsilon
sds's avatar
sds committed
19 20 21 22 23
                       single-float-negative-epsilon
                       double-float-negative-epsilon
                       long-float-negative-epsilon)
        when (= (float 1 e) (- (float 1 e) e))
        collect e)
24 25 26 27
  nil)

(deftest epsilons.3
  (loop for e in (list short-float-epsilon single-float-epsilon
sds's avatar
sds committed
28 29 30
                       double-float-epsilon long-float-epsilon)
        unless (= (float 1 e) (+ (float 1 e) (/ e 2)))
        collect e)
31 32 33 34
  nil)

(deftest epsilons.4
  (loop for e in (list short-float-negative-epsilon
sds's avatar
sds committed
35 36 37 38 39
                       single-float-negative-epsilon
                       double-float-negative-epsilon
                       long-float-negative-epsilon)
        unless (= (float 1 e) (- (float 1 e) (/ e 2)))
        collect e)
40 41 42 43
  nil)

(deftest epsilons.5
  (loop for (type var) in
sds's avatar
sds committed
44 45 46 47 48 49 50 51 52 53 54 55
        '(
          (short-float short-float-epsilon)
          (short-float short-float-negative-epsilon)
          (single-float single-float-epsilon)
          (single-float single-float-negative-epsilon)
          (double-float double-float-epsilon)
          (double-float double-float-negative-epsilon)
          (long-float long-float-epsilon)
          (long-float long-float-negative-epsilon))
        for val = (symbol-value var)
        unless (typep val type)
        collect (list type var val))
56 57 58 59 60 61
  nil)

(deftest epsilons.6
  (flet ((%check (x) (/= 1.0s0 (+ 1.0s0 x))))
    (let ((eps (float-binary-search #'%check 0.0s0 1.0s0)))
      (if (= eps short-float-epsilon)
sds's avatar
sds committed
62 63
          :good
        (list eps short-float-epsilon))))
64 65 66 67 68 69
  :good)

(deftest epsilons.7
  (flet ((%check (x) (/= 1.0f0 (+ 1.0f0 x))))
    (let ((eps (float-binary-search #'%check 0.0f0 1.0f0)))
      (if (= eps single-float-epsilon)
sds's avatar
sds committed
70 71
          :good
        (list eps single-float-epsilon))))
72 73 74 75 76 77
  :good)

(deftest epsilons.8
  (flet ((%check (x) (/= 1.0d0 (+ 1.0d0 x))))
    (let ((eps (float-binary-search #'%check 0.0d0 1.0d0)))
      (if (= eps double-float-epsilon)
sds's avatar
sds committed
78 79
          :good
        (list eps double-float-epsilon))))
80 81 82 83 84 85
  :good)

(deftest epsilons.9
  (flet ((%check (x) (/= 1.0l0 (+ 1.0l0 x))))
    (let ((eps (float-binary-search #'%check 0.0l0 1.0l0)))
      (if (= eps long-float-epsilon)
sds's avatar
sds committed
86 87
          :good
        (list eps long-float-epsilon))))
88 89 90 91 92 93
  :good)

(deftest epsilons.10
  (flet ((%check (x) (/= 1.0s0 (- 1.0s0 x))))
    (let ((eps (float-binary-search #'%check 0.0s0 1.0s0)))
      (if (= eps short-float-negative-epsilon)
sds's avatar
sds committed
94 95
          :good
        (list eps short-float-negative-epsilon))))
96 97 98 99 100 101
  :good)

(deftest epsilons.11
  (flet ((%check (x) (/= 1.0f0 (- 1.0f0 x))))
    (let ((eps (float-binary-search #'%check 0.0f0 1.0f0)))
      (if (= eps single-float-negative-epsilon)
sds's avatar
sds committed
102 103
          :good
        (list eps single-float-negative-epsilon))))
104 105 106 107 108 109
  :good)

(deftest epsilons.12
  (flet ((%check (x) (/= 1.0d0 (- 1.0d0 x))))
    (let ((eps (float-binary-search #'%check 0.0d0 1.0d0)))
      (if (= eps double-float-negative-epsilon)
sds's avatar
sds committed
110 111
          :good
        (list eps double-float-negative-epsilon))))
112 113 114 115 116 117
  :good)

(deftest epsilons.13
  (flet ((%check (x) (/= 1.0l0 (- 1.0l0 x))))
    (let ((eps (float-binary-search #'%check 0.0l0 1.0l0)))
      (if (= eps long-float-negative-epsilon)
sds's avatar
sds committed
118 119
          :good
        (list eps long-float-negative-epsilon))))
120 121 122 123 124 125
  :good)





sds's avatar
sds committed
126