<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 15 March 2013 18:35, Johannes Pfau <span dir="ltr"><<a href="mailto:nospam@example.com" target="_blank">nospam@example.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">
Forget what I've said, I somehow read that code as a bitwise/reinterpret<br>
cast but of course the code does an integer/float conversion so it's<br>
probably OK.<br>
<br>
This is more interesting:<br>
<br>
---<br>
    float f = float.infinity;<br>
    float f2 = float.max;<br>
    int i = cast(int) f;<br>
    int i2 = cast(int) f2;<br>
    writefln("0x%x == int.min(0x%x)", i, int.min);<br>
    writefln("0x%x == int.max(0x%x)", cast(int)float.infinity, int.max);<br>
    writefln("0x%x == int.min(0x%x)", i2, int.min);<br>
    writefln("0x%x == int.max(0x%x)", cast(int)float.max, int.max);<br>
---<br>
<br>
const folding expands to int.max, but the same code at runtime expands<br>
to int.min. C does not define what happens if too large float values<br>
are cast into ints. Do you know if D somehow defines this?<br>
<br>
(There's a failing test in the test suite which assumes that the result<br>
is int.min in all cases above)<br>
</blockquote></div><br><br></div><div class="gmail_extra">I think the behaviour from DMD is more incidental than intended.  They use C's FLOAT_INFINITY, etc, macros. But because of the way it's written, gcc doesn't optimise the use of the value.   Whereas with gdc, because it uses gcc's real_t types, values of extreme numbers may change to be either 2147483647 or -2147483648 depending on whether -O is used.  As I said, in most cases you can see the same behaviour in C.<br>
<br></div><div class="gmail_extra">I can see if there might be some flag I can set to try and make gcc's codegen more safe for floats, but that might have impact on runtime.<br></div><div class="gmail_extra"><br></div>
<div class="gmail_extra"><br>-- <br>Iain Buclaw<br><br>*(p < e ? p++ : p) = (c & 0x0f) + '0';
</div></div>