Always false float comparisons

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Sat May 21 13:22:20 PDT 2016


On 21.05.2016 19:58, Walter Bright wrote:
> On 5/21/2016 2:26 AM, Tobias Müller wrote:
>> On Friday, 20 May 2016 at 22:22:57 UTC, Walter Bright wrote:
>>> On 5/20/2016 5:36 AM, Tobias M wrote:
>>>> Still an authority, though.
>>>
>>> If we're going to use the fallacy of appeal to authority, may I
>>> present Kahan
>>> who concurrently designed the IEEE 754 spec and the x87.
>>
>> Actually cited this *because* of you mentioning Kahan several times.
>> And because
>> you said "The people who design these things are not fools, and there
>> are good
>> reasons for the way things are."
>
> I meant two things by this:
>
> 1. Do the homework before disagreeing with someone who literally wrote
> the book and designed the hardware for it.
> ...

Sure.

> 2. Complaining that the x87 is not IEEE compliant, when the guy that
> designed the x87 wrote the spec at the same time, suggests a
> misunderstanding the spec.

Who claimed that the x87 is not IEEE compliant? Anyway, this is easy to 
resolve. IEEE 754-2008 requires FMA. x87 has no FMA.


Also, in practice, it is used to produce non-compliant results, as it 
has a default mode of being used that gives you results that differ from 
the specified results for single and double precision sources and 
destinations.

 From IEEE 754-2008:

"1.2 Purpose
1.2.0
This standard provides a method for computation with floating-point 
numbers that will yield the same result whether the processing is done 
in hardware, software, or a combination of the two."

I.e. the only stated purpose of IEEE 754 is actually reproducibility.



"shall indicates mandatory requirements strictly to be followed in order 
to conform to the standard and from which no deviation is permitted 
(“shall” means “is required to”"

"3.1.2 Conformance
3.1.2 .0
A  conforming  implementation  of  any  supported  format  shall 
provide means to initialize that format and shall provide conversions 
between that format and all other supported formats.

A conforming implementation of a supported arithmetic format shall 
provide all the operations of this standard defined in Clause 5, for 
that format.

A conforming implementation of a supported interchange format shall 
provide means to read and write that
format using a specific encoding defined in this clause, for that format.

A programming environment conforms to this standard, in a particular 
radix, by implementing one or more of the basic formats of that radix as 
both a supported arithmetic format and a supported interchange format."


For the original IEEE 754-1985, the x87 seems to support all of those 
clauses for float, double and extended (if you use it in the right way, 
which is inefficient, as you need to spill the result to memory after 
each operation, and it is not the default way), but it also supports 
further operations that fulfill similar functions in a non-conforming 
manner, and compiler implementations use it that way.

Another way to read it is that the x86 conforms by supporting float and 
double as interchange formats and extended as arithmetic format.

What is the correct way to interpret the x87 as conforming?


> I.e. again, gotta do the homework first.
>
> Dismissing several decades of FP designs, and every programming
> language, as being "obviously wrong" and "insane"

No need to unduly generalize the scope of my claims.

> is an extraordinary claim,

Not really. There don't seem to be so many popular systems in computing 
that are not broken in one way or another. (And even when they are, they 
are a lot more useful than nothing. I'd rather have the x87 than no 
hardware floating point support at all.)

> and so requires extraordinary evidence.
> ...

There are several decades of experience with the x87 to draw from. SSE 
does not suffer from those issues anymore. This is because flaws in the 
design were identified and fixed. Why is this evidence not extraordinary 
enough?

> After all, what would your first thought be when a sophomore physics
> student tells you that Feynman got it all wrong?

It's an oddly unspecific statement (what about his work is wrong?) and 
it's a completely different case. Feynman getting everything wrong is 
not a popular sentiment in the Physics community AFAICT.

> It's good to revisit
> existing dogma now and then, and challenge the underlying assumptions of
> it, but again, you gotta understand the existing dogma all the way down
> first.
> ...

What parts of "existing dogma" justify all the problems that x87 causes?
Also, if e.g.implicit 80 bit precision for CTFE floats truly is mandated 
by "floating point dogma" then "floating point dogma" clashes with 
"language design dogma".

> If you don't, you're very likely to miss something fundamental and
> produce a design that is less usable.

I haven't invented anything new either. SSE already fixes the issues.

(But yes, it is probably hard to support systems that only have the x87 
in a sane way. Tradeoffs might be necessary. Deliberately copying 
mistakes that x87 made to other contexts is not the right course of 
action though.)



More information about the Digitalmars-d mailing list