## digitalmars.D.bugs - Casting to an imaginary float, zeros out the casted value

• David L. Davis (33/33) Oct 25 2005 # // ift.d dmd v0.137 WinXP SP2
• Walter Bright (5/6) Oct 25 2005 That's the way it's supposed to work, as a real number has a 0 imaginary
• David L. Davis (19/25) Oct 26 2005 Opps!! My mistake Walter...somehow I forgot that the .im of a complex fl...
David L. Davis <SpottedTiger yahoo.com> writes:
```

Output:
----------------
C:\dmd>dmd ift.d

C:\dmd>ift
cr=2.3456e-10+789.675i cr.im=789.675 ift1=0 ift2=789.675
f=789.675 d=789.675 r=789.675
id=0 ir=0

C:\dmd>

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
```
Oct 25 2005
"Walter Bright" <newshound digitalmars.com> writes:
```"David L. Davis" <SpottedTiger yahoo.com> wrote in message
news:djmijl\$1mjj\$1 digitaldaemon.com...

That's the way it's supposed to work, as a real number has a 0 imaginary
part. If you want to take a real number and make an imaginary number out of
it, multiply it by 1i.
```
Oct 25 2005
David L. Davis <SpottedTiger yahoo.com> writes:
```In article <djn4vl\$3ia\$3 digitaldaemon.com>, Walter Bright says...
"David L. Davis" <SpottedTiger yahoo.com> wrote in message
news:djmijl\$1mjj\$1 digitaldaemon.com...

That's the way it's supposed to work, as a real number has a 0 imaginary
part. If you want to take a real number and make an imaginary number out of
it, multiply it by 1i.

Opps!! My mistake Walter...somehow I forgot that the .im of a complex float is
only the value of the imaginary number piece and not itself an imaginary number
value. Yet it seems so natural that it should be an imaginary number value, plus
it seems a bit odd the multiply .im by 1.0i (when im = imaginary number) to make
it an imaginary number. If you know what I mean?

This approach works just fine:
creal cr = 234.56e-12+789.675i;
real   r = cast(real)cr;  // r  = 2.3456e-10
ireal ir = cast(ireal)cr; // ir = 789.675

So why not this, without the need to cast?
real  r  = cr.re; // this works
ireal ir = cr.im; // this won't without a cast(ireal)cr.im * 1.0i

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
```
Oct 26 2005
"Walter Bright" <newshound digitalmars.com> writes:
```"David L. Davis" <SpottedTiger yahoo.com> wrote in message
news:djoc35\$2m8b\$1 digitaldaemon.com...
Opps!! My mistake Walter...somehow I forgot that the .im of a complex

float is
only the value of the imaginary number piece and not itself an imaginary

number
value. Yet it seems so natural that it should be an imaginary number

value, plus
it seems a bit odd the multiply .im by 1.0i (when im = imaginary number)

to make
it an imaginary number. If you know what I mean?

This approach works just fine:
creal cr = 234.56e-12+789.675i;
real   r = cast(real)cr;  // r  = 2.3456e-10
ireal ir = cast(ireal)cr; // ir = 789.675

So why not this, without the need to cast?
real  r  = cr.re; // this works
ireal ir = cr.im; // this won't without a cast(ireal)cr.im * 1.0i

Because cr.im gets the imaginary part *as a real number*, from whence it
follows the rules for real numbers.
```
Oct 26 2005