Opened 10 years ago

Last modified 10 years ago

#406 new defect

Multiplication at different safety levels

Reported by: gz Owned by: gb
Priority: normal Milestone:
Component: Compiler Version:
Keywords: Cc:


? (defun test (x y) (* x y 0.05))
? (defun safe-test (x y) (declare (optimize (safety 3))) (* x y 0.05))
? (= (test 30.0 23/20) (safe-test 30.0 23/20))

The problem is that optimization changes the order of args to #'*, and (* 0.05 30.0 23/20) is not the same as (* 30.0 23/20 0.05). The spec gives us latitude to compute (* 30.0 23/20 0.05) in any order, but in practice it'd be helpful if just changing optimization settings didn't result in a different answers.

Change History (1)

comment:1 Changed 10 years ago by hrapof

I think it's unsafe anyway to rely on upon plain #'= to compare floating point numbers, as 0.05 may turn up as 0.04999999999 :) It seems to me people always use some kind of epsilon to make an inexact comparison within certain bounds.

Note: See TracTickets for help on using tickets.