Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
ansi-test
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michał Herda
ansi-test
Commits
2b5d10f0
Commit
2b5d10f0
authored
20 years ago
by
pfdietz
Browse files
Options
Downloads
Patches
Plain Diff
Tests of floats and big rationals
parent
d6031558
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ansi-tests/number-comparison.lsp
+247
-1
247 additions, 1 deletion
ansi-tests/number-comparison.lsp
with
247 additions
and
1 deletion
ansi-tests/number-comparison.lsp
+
247
−
1
View file @
2b5d10f0
...
@@ -1342,4 +1342,250 @@
...
@@ -1342,4 +1342,250 @@
(list (list x i))))))
(list (list x i))))))
nil)
nil)
;;; To add ... comparisons of large rationals with floats
(deftest bignum.float.compare.7
\ No newline at end of file
(let ((toobig (loop for x in *reals*
collect (and (> (abs x) 1.0)
(> (abs (log (abs x))) 10000)))))
(loop for x in *reals*
for xtoobig in toobig
nconc
(unless xtoobig
(let ((fx (floor x)))
(loop for y in *reals*
for ytoobig in toobig
when (and (not ytoobig)
(< x y)
(or (not (< fx y))
(<= y fx)
(not (> y fx))
(>= fx y)))
collect (list x y))))))
nil)
(deftest bignum.float.compare.8
(let ((toobig (loop for x in *reals*
collect (and (> (abs x) 1.0)
(> (abs (log (abs x))) 10000)))))
(loop for x in *reals*
for xtoobig in toobig
nconc
(unless xtoobig
(let ((fx (floor x)))
(loop for y in *reals*
for ytoobig in toobig
when (and (not ytoobig)
(<= x y)
(or (not (<= fx y))
(> fx y)
(not (>= y fx))
(< y fx)))
collect (list x y))))))
nil)
;;; More randomized comparisons
(deftest bignum.short-float.random.compare.1
(let* ((integer-bound (ash 1 1000))
(upper-bound (if (< (/ most-positive-short-float 2) integer-bound)
(/ most-positive-short-float 2)
(coerce integer-bound 'short-float))))
(loop for bound = 1.0s0 then (* bound 2)
while (<= bound upper-bound)
nconc
(loop for r = (random bound)
for fr = (floor r)
for cr = (ceiling r)
repeat 20
unless (and (<= fr r cr)
(if (= r fr)
(= r cr)
(/= r cr))
(>= cr r fr))
collect (list r fr cr))))
nil)
(deftest bignum.single-float.random.compare.1
(let* ((integer-bound (ash 1 100))
(upper-bound (if (< (/ most-positive-single-float 2) integer-bound)
(/ most-positive-single-float 2)
(coerce integer-bound 'single-float))))
(loop for bound = 1.0f0 then (* bound 2)
while (<= bound upper-bound)
nconc
(loop for r = (random bound)
for fr = (floor r)
for cr = (ceiling r)
repeat 20
unless (and (<= fr r cr)
(if (= r fr)
(= r cr)
(/= r cr))
(>= cr r fr))
collect (list r fr cr))))
nil)
(deftest bignum.double-float.random.compare.1
(let* ((integer-bound (ash 1 100))
(upper-bound (if (< (/ most-positive-double-float 2) integer-bound)
(/ most-positive-double-float 2)
(coerce integer-bound 'double-float))))
(loop for bound = 1.0d0 then (* bound 2)
while (<= bound upper-bound)
nconc
(loop for r = (random bound)
for fr = (floor r)
for cr = (ceiling r)
repeat 20
unless (and (<= fr r cr)
(if (= r fr)
(= r cr)
(/= r cr))
(>= cr r fr))
collect (list r fr cr))))
nil)
(deftest bignum.long-float.random.compare.1
(let* ((integer-bound (ash 1 100))
(upper-bound (if (< (/ most-positive-long-float 2) integer-bound)
(/ most-positive-long-float 2)
(coerce integer-bound 'long-float))))
(loop for bound = 1.0l0 then (* bound 2)
while (< bound upper-bound)
nconc
(loop for r = (random bound)
for fr = (floor r)
for cr = (ceiling r)
repeat 20
unless (and (<= fr r cr)
(if (= r fr)
(= r cr)
(/= r cr))
(>= cr r fr))
collect
(list r fr cr))))
nil)
;;; Rational/float comparisons
(deftest rational.short-float.random.compare.1
(let* ((integer-bound (ash 1 1000))
(upper-bound (if (< (/ most-positive-short-float 2) integer-bound)
(/ most-positive-short-float 2)
(coerce integer-bound 'short-float))))
(loop for bound = 1.0s0 then (* bound 2)
while (<= bound upper-bound)
nconc
(loop for r = (+ 1.s0 (random bound))
for fr = (floor r)
for cr = (ceiling r)
for m = (ash 1 (1+ (random 30)))
for p = (1+ (random m))
for q = (1+ (random m))
for x = 0
repeat 50
when (<= p q) do (psetf p (1+ q) q p)
do (setf x (/ p q))
unless (let ((fr/x (/ fr x))
(cr*x (* cr x)))
(and (<= fr/x r cr*x)
(< fr/x r cr*x)
(> cr*x r fr/x)
(>= cr*x r fr/x)))
collect (list r p q x fr cr))))
nil)
(deftest rational.single-float.random.compare.1
(let* ((integer-bound (ash 1 1000))
(upper-bound (if (< (/ most-positive-single-float 2) integer-bound)
(/ most-positive-single-float 2)
(coerce integer-bound 'single-float))))
(loop for bound = 1.0f0 then (* bound 2)
while (<= bound upper-bound)
nconc
(loop for r = (+ 1.s0 (random bound))
for fr = (floor r)
for cr = (ceiling r)
for m = (ash 1 (1+ (random 30)))
for p = (1+ (random m))
for q = (1+ (random m))
for x = 0
repeat 50
when (<= p q) do (psetf p (1+ q) q p)
do (setf x (/ p q))
unless (let ((fr/x (/ fr x))
(cr*x (* cr x)))
(and (<= fr/x r cr*x)
(< fr/x r cr*x)
(> cr*x r fr/x)
(>= cr*x r fr/x)))
collect (list r p q x fr cr))))
nil)
(deftest rational.double-float.random.compare.1
(let* ((integer-bound (ash 1 1000))
(upper-bound (if (< (/ most-positive-double-float 4) integer-bound)
(/ most-positive-double-float 4)
(coerce integer-bound 'double-float))))
(loop for bound = 1.0d0 then (* bound 4)
while (<= bound upper-bound)
nconc
(loop for r = (+ 1.s0 (random bound))
for fr = (floor r)
for cr = (ceiling r)
for m = (ash 1 (1+ (random 30)))
for p = (1+ (random m))
for q = (1+ (random m))
for x = 0
repeat 50
when (<= p q) do (psetf p (1+ q) q p)
do (setf x (/ p q))
unless (let ((fr/x (/ fr x))
(cr*x (* cr x)))
(and (<= fr/x r cr*x)
(< fr/x r cr*x)
(> cr*x r fr/x)
(>= cr*x r fr/x)))
collect (list r p q x fr cr))))
nil)
(deftest rational.long-float.random.compare.1
(let* ((integer-bound (ash 1 1000))
(upper-bound (if (< (/ most-positive-long-float 4) integer-bound)
(/ most-positive-long-float 4)
(coerce integer-bound 'long-float))))
(loop for bound = 1.0d0 then (* bound 4)
while (<= bound upper-bound)
nconc
(loop for r = (+ 1.s0 (random bound))
for fr = (floor r)
for cr = (ceiling r)
for m = (ash 1 (1+ (random 30)))
for p = (1+ (random m))
for q = (1+ (random m))
for x = 0
repeat 50
when (<= p q) do (psetf p (1+ q) q p)
do (setf x (/ p q))
unless (let ((fr/x (/ fr x))
(cr*x (* cr x)))
(and (<= fr/x r cr*x)
(< fr/x r cr*x)
(> cr*x r fr/x)
(>= cr*x r fr/x)))
collect (list r p q x fr cr))))
nil)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment