Always false float comparisons

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Mon May 16 02:56:07 PDT 2016


On 5/16/2016 1:43 AM, Timon Gehr wrote:
> My examples were not contrived.

I don't see where you posted examples in this thread. You did link to two 
wikipedia articles, which seemed to be more conjecture than actual examples.


> Manu's even less so.

Manu has said he's had trouble with it. I believe him. But I haven't seen his 
code to see just what he was doing.


> What you call "illegitimate" are really just legitimate examples that you
> dismiss because they do not match your own specific experience.

Of course, legitimate is a matter of opinion. Can code be written to rely on 
lower precision? Of course. Is it portable to any standard conforming C/C++ 
compiler? Nope. Can algorithms be coded to not require reduced precision? I'm 
pretty sure they can be, and should be.

The links I've posted here make it clear that there is no "obvious" right way 
for compilers to implement FP. If you're going to write sensitive FP algorithms, 
it only makes sense to take the arbitrariness of FP implementations into account.

My proposal for D means less is implementation defined than C/C++, the semantics 
fall within the "implementation defined" part of the C/C++ standards, and the 
implementation is completely IEEE compliant.

I don't believe it is a service to programmers to have the panopoly of FP 
behavior switches sported by typical compilers that apparently very few people 
understand. Worse, writing code that is invisibly, subtly, and critically 
dependent on specific compiler switches and versions is not something I can 
recommend as a best practice.


 > I think that's a little disrespectful.

Perhaps, but disrespecting code is not an ad homenim argument.


More information about the Digitalmars-d mailing list