Permalink
Browse files

Fix bug that would break subnormal encoding

  • Loading branch information...
1 parent 28d2d70 commit 6003349936ef06044e1a437b06c681d7ddcb4fdb @marijnh committed Aug 23, 2012
Showing with 5 additions and 1 deletion.
  1. +1 −1 ieee-floats.lisp
  2. +4 −0 tests.lisp
View
@@ -83,7 +83,7 @@ point numbers anymore, but also keywords."
(sign (if (= sign 1.0) 0 1)))
(unless (< exponent ,(expt 2 exponent-bits))
(error "Floating point overflow when encoding ~A." float))
- (if (< exponent 0) ; (C)
+ (if (<= exponent 0) ; (C)
(values sign (ash (round (* ,(expt 2 significand-bits) significand)) exponent) 0)
(values sign (round (* ,(expt 2 significand-bits) (1- (* significand 2)))) exponent))))))
(let ((bits 0))
View
@@ -31,6 +31,10 @@
(test tiny-32
(pairs-correspond decode-float32 encode-float32
(9.949219e-44 #b00000000000000000000000001000111)))
+
+(test tiny-16
+ (dolist (n '(#b0000001111111111 #b0000001100000000 #b0000001000000000))
+ (is (eql n (encode-float16 (decode-float16 n))))))
(test overflow-32
(signals error

0 comments on commit 6003349

Please sign in to comment.