Ticket #65 (closed defect: fixed)

Opened 20 months ago

Last modified 18 months ago

Different results for EXPT between compiled and interpreted code

Reported by: rtoy Owned by: somebody
Priority: major Milestone:
Component: Core Version: 2012-12
Keywords: Cc:

Description (last modified by rtoy) (diff)

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

Changed 18 months ago by rtoy

  • description modified (diff)
  • summary changed from Different results for {{{expt}}} between compiled and interpreted code to Different results for EXPT between compiled and interpreted code

Changed 18 months ago by toy.raymond@…

  • status changed from new to closed
  • resolution set to fixed

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

Fix ticket:65. Implement the deftransform in the expt function.

Changed 18 months ago by rtoy

  • status changed from closed to reopened
  • resolution fixed deleted

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.

Changed 18 months ago by toy.raymond@…

  • status changed from reopened to closed
  • resolution set to fixed

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.

Note: See TracTickets for help on using tickets.