Opened 13 years ago
Closed 13 years ago
#65 closed defect (fixed)
Different results for EXPT between compiled and interpreted code
| Reported by: | Raymond Toy | Owned by: | somebody |
|---|---|---|---|
| Priority: | major | Milestone: | |
| Component: | Core | Version: | 2012-12 |
| Keywords: | Cc: |
Description (last modified by )
Consider
(defun sqr (x) (declare (type (complex double-float) x)) (expt x 2))
Compare the results:
* (sqr #c(0d0 1d0)) #C(-1d0 0d0) * (expt #c(0d0 1d0) 2) #C(-1.0d0 1.2246467991473532d-16)
The difference is caused by a deftransform for expt that converts (expt x 2) to (* x x).
Perhaps the expt should be modified to do the same transformation when the power is one of the special values in the deftransform? (The deftransform handles 2, 3, 4, and 1/2 and their negatives.)
Change History (4)
comment:1 Changed 13 years ago by
| Description: | modified (diff) |
|---|---|
| Summary: | Different results for {{{expt}}} between compiled and interpreted code → Different results for EXPT between compiled and interpreted code |
comment:2 Changed 13 years ago by
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
comment:3 Changed 13 years ago by
| Resolution: | fixed |
|---|---|
| Status: | closed → reopened |
Some cases were missed in the previous patch. Here is a test that should cover all the cases.
(defun test-expt-xfrm ()
(let (failures)
(dolist (base '(2 2f0 2d0 2w0 #c(0 1) #c(0f0 1) #c(0d0 1) #c(0w0 1)))
(dolist (power '(2 3 1/2 -2 -3 -1/2 5))
(dolist (power-type '(rational single-float double-float double-double-float
(complex single-float) (complex double-float)
(complex double-double-float)))
(let* ((pp (coerce power power-type))
(interp (expt base pp))
(compiled (funcall (compile nil `(lambda (b)
(declare (type ,(type-of base) b))
(expt b ,pp)))
base)))
(unless (= interp compiled)
(push (list base pp interp compiled) failures)
(format t "~S^~S =~% ~S~% ~S~%" base pp interp compiled))))))
failures))
This should return NIL if everything is working correctly.
comment:4 Changed 13 years ago by
| Resolution: | → fixed |
|---|---|
| Status: | reopened → closed |
commit 719e87b7d103d3201c031412de576653a42daff7 Author: Raymond Toy <toy.raymond@…> Date: Thu Jan 24 20:55:45 2013 -0800
Fix ticket:65 some more.
Apply the expt transform in more places. The test script in the ticket now passes.

commit 93656b6aa0ef4e939a84dfb62a6f088f58d3ff62 Author: Raymond Toy <toy.raymond@…> Date: Wed Jan 23 21:22:24 2013 -0800