#65: Different results for {{{expt}}} between compiled and interpreted code --------------------+------------------------------------------------------- Reporter: rtoy | Owner: somebody Type: defect | Status: new Priority: major | Milestone: Component: Core | Version: 2012-12 Keywords: | --------------------+------------------------------------------------------- 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)) #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.)
#65: Different results for EXPT between compiled and interpreted code --------------------+------------------------------------------------------- Reporter: rtoy | Owner: somebody Type: defect | Status: new Priority: major | Milestone: Component: Core | Version: 2012-12 Keywords: | --------------------+------------------------------------------------------- Description changed by rtoy:
Old description:
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))
#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.)
New description:
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.)
--
#65: Different results for EXPT between compiled and interpreted code ---------------------+------------------------------------------------------ Reporter: rtoy | Owner: somebody Type: defect | Status: closed Priority: major | Milestone: Component: Core | Version: 2012-12 Resolution: fixed | Keywords: ---------------------+------------------------------------------------------ Changes (by toy.raymond@…):
* status: new => closed * resolution: => fixed
Comment:
commit 93656b6aa0ef4e939a84dfb62a6f088f58d3ff62 Author: Raymond Toy toy.raymond@gmail.com Date: Wed Jan 23 21:22:24 2013 -0800
Fix ticket:65. Implement the deftransform in the expt function.
#65: Different results for EXPT between compiled and interpreted code ---------------------+------------------------------------------------------ Reporter: rtoy | Owner: somebody Type: defect | Status: reopened Priority: major | Milestone: Component: Core | Version: 2012-12 Resolution: | Keywords: ---------------------+------------------------------------------------------ Changes (by rtoy):
* status: closed => reopened * resolution: fixed =>
Comment:
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.
#65: Different results for EXPT between compiled and interpreted code ---------------------+------------------------------------------------------ Reporter: rtoy | Owner: somebody Type: defect | Status: closed Priority: major | Milestone: Component: Core | Version: 2012-12 Resolution: fixed | Keywords: ---------------------+------------------------------------------------------ Changes (by toy.raymond@…):
* status: reopened => closed * resolution: => fixed
Comment:
commit 719e87b7d103d3201c031412de576653a42daff7 Author: Raymond Toy toy.raymond@gmail.com 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.