epsilons.lsp 3.33 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 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
(deftest epsilons.1
  (loop for e in (list short-float-epsilon single-float-epsilon
		       double-float-epsilon long-float-epsilon)
	when (= (float 1 e) (+ (float 1 e) e))
	collect e)
  nil)

(deftest epsilons.2
  (loop for e in (list short-float-negative-epsilon
		       single-float-negative-epsilon
		       double-float-negative-epsilon
		       long-float-negative-epsilon)
	when (= (float 1 e) (- (float 1 e) e))
	collect e)
  nil)

(deftest epsilons.3
  (loop for e in (list short-float-epsilon single-float-epsilon
		       double-float-epsilon long-float-epsilon)
	unless (= (float 1 e) (+ (float 1 e) (/ e 2)))
	collect e)
  nil)

(deftest epsilons.4
  (loop for e in (list short-float-negative-epsilon
		       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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
  nil)

(deftest epsilons.5
  (loop for (type var) in
	'(
	  (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))
  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)
	  :good
	(list eps short-float-epsilon))))
  :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)
	  :good
	(list eps single-float-epsilon))))
  :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)
	  :good
	(list eps double-float-epsilon))))
  :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)
	  :good
	(list eps long-float-epsilon))))
  :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)
	  :good
	(list eps short-float-negative-epsilon))))
  :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)
	  :good
	(list eps single-float-negative-epsilon))))
  :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)
	  :good
	(list eps double-float-negative-epsilon))))
  :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)
	  :good
	(list eps long-float-negative-epsilon))))
  :good)