Commit 04797b84 authored by pfdietz's avatar pfdietz
Browse files

Added float/nearby rational comparison tests

parent ac9c057c
......@@ -157,6 +157,47 @@
collect (list a b c d)))
nil)
;;; Comparison of a rational with a float
(deftest =.17
(loop for x in '(1.0s0 1.0f0 1.0d0 1.0l0)
for eps in (list short-float-epsilon single-float-epsilon
double-float-epsilon long-float-epsilon)
for exp = (nth-value 1 (decode-float eps))
for radix = (float-radix eps)
when (< (* (log radix 2) exp) 1000)
nconc
(let* ((rat (rational eps))
(xrat (rational x)))
(loop for i from 2 to 100
for rat/i = (/ rat i)
for xrat+rat/i = (+ xrat rat/i)
nconc
(if (= x xrat+rat/i)
(list (list x i xrat+rat/i))
nil))))
nil)
(deftest =.18
(loop for x in '(1.0s0 1.0f0 1.0d0 1.0l0)
for eps in (list short-float-negative-epsilon single-float-negative-epsilon
double-float-negative-epsilon long-float-negative-epsilon)
for exp = (nth-value 1 (decode-float eps))
for radix = (float-radix eps)
when (< (* (log radix 2) exp) 1000)
nconc
(let* ((rat (rational eps))
(xrat (rational x)))
(loop for i from 2 to 100
for rat/i = (/ rat i)
for xrat-rat/i = (- xrat rat/i)
nconc
(if (= x xrat-rat/i)
(list (list x i xrat-rat/i))
nil))))
nil)
(deftest =.order.1
(let ((i 0) x y)
(values
......@@ -300,6 +341,45 @@
collect (list x y))))
nil)
(deftest /=.17
(loop for x in '(1.0s0 1.0f0 1.0d0 1.0l0)
for eps in (list short-float-epsilon single-float-epsilon
double-float-epsilon long-float-epsilon)
for exp = (nth-value 1 (decode-float eps))
for radix = (float-radix eps)
when (< (* (log radix 2) exp) 1000)
nconc
(let* ((rat (rational eps))
(xrat (rational x)))
(loop for i from 2 to 100
for rat/i = (/ rat i)
for xrat+rat/i = (+ xrat rat/i)
nconc
(if (/= x xrat+rat/i)
nil
(list (list x i xrat+rat/i))))))
nil)
(deftest /=.18
(loop for x in '(1.0s0 1.0f0 1.0d0 1.0l0)
for eps in (list short-float-negative-epsilon single-float-negative-epsilon
double-float-negative-epsilon long-float-negative-epsilon)
for exp = (nth-value 1 (decode-float eps))
for radix = (float-radix eps)
when (< (* (log radix 2) exp) 1000)
nconc
(let* ((rat (rational eps))
(xrat (rational x)))
(loop for i from 2 to 100
for rat/i = (/ rat i)
for xrat-rat/i = (- xrat rat/i)
nconc
(if (/= x xrat-rat/i)
nil
(list (list x i xrat-rat/i))))))
nil)
(deftest /=.order.1
(let ((i 0) x y)
(values
......@@ -511,6 +591,45 @@
(< x (- x))))
t)
(deftest <.17
(loop for x in '(1.0s0 1.0f0 1.0d0 1.0l0)
for eps in (list short-float-epsilon single-float-epsilon
double-float-epsilon long-float-epsilon)
for exp = (nth-value 1 (decode-float eps))
for radix = (float-radix eps)
when (< (* (log radix 2) exp) 1000)
nconc
(let* ((rat (rational eps))
(xrat (rational x)))
(loop for i from 2 to 100
for rat/i = (/ rat i)
for xrat+rat/i = (+ xrat rat/i)
nconc
(if (< x xrat+rat/i)
nil
(list (list x i xrat+rat/i))))))
nil)
(deftest <.18
(loop for x in '(1.0s0 1.0f0 1.0d0 1.0l0)
for eps in (list short-float-negative-epsilon single-float-negative-epsilon
double-float-negative-epsilon long-float-negative-epsilon)
for exp = (nth-value 1 (decode-float eps))
for radix = (float-radix eps)
when (< (* (log radix 2) exp) 1000)
nconc
(let* ((rat (rational eps))
(xrat (rational x)))
(loop for i from 2 to 100
for rat/i = (/ rat i)
for xrat-rat/i = (- xrat rat/i)
nconc
(if (< x xrat-rat/i)
(list (list x i xrat-rat/i))
nil))))
nil)
(deftest <.order.1
(let ((i 0) x y)
(values
......@@ -718,6 +837,44 @@
(<= x (- x))))
t)
(deftest <=.17
(loop for x in '(1.0s0 1.0f0 1.0d0 1.0l0)
for eps in (list short-float-epsilon single-float-epsilon
double-float-epsilon long-float-epsilon)
for exp = (nth-value 1 (decode-float eps))
for radix = (float-radix eps)
when (< (* (log radix 2) exp) 1000)
nconc
(let* ((rat (rational eps))
(xrat (rational x)))
(loop for i from 2 to 100
for rat/i = (/ rat i)
for xrat+rat/i = (+ xrat rat/i)
nconc
(if (<= x xrat+rat/i)
nil
(list (list x i xrat+rat/i))))))
nil)
(deftest <=.18
(loop for x in '(1.0s0 1.0f0 1.0d0 1.0l0)
for eps in (list short-float-negative-epsilon single-float-negative-epsilon
double-float-negative-epsilon long-float-negative-epsilon)
for exp = (nth-value 1 (decode-float eps))
for radix = (float-radix eps)
when (< (* (log radix 2) exp) 1000)
nconc
(let* ((rat (rational eps))
(xrat (rational x)))
(loop for i from 2 to 100
for rat/i = (/ rat i)
for xrat-rat/i = (- xrat rat/i)
nconc
(if (<= x xrat-rat/i)
(list (list x i xrat-rat/i))
nil))))
nil)
(deftest <=.order.1
(let ((i 0) x y)
(values
......@@ -808,6 +965,44 @@
(> x (- x))))
t)
(deftest >.17
(loop for x in '(1.0s0 1.0f0 1.0d0 1.0l0)
for eps in (list short-float-epsilon single-float-epsilon
double-float-epsilon long-float-epsilon)
for exp = (nth-value 1 (decode-float eps))
for radix = (float-radix eps)
when (< (* (log radix 2) exp) 1000)
nconc
(let* ((rat (rational eps))
(xrat (rational x)))
(loop for i from 2 to 100
for rat/i = (/ rat i)
for xrat+rat/i = (+ xrat rat/i)
nconc
(if (> x xrat+rat/i)
(list (list x i xrat+rat/i))
nil))))
nil)
(deftest >.18
(loop for x in '(1.0s0 1.0f0 1.0d0 1.0l0)
for eps in (list short-float-negative-epsilon single-float-negative-epsilon
double-float-negative-epsilon long-float-negative-epsilon)
for exp = (nth-value 1 (decode-float eps))
for radix = (float-radix eps)
when (< (* (log radix 2) exp) 1000)
nconc
(let* ((rat (rational eps))
(xrat (rational x)))
(loop for i from 2 to 100
for rat/i = (/ rat i)
for xrat-rat/i = (- xrat rat/i)
nconc
(if (> x xrat-rat/i)
nil
(list (list x i xrat-rat/i))))))
nil)
(deftest >.order.1
(let ((i 0) x y)
(values
......@@ -900,6 +1095,45 @@
(>= x (- x))))
t)
(deftest >=.17
(loop for x in '(1.0s0 1.0f0 1.0d0 1.0l0)
for eps in (list short-float-epsilon single-float-epsilon
double-float-epsilon long-float-epsilon)
for exp = (nth-value 1 (decode-float eps))
for radix = (float-radix eps)
when (< (* (log radix 2) exp) 1000)
nconc
(let* ((rat (rational eps))
(xrat (rational x)))
(loop for i from 2 to 100
for rat/i = (/ rat i)
for xrat+rat/i = (+ xrat rat/i)
nconc
(if (>= x xrat+rat/i)
(list (list x i xrat+rat/i))
nil))))
nil)
(deftest >=.18
(loop for x in '(1.0s0 1.0f0 1.0d0 1.0l0)
for eps in (list short-float-negative-epsilon single-float-negative-epsilon
double-float-negative-epsilon long-float-negative-epsilon)
for exp = (nth-value 1 (decode-float eps))
for radix = (float-radix eps)
when (< (* (log radix 2) exp) 1000)
nconc
(let* ((rat (rational eps))
(xrat (rational x)))
(loop for i from 2 to 100
for rat/i = (/ rat i)
for xrat-rat/i = (- xrat rat/i)
nconc
(if (>= x xrat-rat/i)
nil
(list (list x i xrat-rat/i))))))
nil)
(deftest >=.order.1
(let ((i 0) x y)
(values
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment