www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Unable to explicitly cast imaginary float to a real floating-point (dmd v0.165)

reply "David L. Davis" <SpottedTiger yahoo.com> writes:
// 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 
Aug 30 2006
parent reply Walter Bright <newshound digitalmars.com> writes:
David L. Davis wrote:
 // Unable to explicitly cast a imaginary float to a real floating-point.

r = ift * -1i; should do it.
Aug 30 2006
next sibling parent reply Don Clugston <dac nospam.com.au> writes:
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.
Aug 30 2006
parent "David L. Davis" <SpottedTiger yahoo.com> writes:
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.

Sep 02 2006
prev sibling parent "David L. Davis" <SpottedTiger yahoo.com> writes:
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.

Sep 02 2006