Is there any reason why arithmetic operation on shorts and bytes return int?

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Dec 13 22:19:45 PST 2012


On Thu, Dec 13, 2012 at 05:44:23PM -0800, Walter Bright wrote:
> On 12/13/2012 6:30 AM, Simen Kjaeraas wrote:
> >Walter does not seem to agree (see his post in this discussion).
> 
> Note that the following implementation of halffloat does work,
> allowing explicit cast to halffloat and implicit conversion from.
> (The halffloat literals don't work at the moment because of a
> limitation in CTFE, I'm working with Don to resolve that.)
> -----------------------------------------------------------

Nice!!


[...]
>     /* Provide implicit conversion of HF to float
>      */
> 
>     @property float toFloat() { return shortToFloat(s); }
>     alias toFloat this;
[...]

This is cool, I've never thought of using alias this on a @property
function. I'll have to start using that in my code. :-)

The rest of the code is tl;dr, but I think it does showcase quite well
the power of user-defined types in D. Now we just have to iron out
implicit conversion from literals (and I mean that in general, not just
for this particular example), and it will just be great.


T

-- 
Which is worse: ignorance or apathy? Who knows? Who cares? -- Erich Schubert


More information about the Digitalmars-d mailing list