On 18 November 2012 14:51, Artur Skawina <span dir="ltr"><<a href="mailto:art.08.09@gmail.com" target="_blank">art.08.09@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5">On 11/18/12 12:21, Manu wrote:<br>
> I've often wondered about having an official 'half' type.<br>
> It's very common in rendering/image processing, supported by most video cards (so compression routines interacting with this type are common), and it's also supported in hardware by some cpu's.<br>
><br>
> ARM for instance supports 'half's in hardware, and GCC has an __fp16 type which would map nicely if D supported the type in the front end.<br>
><br>
> The alternative us to use ushort everywhere, which is awkward, because it is neither unsigned, nor is it an integer, and it's not typesafe (allows direct assignment to ints and stuff)...<br>
> It would be nice if: cast(half)someFloat would yield the proper value, even if it is performed in software in most architectures, it could be mapped to hardware for those that do it.<br>
><br>
> It could be done in a library, but then GCC couldn't map it properly to the hardware type, and since D has no way to describe implicit casts (that I know of?) it becomes awkward to use.<br>
> someFloat = someHalf <- doesn't work, because a cast operator expects an explicit cast, even though this is a lossless conversion and should be exactly the same as someDouble = someFloat.<br>
><br>
> Thoughts?<br>
<br>
</div></div>   version (GNU) alias half = @gcc[mode(HF)] float;<br>
<br>
But of course this won't work right now, cause that kind of type attributes<br>
aren't supported yet. 'pragma' can't be used on types either (otherwise<br>
something like "alias half = pragma(attribute, mode("HF")) float;" could be<br>
made to work).<br>
<br>
And - yes - the /proper/ way would be eg<br>
<br>
   alias half = @core[size=2] float;<br>
         // or '@core.size(2)' or any other syntax.<br>
<br>
For now, a struct + alias-this-getter might be enough, for a s/w implementation.<br></blockquote><div><br></div><div>Yes, that's what I and everyone else does, but that's not the point of the topic...</div><div>I think it's a fundamental datatype, and it deserves the same casting/type conversion/type safety rules as ints and floats, and it would also be useful to map it to hardware (which GDC can easily do).</div>
</div></div>