Thread overview
a complex question
Nov 19, 2005
dennis luehring
Nov 19, 2005
Tomás Rossi
Nov 19, 2005
dennis luehring
Nov 19, 2005
Walter Bright
Nov 19, 2005
dennis luehring
Nov 19, 2005
Manfred Nowak
Nov 19, 2005
dennis luehring
Nov 19, 2005
David L. Davis
November 19, 2005
why can't i write something like this

float a;
float b;

a = do_something(a);
b = do_something(b);

cfloat c = (1+b) + (3*a)i

or

cfloat c = (1+do_something(a)) + (3 * do_something(b))i;

ok i know it is a syntax problem - but why?

maybe with a new syntax?

cfloat c = (1+b) + (3*a)#i

ciao dennis

November 19, 2005
In article <dlnkoi$knk$1@digitaldaemon.com>, dennis luehring says...
>
>why can't i write something like this
>
>float a;
>float b;
>
>a = do_something(a);
>b = do_something(b);
>
>cfloat c = (1+b) + (3*a)i
>
>or
>
>cfloat c = (1+do_something(a)) + (3 * do_something(b))i;
>
>ok i know it is a syntax problem - but why?
>
>maybe with a new syntax?
>
>cfloat c = (1+b) + (3*a)#i

The precious '#' symbol? No, that looks UGLY man!

Tom
November 19, 2005
> The precious '#' symbol? No, that looks UGLY man!

other ideas to solve the problem or syntax changes

cfloat c = 1*b + (a*5)i // or do nobody need this (a*5)i thing
(im not an complex pro. :-))

how can i write this in d (in an clear and handy way)

ciao dennis
November 19, 2005
dennis luehring wrote:

[...]
> maybe with a new syntax?
> cfloat c = (1+b) + (3*a)#i

Why is it so bad to write the usual

cfloat c = (1+b) + (3*a)*1i

???
-manfred
November 19, 2005
In article <dlnkoi$knk$1@digitaldaemon.com>, dennis luehring says...
>
>why can't i write something like this
>
>float a;
>float b;
>
>a = do_something(a);
>b = do_something(b);
>
>cfloat c = (1+b) + (3*a)i
>
>or
>
>cfloat c = (1+do_something(a)) + (3 * do_something(b))i;
>
>ok i know it is a syntax problem - but why?
>
>maybe with a new syntax?
>
>cfloat c = (1+b) + (3*a)#i
>
>ciao dennis
>

It can be done with a small change, see your code modified below:

# // floattest2.d
# // Tested on WinXP SP2 with dmd v0.139
# private import std.stdio;
#
# int main()
# {
#     // float-point numbers are set to a NaN
#     // by the default initializer, init to 0.0f
#     float  a = 0.0f;
#     float  b = 0.0f;
#     cfloat c;
#
#     a = do_something(a);
#     b = do_something(b);
#
#     //cfloat c = (1 + b) + (3 * a)i;
#     c = (1 + b) + (3 * a) * 1.0fi;
#     writefln("c = (1 + b) + (3 * a) * 1.0fi;");
#     writefln("a=%3.2f, b=%3.2f, c=%g", a, b, c);
#     writefln();
#
#     // or
#
#     a = 0.0f;
#     b = 0.0f;
#
#     //cfloat c = (1 + do_something(a)) + (3 * do_something(b))i;
#     c = (1 + do_something(a)) + (3 * do_something(b)) * 1.0fi;
#     writefln("c = (1 + do_something(a)) + (3 * do_something(b)) * 1.0fi;");
#     writefln("do_something(a)=%3.2f, do_something(b)=%3.2f, c=%g",
#               do_something(a), do_something(b), c);
#
#     return 0;
# }
#
# float do_something(in float f) { return f + 1.5f; }
#
Output:
-------------------------
C:\dmd>dmd floattest2.d
C:\dmd\bin\..\..\dm\bin\link.exe floattest2,,,user32+kernel32/noi;

C:\dmd>floattest2
c = (1 + b) + (3 * a) * 1.0fi;
a=1.50, b=1.50, c=2.5+4.5i

c = (1 + do_something(a)) + (3 * do_something(b)) * 1.0fi;
do_something(a)=1.50, do_something(b)=1.50, c=2.5+4.5i

C:\dmd>

Hope you find this sample code useful,
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
November 19, 2005
im so stupid , thank your
November 19, 2005
> The precious '#' symbol? No, that looks UGLY man!

sorry i can use 1i

cfloat c = 1 + (2*3)*1i;

cioa dennis
November 19, 2005
"dennis luehring" <dl.soluz@gmx.net> wrote in message news:dlnmr9$mu4$1@digitaldaemon.com...
> > The precious '#' symbol? No, that looks UGLY man!
>
> other ideas to solve the problem or syntax changes
>
> cfloat c = 1*b + (a*5)i // or do nobody need this (a*5)i thing
> (im not an complex pro. :-))
>
> how can i write this in d (in an clear and handy way)

cfloat c = 1*b + (a*5i);
cfloat c = 1*b + (a*5)*1i;

ifloat i = 1i;
cfloat c = 1*b + (a*5)*i;