Thread overview
Unable to explicitly cast imaginary float to a real floating-point (dmd v0.165)
Aug 30, 2006
David L. Davis
Aug 31, 2006
Walter Bright
Aug 31, 2006
Don Clugston
Sep 03, 2006
David L. Davis
Sep 03, 2006
David L. Davis
August 30, 2006
// WinXP SP2, D v0.165
// cast1.d
// Unable to explicitly cast a imaginary float to a real floating-point.
private import std.stdio;

int main()
{
    ifloat ift = 234.67fi;
    real   r  = cast(real)ift;

    writefln("ift=%gi, r=%g", ift, r);

    return 0;
}

Output:
--------
C:\dmd>dmd cast1.d
C:\dmd\bin\..\..\dm\bin\link.exe cast1,,,user32+kernel32/noi;

C:\dmd>cast1
ift=234.67i, r=0

C:\dmd>

-------------------------------------------------------------------
"Dare to reach for the Stars...Dare to Dream, Build, and Achieve!"
-------------------------------------------------------------------

MKoD: http://spottedtiger.tripod.com/D_Language/D_Main_XP.html


August 31, 2006
David L. Davis wrote:
> // Unable to explicitly cast a imaginary float to a real floating-point.

r = ift * -1i;

should do it.
August 31, 2006
Walter Bright wrote:
> David L. Davis wrote:
>> // Unable to explicitly cast a imaginary float to a real floating-point.
> 
> r = ift * -1i;
> 
> should do it.

r = ift.im;

also works.
September 03, 2006
Thxs for the reply Walter. But the cast(real) used to work...why exactly is the reason this doesn't now? I know you changed the implict conversion of imaginary floats so they do not work for a good reason, just unsure why the explict cast() has changed also.

Thanks for your reply in advance.
David L.

-------------------------------------------------------------------
"Dare to reach for the Stars...Dare to Dream, Build, and Achieve!"
-------------------------------------------------------------------

MKoD: http://spottedtiger.tripod.com/D_Language/D_Main_XP.html "Walter Bright" <newshound@digitalmars.com> wrote in message news:ed5le5$1c1c$1@digitaldaemon.com...
> David L. Davis wrote:
>> // Unable to explicitly cast a imaginary float to a real floating-point.
>
> r = ift * -1i;
>
> should do it.


September 03, 2006
Don thanks for pointing that out, but it has little use in templates I'm afraid...the place where I'm having my issue at the moment.

Thanks again for the reply,
David L.

-------------------------------------------------------------------
"Dare to reach for the Stars...Dare to Dream, Build, and Achieve!"
-------------------------------------------------------------------

MKoD: http://spottedtiger.tripod.com/D_Language/D_Main_XP.html "Don Clugston" <dac@nospam.com.au> wrote in message news:ed5vsk$1qad$1@digitaldaemon.com...
> Walter Bright wrote:
>> David L. Davis wrote:
>>> // Unable to explicitly cast a imaginary float to a real floating-point.
>>
>> r = ift * -1i;
>>
>> should do it.
>
> r = ift.im;
>
> also works.