On 08/05/18 20:35, Marc Glisse wrote: > On Sun, 5 Aug 2018, Bernd Edlinger wrote: > >>> merging log a + log b => log a*b and >> >> Maybe a*b could overflow, while adding the logarithms would not? > > Well, that's a discussion that happens every time a new transformation is > added to -funsafe-math-optimizations (I assume this one is under that > umbrella?). We already may get extra overflow with -fassociative-math for > instance. Sure, the overflow (or underflow!) is more likely for log than for > addition, but this still seems like the kind of transformation that > -ffast-math should enable, in my opinion. Now we can see if I am in the > minority... >
Yes, this should be unsafe-math Regarding the second transformation, I think it is invalid. I tried in sage: sage: a=2 sage: b=3 sage: x=5 sage: y=6 sage: p = x*log(a) + y*log(b) sage: q = x*y*log(a*b) sage: print p 6*log(3) + 5*log(2) sage: print q 30*log(6) sage: print numerical_approx(p) 10.0574096348084 sage: print numerical_approx(q) 53.7527840768416 Bernd.