(define (->flonum x)
(guarantee real? x '->flonum)
(exact->inexact (real-part x)))
+
+(define (flo:subnormal? x)
+ (and (flo:finite? x)
+ (not (or (flo:zero? x)
+ (flo:normal? x)))))
+
+(define (flo:classify x)
+ (cond ((not (flo:finite? x)) (if (flo:infinite? x) 'infinite 'nan))
+ ((flo:zero? x) 'zero)
+ ((flo:normal? x) 'normal)
+ (else 'subnormal)))
\f
;;;; Exact integers
(define assert-normal
(predicate-assertion flo:normal? "normal floating-point number"))
-(define (flo:subnormal? x)
- (and (flo:finite? x)
- (not (flo:zero? x))
- (not (flo:normal? x))))
-
(define assert-subnormal
(predicate-assertion flo:subnormal? "subnormal floating-point number"))
(lambda (v)
(let ((z (vector-ref v 0))
(t (vector-ref v 1)))
- (assert-<= (relerr t (angle z)) 1e-15))))
\ No newline at end of file
+ (assert-<= (relerr t (angle z)) 1e-15))))
+
+(define-enumerated-test 'flo:classify
+ `#((0. zero)
+ (-0. zero)
+ (,(flo:nextafter 0. 1.) subnormal)
+ (,flo:smallest-positive-subnormal subnormal)
+ (,flo:smallest-positive-normal normal)
+ (1. normal)
+ (+inf.0 infinite)
+ (-inf.0 infinite)
+ (+nan.0 nan)
+ (-nan.0 nan))
+ (lambda (l)
+ (let ((x (car l))
+ (c (cadr l)))
+ (assert-eq (flo:classify x) c))))
\ No newline at end of file