On 5/15/2016 9:02 PM, Manu via Digitalmars-d wrote:
Yes, but you don't accidentally use 128bit floats, you type:

extended x = 1.3;
x + y;

The C/C++ standards allow constant folding at 128 bits, despite floats being 32 bits.


If that code were to CTFE, I expect the CTFE to use extended precision.
My point is, CTFE should surely follow the types and language
semantics as if it were runtime generated code... It's not reasonable
that CTFE has higher precision applied than the same code at runtime.
CTFE must give the exact same result as runtime execution of the function.

It hasn't for decades on x86 machines, and the world hasn't collapsed, in fact, few people ever even notice. Not many people prefer less accurate answers.

The initial Java spec worked as you desired, and they were pretty much forced to back off of it.


The belief that compile time and runtime are exactly the same floating point
in C/C++ is false.

I'm not interested in C/C++, I gave some anecdotes where it's gone
wrong for me too, but regardless; generally, they do match, and I
can't think of a single modern example where that's not true. If you
*select* fast-math, then you may generate code that doesn't match, but
that's a deliberate selection.

They won't match on any code that uses the x87. The standard doesn't require float math to use float instructions, they can (and do) use double instructions for temporaries.


If I want 'real' math (in CTFE or otherwise), I will type "real". It
is completely unreasonable to reinterpret the type that the user
specified. CTFE should execute code the same way runtime would execute
the code (without -ffast-math, and conformant ieee hardware). This is
not a big ask.

Incidentally, I made the mistake of mentioning this thread (due to my
astonishment that CTFE ignores float types)

Float types are not selected because they are less accurate, they are selected because they are smaller and faster.

out loud to my
colleagues... and they actually started yelling violently out loud.
One of them has now been on a 10 minute angry rant with elevated tone
and waving his arms around about how he's been shafted by this sort
behaviour so many times before. I wish I recorded it, I'd love to have
submit it as evidence.

I'm interested to hear how he was "shafted" by this. This apparently also contradicts the claim that other languages do as you ask.

Reply via email to