source: tags/1.6.1/t/decode-float.lisp

Last change on this file was 15249, checked in by Mark Evenson, 4 years ago

t/decode-float: hopefully clarify intent of test

File size: 1.8 KB
Line 
1(in-package :cl-user)
2
3;;; <https://github.com/armedbear/abcl/issues/93>
4(let ((floats `(1f0
5                1f6
6                1f-6
7                ,least-positive-normalized-single-float
8                ,least-positive-single-float)))
9  (prove:plan (length floats))
10  (dolist (float floats)
11    (multiple-value-bind (quotient exponent sign)
12        (decode-float float)
13      (let ((radix (float-radix float)))
14        (let ((lower (/ 1 radix)))
15          (prove:ok
16           (and (< quotient 1)
17                (>= quotient lower))
18           (format nil "Whether ~a lies within (1 ~a]" quotient lower)))))))
19
20;;; <https://github.com/armedbear/abcl/issues/94>
21(let ((floats `(,least-positive-normalized-double-float
22                ,(/ least-positive-normalized-double-float 2)
23                ,(/ least-positive-normalized-double-float 4)
24                ,(/ least-positive-normalized-double-float 8)
25                ,(/ least-positive-normalized-double-float 16)
26                ,(/ least-positive-normalized-double-float 1024))))
27  (prove:plan (length floats))
28  (dolist (float floats)
29    (multiple-value-bind (quotient exponent sign)
30        (decode-float float)
31      (let ((radix (float-radix float)))
32        (let ((lower (/ 1 radix)))
33          (prove:ok
34           (and (< quotient 1)
35                (>= quotient lower))
36           (format nil "Whether ~a lies within  (1 ~a]" quotient lower)))))))
37
38;;; <https://github.com/armedbear/abcl/issues/95>
39(let ((floats `(1d0 ,most-positive-double-float ,least-positive-double-float)))
40  (prove:plan (* 2 (length floats)))
41  (dolist (float floats)
42    (prove:is-type float 'double-float)
43    (let ((result (decode-float float)))
44      (prove:is-type result 'double-float))))
45
46;;; additional things along the way

47
48#|
49Should fail, as you shouldn't be able to
50(decode-float single-float-positive-infinity)
51|# 
52
53(prove:finalize)
Note: See TracBrowser for help on using the repository browser.