<div dir="ltr"><div class="gmail_extra"><br><br><div class="gmail_quote">On 15 July 2013 11:46, Iain Buclaw <span dir="ltr"><<a href="mailto:ibuclaw@ubuntu.com" target="_blank">ibuclaw@ubuntu.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">But for floor and ceil, at least one of the following must be<br>
available in CTFE to allow setting bits.<br>
<br>
----<br>
// Cannot convert &real to ushort* at compile time<br>
real y = x;<br>
ushort* sh = cast(ushort*)&y;<br></blockquote><div><br><br></div><div>Yeah. The problem with this, is that what happens if somebody stores the pointer? It introduces loads of special cases.<br><br></div><div>The most minimal solution would be to explicitly allow:<br>
<br>ushort e = *(cast ushort *)&y;<br>*(cast ushort *)&y = e;<br><br></div><div>and likewise for getting the raw mantissa into a ulong.<br></div><div>Simply two permissible reads, and two permissible writes, and only for x86. Essentially provides .exp | sign, and .mantissa as writable properties, but without syntax sugar. We could wrap it in a library to create syntax sugar.</div>
<div><br></div><div>It's really a hack, but this is one of those low-level primitives that needs to be provided as a special case, it's kind of an __asm feature.<br></div><div>I think the special case nature of this is unavoidable, it creates a host of problems if you allow general casting.<br>
</div><div><br></div><div></div>We need it for doing atof() at compile-time, too, so providing built-in ceil and floor is not an option.<br></div><br></div></div>