[Issue 9937] CTFE floats don't overflow correctly

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Aug 22 00:57:28 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=9937



--- Comment #19 from Don <clugdbug at yahoo.com.au> 2013-08-22 00:57:25 PDT ---
(In reply to comment #18)
> (In reply to comment #15)
> > Don, I think we've reached an impasse here. How about we duke it out at Dcon? I
> > think some beers will get us to a solution!
> 
> And the result is....?

Well, we didn't spend much time on it. I've realized a few things since then:

(1) My statement about x87 being the only case where you can get extra
precision, is wrong. Machines with FMA can effectively have twice double
precision on some operations. The 80-precision that DMD currently uses, is
actually not enough, even for x86-64.

(2) We have a few things conflated here.
The most severe bug in the current situation is the example in comment 4: the
compiler acts as though extra bits of precision can be transferred from compile
time to run time. This has a simple solution, see below.

(3) The solution to my initial test case is less clear. There needs to be a way
to reliably dump extra precision from a calculation. Walter's example in
comment 10 is one possibility.

----
Now, to fix comment 4:
All that needs to happen to fix this, is that floating point values should be
rounded to fit the target type *at the end of CTFE*, as part of the existing
scrubbing process.
They should not be carrying extra precision that could not possibly exist at
runtime. This rounding does not apply to const-folding (where things such as
inlining could happen which might preserve more precision).

The philosophy then would be, const-folding never reduces precision below what
the machine can support. But in cases where a CTFE value must be created, such
as in a template value parameter, the result has a single value throughout the
program. Any extra precision it used in generating that value is entirely
CTFE's business and should not leak into the rest of the compiler.

Now that I've split CTFE off completely from const-folding, it's possible to
make this distinction. This would fix the issue in comment 4, but doesn't
affect anything else.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list