<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 6 November 2013 09:09, Don <span dir="ltr"><<a href="mailto:x@nospam.com" target="_blank">x@nospam.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div class="im">On Wednesday, 6 November 2013 at 06:28:59 UTC, Walter Bright wrote:<br>
</div><div class="im"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
On 11/5/2013 8:19 AM, Don wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
On Wednesday, 30 October 2013 at 18:28:14 UTC, Walter Bright wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Not exactly what I meant - I mean the algorithm should be designed so that<br>
extra precision does not break it.<br>
</blockquote>
<br>
Unfortunately, that's considerably more difficult than writing an algorithm for<br>
a known precision.<br>
And it is impossible in any case where you need full machine precision (which<br>
applies to practically all library code, and most of my work).<br>
</blockquote>
<br>
I have a hard time buying this. For example, when I wrote matrix inversion code, more precision was always gave more accurate results.<br>
</blockquote>
<br></div>
With matrix inversion you're normally far from full machine precision. If half the bits are correct, you're doing very well.<br>
<br>
The situations I'm referring to, are the ones where the result is correctly rounded, when no extra precision is present. If you then go and add extra precision to some or all of the intermediate results, the results will no longer be correctly rounded.<br>

<br>
eg, the simplest case is rounding to integer:<br>
3.499999999999999999999999999<br>
must round to 3. If you round it twice, you'll get 4.<br>
<br>
But we can test this. I predict that adding some extra bits to the internal calculations in CTFE (to make it have eg 128 bit intermediate values instead of 80), will cause Phobos math unit tests to break.<br>
Perhaps this can already be done trivially in GCC.<div class="im"><br>
<br></div></blockquote><div><br></div><div>The only tests that break in GDC because GCC operates on 160 bit intermediate values are the 80-bit specific tests  (the unittest in std.math with the comment "Note that these are only valid for 80-bit reals").<br>
<br></div><div>Saying that though, GCC isn't exactly IEEE 754 compliant either...<br></div><div><br><br><br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div class="im">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

A compiler intrinsic, which generates no code (simply inserting a barrier for<br>
the optimiser) sounds like the correct approach.<br>
<br>
Coming up for a name for this operation is difficult.<br>
</blockquote>
<br>
float toFloatPrecision(real arg) ?<br>
</blockquote>
<br></div>
Meh. That's wordy and looks like a rounding operation. I'm interested in the operation float -> float and double -> double (and perhaps real->real), where no conversion is happening, and on most architectures it will be a no-op.<br>

<br>
It should be a name that indicates that it's not generating any code,<br>
you're just forbidding the compiler from doing funky weird stuff.<br>
<br>
And for generic code, the name should be the same for float, double, and real.<br>
<br>
Perhaps an attribute rather than a function call.<br>
<br>
double x;<br>
double y = x.strictfloat;<br>
double y = x.strictprecision;<br>
<br>
ie, (expr).strictfloat  would return expr, discarding any extra precision.<br>
That's the best I've come up with so far.<br>
</blockquote></div><br></div><div class="gmail_extra">double y = cast(float) x;  ?  :o)<br><br clear="all"></div><div class="gmail_extra"><br>-- <br>Iain Buclaw<br><br>*(p < e ? p++ : p) = (c & 0x0f) + '0';
</div></div>