TDPL: Overloading template functions

Andrej Mitrovic andrej.mitrovich at gmail.com
Wed Jul 28 14:15:43 PDT 2010


Should I just keep posting my findings in this thread? I hate to make a new
thread for every problem I find..

Anyway, on Page 150, this code fails:

auto f = (int i) {};
assert(is(f == function));

I've checked via typeid(), and f is a delegate by default, not a function.
I've tested it both in a function's scope and in module scope, with the same
results.

On Wed, Jul 28, 2010 at 10:56 PM, Rainer Schuetze <r.sagitario at gmx.de>wrote:

>
> Andrej Mitrovic wrote:
>
>> Woops, I got confused. I was thinking about structs, not arrays.
>>
>>
>> But yeah, in this case a float gets compared to a double and it seems to
>> evaluate to false.
>>
>
> 2.4 has no exact representation as a floating point value, as it is
> 2^^2*0.6, so the mantissa is 3/5. It is rounded after 24 bits for float, but
> after 53 bits for a double. As a result
>
>        float f = 2.4; // approximately 2.4000001
>        double d = 2.4; // approximately 2.3999999999999999
>        assert(f == d);
>
> fails, because the comparison is done after converting the truncated float
> to double (as long as the compiler does not issue SSE instructions with
> single precision).
>
> In contrast, this
>
>        assert(2.4 == 2.4f);
>
> passes, as the compiler keeps real precision until writing the value to
> memory and evaluates the expression at compile time.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20100728/9a2abcea/attachment.html>


More information about the Digitalmars-d mailing list