www.digitalmars.com         C & C++   DMDScript  

D - imaginary types - what for?

reply Helmut Leitner <leitner hls.via.at> writes:
In a way I fail to understand what the imaginary types
  - ifloat
  - idouble
  - ireal
are for.

I have sometimes used complex numbers - though rarely - in my life, 
but I never came upon applications or mathematical functions that 
used "pure" imaginary parts of numbers.

Could someone explain?

-- 
Helmut Leitner    leitner hls.via.at
Graz, Austria   www.hls-software.com
Apr 10 2003
next sibling parent Ilya Minkov <midiclub tiscali.de> writes:
IIRC imaginary types are fakes. That is, it's only a type for constants, 
which generates complex.

Pure imaginary has also sense, as someone said, because it distinguishes 
between a positve and a negative zero.

-i.

Helmut Leitner wrote:
 In a way I fail to understand what the imaginary types
   - ifloat
   - idouble
   - ireal
 are for.
 
 I have sometimes used complex numbers - though rarely - in my life, 
 but I never came upon applications or mathematical functions that 
 used "pure" imaginary parts of numbers.
 
 Could someone explain?
 

Apr 10 2003
prev sibling next sibling parent Olaf Rogalsky <olaf.rogalsky theorie1.physik.uni-erlangen.de> writes:
Helmut Leitner wrote:
 
 In a way I fail to understand what the imaginary types
   - ifloat
   - idouble
   - ireal
 are for.

-- +----------------------------------------------------------------------+ I Dr. Olaf Rogalsky Institut f. Theo. Physik I I I Tel.: 09131 8528440 Univ. Erlangen-Nuernberg I I Fax.: 09131 8528444 Staudtstrasse 7 B3 I I rogalsky theorie1.physik.uni-erlangen.de D-91058 Erlangen I +----------------------------------------------------------------------+
Apr 10 2003
prev sibling next sibling parent reply "Walter" <walter digitalmars.com> writes:
Having a separate imaginary type is necessary for some calculations that
need to preserve the sign of branch cuts. Multiplying by an imaginary number
doesn't have quite the same semantics as multiplying by  0+yi.

"Helmut Leitner" <leitner hls.via.at> wrote in message
news:3E953FB0.3761738 hls.via.at...
 In a way I fail to understand what the imaginary types
   - ifloat
   - idouble
   - ireal
 are for.

 I have sometimes used complex numbers - though rarely - in my life,
 but I never came upon applications or mathematical functions that
 used "pure" imaginary parts of numbers.

 Could someone explain?

 --
 Helmut Leitner    leitner hls.via.at
 Graz, Austria   www.hls-software.com

Apr 10 2003
parent reply Helmut Leitner <leitner hls.via.at> writes:
Walter wrote:
 
 Having a separate imaginary type is necessary for some calculations that
 need to preserve the sign of branch cuts. Multiplying by an imaginary number
 doesn't have quite the same semantics as multiplying by  0+yi.

I can't understand "sign of branch cuts". Is this an application programming or an implementation issue? -- Helmut Leitner leitner hls.via.at Graz, Austria www.hls-software.com
Apr 11 2003
parent reply "Walter" <walter digitalmars.com> writes:
"Helmut Leitner" <leitner hls.via.at> wrote in message
news:3E967152.A99DD24E hls.via.at...
 Walter wrote:
 Having a separate imaginary type is necessary for some calculations that
 need to preserve the sign of branch cuts. Multiplying by an imaginary


 doesn't have quite the same semantics as multiplying by  0+yi.

Is this an application programming or an implementation issue?

Hopefully, this will explain it better than I can: http://www.cs.berkeley.edu/~wkahan/JAVAhurt.pdf A branch cut (simplisticly) is attempting to draw a distinction between +0 and -0. It comes up a lot in complex arithmetic calculations. Prof. Kahan did another paper on that, but unfortunately it isn't online.
Apr 11 2003
next sibling parent reply Helmut Leitner <leitner hls.via.at> writes:
Walter wrote:
 
 "Helmut Leitner" <leitner hls.via.at> wrote in message
 news:3E967152.A99DD24E hls.via.at...
 Walter wrote:
 Having a separate imaginary type is necessary for some calculations that
 need to preserve the sign of branch cuts. Multiplying by an imaginary


 doesn't have quite the same semantics as multiplying by  0+yi.

Is this an application programming or an implementation issue?

Hopefully, this will explain it better than I can: http://www.cs.berkeley.edu/~wkahan/JAVAhurt.pdf A branch cut (simplisticly) is attempting to draw a distinction between +0 and -0. It comes up a lot in complex arithmetic calculations. Prof. Kahan did another paper on that, but unfortunately it isn't online.

Does this a commitment that D will comply with IEEE 754 (or whatever the latest of floating point processing standards is), better than C, C++ and Java? (Don't know about the state of C#) If yes, it would be an important addition to <http://www.digitalmars.com/d/comparison.html> for those folks dealing with that black art. BTW I think that there should be another two entries to the comparison: - one is something like "native interface" or "native call interface" which means that you can call a OS function directly without a special interface or thunk converting parameters. Neither Java nor C# do. Java defines "jni" (java native interface), a real PITA where you have to create a DLL function for any call you want to make into the native OS libraries. They are a lot of work and they slow down the calls considerably, e. g. from 7 to 40 us for a call to QueryPerformanceCounter (750 Mhz Athlon). C# automates building these interfaces but it doesn't change its nature - they are just as slow as Javas (40 us in the example). This also means that a Java/C# programmer can never resort to small native low level functions when he wants to write software having competitive performance. He must hope that the functions are duplicated in the runtime. Often they aren't. - a point that should IMHO not be hidden is "runtime reflection" which both C# and Java have. -- Helmut Leitner leitner hls.via.at Graz, Austria www.hls-software.com
Apr 11 2003
next sibling parent reply "J. Daniel Smith" <J_Daniel_Smith HoTMaiL.com> writes:
C# allows the use of "unsafe" code which pretty much lets you do anything
you can do in C++ (i.e., pointers are allowed).

Also, I don't think that Microsoft necessarily designed C# to be a super
high-performance language.  If you need absolute performance, use C++ to
create a .NET component that is used from C#; in C++ you have much more
control over the managed/unmanged interface.

   Dan

"Helmut Leitner" <leitner hls.via.at> wrote in message
news:3E96CAD6.6E24AEB4 hls.via.at...
 Walter wrote:
 "Helmut Leitner" <leitner hls.via.at> wrote in message
 news:3E967152.A99DD24E hls.via.at...
 Walter wrote:
 Having a separate imaginary type is necessary for some calculations




 need to preserve the sign of branch cuts. Multiplying by an




 number
 doesn't have quite the same semantics as multiplying by  0+yi.

Is this an application programming or an implementation issue?

Hopefully, this will explain it better than I can: http://www.cs.berkeley.edu/~wkahan/JAVAhurt.pdf A branch cut (simplisticly) is attempting to draw a distinction between


 and -0. It comes up a lot in complex arithmetic calculations. Prof.


 did another paper on that, but unfortunately it isn't online.

Does this a commitment that D will comply with IEEE 754 (or whatever the latest of floating point processing standards is), better than C, C++ and Java? (Don't know about the state of C#) If yes, it would be an important addition to <http://www.digitalmars.com/d/comparison.html> for those folks dealing with that black art. BTW I think that there should be another two entries to the comparison: - one is something like "native interface" or "native call interface" which means that you can call a OS function directly without a special interface or thunk converting parameters. Neither Java nor C# do. Java defines "jni" (java native interface), a real PITA where you have to create a DLL function for any call you want to make into the native OS libraries. They are a lot of work and they slow down the calls considerably, e. g. from 7 to 40 us for a call to QueryPerformanceCounter (750 Mhz Athlon). C# automates building these interfaces but it doesn't change its nature - they are just as slow as Javas (40 us in the example). This also means that a Java/C# programmer can never resort to small native low level functions when he wants to write software having competitive performance. He must hope that the functions are duplicated in the runtime. Often they aren't. - a point that should IMHO not be hidden is "runtime reflection" which both C# and Java have. -- Helmut Leitner leitner hls.via.at Graz, Austria www.hls-software.com

Apr 11 2003
parent reply "Matthew Wilson" <dmd synesis.com.au> writes:
 Also, I don't think that Microsoft necessarily designed C# to be a super
 high-performance language.  If you need absolute performance, use C++ to
 create a .NET component that is used from C#; in C++ you have much more
 control over the managed/unmanged interface.

I can't say I agree with this. The marketing hype squeaks performance, and high-scalable servers, and all that. Also, I've been working on a series of C# performance articles - contrasting with C, C++, D and Java - for WDM (the first instalment goes in in June's issue), and there are a number of areas in which it comes across very well. (And you can take it from me, a committed C++ fan, that I'd not be suggesting this if honesty didn't force me to.) There are also, of course, areas in which it performs very badly. I'm halfway through the series, so it's too early to tell a definitive picture, of course, but it's clear Microsoft have spent a lot of effort in providing competitive efficiency. As regards Managed C++, I think that it's largely a marketing sell to C++ programmers, and to score a psychological blow to "Unmanaged" C++ programmers. I get the argument that it lets one deal with the CLR from C++, rather than C#, but I'm yet to come across something I cannot do in C#, or in C# calling into COM components or C API functions.
Apr 11 2003
parent reply "J. Daniel Smith" <J_Daniel_Smith HoTMaiL.com> writes:
I was trying to counter the notion that you can't get a high performance
application with C#; part of that argument is that you can't consider just
C# by itself, you have to look at all of .NET.  But it sounds like you have
some evidence that even C# by itself isn't as bad as one might think.

   Dan

"Matthew Wilson" <dmd synesis.com.au> wrote in message
news:b7817f$296o$1 digitaldaemon.com...
 Also, I don't think that Microsoft necessarily designed C# to be a super
 high-performance language.  If you need absolute performance, use C++ to
 create a .NET component that is used from C#; in C++ you have much more
 control over the managed/unmanged interface.

I can't say I agree with this. The marketing hype squeaks performance, and high-scalable servers, and all that. Also, I've been working on a series of C# performance articles -

 with C, C++, D and Java - for WDM (the first instalment goes in in June's
 issue), and there are a number of areas in which it comes across very

 (And you can take it from me, a committed C++ fan, that I'd not be
 suggesting this if honesty didn't force me to.) There are also, of course,
 areas in which it performs very badly. I'm halfway through the series, so
 it's too early to tell a definitive picture, of course, but it's clear
 Microsoft have spent a lot of effort in providing competitive efficiency.

 As regards Managed C++, I think that it's largely a marketing sell to C++
 programmers, and to score a psychological blow to "Unmanaged" C++
 programmers. I get the argument that it lets one deal with the CLR from

 rather than C#, but I'm yet to come across something I cannot do in C#, or
 in C# calling into COM components or C API functions.

Apr 14 2003
parent "Matthew Wilson" <dmd synesis.com.au> writes:
It's very patchy. Some things it's good at, some not.


"J. Daniel Smith" <J_Daniel_Smith HoTMaiL.com> wrote in message
news:b7efic$gi4$1 digitaldaemon.com...
 I was trying to counter the notion that you can't get a high performance
 application with C#; part of that argument is that you can't consider just
 C# by itself, you have to look at all of .NET.  But it sounds like you

 some evidence that even C# by itself isn't as bad as one might think.

    Dan

 "Matthew Wilson" <dmd synesis.com.au> wrote in message
 news:b7817f$296o$1 digitaldaemon.com...
 Also, I don't think that Microsoft necessarily designed C# to be a



 high-performance language.  If you need absolute performance, use C++



 create a .NET component that is used from C#; in C++ you have much



 control over the managed/unmanged interface.

I can't say I agree with this. The marketing hype squeaks performance,


 high-scalable servers, and all that.

 Also, I've been working on a series of C# performance articles -

 with C, C++, D and Java - for WDM (the first instalment goes in in


 issue), and there are a number of areas in which it comes across very

 (And you can take it from me, a committed C++ fan, that I'd not be
 suggesting this if honesty didn't force me to.) There are also, of


 areas in which it performs very badly. I'm halfway through the series,


 it's too early to tell a definitive picture, of course, but it's clear
 Microsoft have spent a lot of effort in providing competitive


 As regards Managed C++, I think that it's largely a marketing sell to


 programmers, and to score a psychological blow to "Unmanaged" C++
 programmers. I get the argument that it lets one deal with the CLR from

 rather than C#, but I'm yet to come across something I cannot do in C#,


 in C# calling into COM components or C API functions.


Apr 14 2003
prev sibling parent "Walter" <walter digitalmars.com> writes:
"Helmut Leitner" <leitner hls.via.at> wrote in message
news:3E96CAD6.6E24AEB4 hls.via.at...
 Does this a commitment that D will comply with IEEE 754 (or whatever
 the latest of floating point processing standards is), better than
 C, C++ and Java? (Don't know about the state of C#)

Yes, although C99 has come a long way forward in supporting it.
 If yes, it would be an important addition to
    <http://www.digitalmars.com/d/comparison.html>
 for those folks dealing with that black art.

 BTW I think that there should be another two entries to the comparison:

    - one is something like "native interface" or "native call interface"
      which means that you can call a OS function directly without a
      special interface or thunk converting parameters.

      Neither Java nor C# do. Java defines "jni" (java native interface),
      a real PITA where you have to create a DLL function for any call
      you want to make into the native OS libraries. They are a lot of
      work and they slow down the calls considerably, e. g. from 7 to 40
      us for a call to QueryPerformanceCounter (750 Mhz Athlon).
      C# automates building these interfaces but it doesn't change its
      nature - they are just as slow as Javas (40 us in the example).

      This also means that a Java/C# programmer can never resort to
      small native low level functions when he wants to write software
      having competitive performance. He must hope that the functions
      are duplicated in the runtime. Often they aren't.

    - a point that should IMHO not be hidden is "runtime reflection"
      which both C# and Java have.

Good ideas.
Apr 11 2003
prev sibling parent "Ben Hinkle" <bhinkle4 juno.com> writes:
I don't (yet) buy Kahan's argument that a new type is needed, though. The
library should be able to handle any "smarts" that the type would have.
Basically, the information you get by declaring a variable to be type
"imaginary" is the same as declaring it to be "complex" and testing that it
has zero real part.

Said differently, you can take any algorithm that works just the way you
want on pure imaginary number y*i, call it f(y), and use it in an algorithm,
call it g(x,y), that does the same thing on complex numbers of the form
0+y*i by adding the following test:

if (x == 0) {
  f(y)
} else {
  ...
}

The only difference is that the imaginary class is known at compile time and
the zero test is only known at run time. However if you are computing logs
and sqrts, which is where branch cuts come up, the test is not going to be
significant.

-Ben

"Walter" <walter digitalmars.com> wrote in message
news:b75u4a$rab$1 digitaldaemon.com...
 "Helmut Leitner" <leitner hls.via.at> wrote in message
 news:3E967152.A99DD24E hls.via.at...
 Walter wrote:
 Having a separate imaginary type is necessary for some calculations



 need to preserve the sign of branch cuts. Multiplying by an imaginary


 doesn't have quite the same semantics as multiplying by  0+yi.

Is this an application programming or an implementation issue?

Hopefully, this will explain it better than I can: http://www.cs.berkeley.edu/~wkahan/JAVAhurt.pdf A branch cut (simplisticly) is attempting to draw a distinction between +0 and -0. It comes up a lot in complex arithmetic calculations. Prof. Kahan did another paper on that, but unfortunately it isn't online.

Apr 21 2003
prev sibling parent John Reimer <jj_reimer msn.com> writes:
Helmut Leitner wrote:
 In a way I fail to understand what the imaginary types
   - ifloat
   - idouble
   - ireal
 are for.
 
 I have sometimes used complex numbers - though rarely - in my life, 
 but I never came upon applications or mathematical functions that 
 used "pure" imaginary parts of numbers.
 
 Could someone explain?
 

Separate use of imaginary numbers is often used in complex arithmatic. A simple example in electronics: Inductive reactance X(L) of 5 ohms is described as 5i (or j5 in engineering notation). Capacitive reactance X(C) of -5 ohms is described as -5i (or -j5 in egineering notation) In both above examples XC and XL could be stored in an ifloat, idouble or ireal. Calculating these imaginary values separately in a circuit is always useful. A case in which a capacitor and inductor are in series would produce a net +,-, or 0 Reactance in the circuit when added together (depending on signal frequency). The complete complex number is made when a resistance is combined with the reactance to produce an impedance Z: 2 ohm resistance + 5 ohm (inductive) reactance: 2 + 5i (complex number) ohm. But manipulating in equations may involve calculating imaginary values separately. This is just basic electronic math (well actually electrical). I imagine other fields will come across similar situations, since reality has so many similar applications for mathematical tools. Looking at Walters answer later, I don't really understand the branch cut thing. I'll have to read the link he gave. While complex reactances above could be stored as 0 + 5i or 0 - 5i to form a full complex number, I don't think that is "proper" syntax in electronics. Mind you, I haven't had any success in recombining these ifloat or idouble values into a whole complex number in D which is eventually necessary. I may be wrong in my understanding of this. Hope that helps a little, Later, John
Apr 15 2003