From mboxrd@z Thu Jan 1 00:00:00 1970 From: Linus Torvalds To: Cc: , Subject: Re: * Re: What is acceptable for -ffast-math? (Was: associative lawin combine) Date: Sun, 29 Jul 2001 12:52:00 -0000 Message-id: References: X-SW-Source: 2001-07/msg01877.html On Sun, 29 Jul 2001, Stephen L Moshier wrote: > > > Why not make this easier for the user: > > - default to non-IEEE, but "reasonably safe". > > The default GCC behavior is not to allow any optimization > that could change the value of an expression. That rule is easy > for users to understand and surely it is a good rule to keep. > > Floating point arithmetic, IEEE or otherwise, does not obey the > associative or distributive laws. This is YOUR opinion. But most people who write floating point code do not think that way. They consider FP to be "mathematically exact" (which _does_ obey associative and distributive laws), and they write their programs that way. And that is exactly my point: to the people who do not care about the exact details of what it means from a mathematical standpoint, using associative and distributive rules is _fine_. Their algorithms do not care, simply because the person writing the code doesn't even _know_ about the issues of limited precision and range of FP code. See? What I'm saying is that the compiler cannot fix "thinking errors" of the programmer. Trying to fix them is self-defeating and ultimately stupid. I'm claiming that 99%+ of all programmers do not know or care about the fact that (a+b)*c is not necessarily the same as a*c+b*c when we're talking about floating point. My _second_ point is that the ones that DO KNOW and DO CARE are also aware enough that _they_ can be counted on to add a "-mieee" or other flags. They are also knowledgeable enough that they know what "associative law" means, which is already a step up from most programmers, I suspect. So they can understand why the compiler has done an optimization, and can (if it is documented) be instructed to use the appropriate switch for not doing that optimization. So: put the onus of understanding different FP optimizations on the people who CAN understand them. Don't make the average person who wants to do his own small project have to worry about it. By the time the person understands about the range of FP arithmetic enough to care, he will also have the capability to do something about it. Linus