complex numbers - most common ways? 
Author Message
 complex numbers - most common ways?

I am developing a set of functions to do some data manipulation of values
and I personally have some need to do this with complex numbers.  So I
will be including them.  But I do not yet have an established means of
how I use complex numbers.  What I would like to know is what is the
most common methods, and what would be most convenient to other programmers
of C programs that do or may involve complex numbers.

The function I am writing builds binary trees to collect data items.
If you were needing to collect and retrieve by value complex numbers,
possibly associated with other data, would you tend to use structs to
make the complex numbers, or just separate variables?  Would calling
a function to do a lookup based on a complex number be easier by one
or the other of these methods (or by some way I had not considered)?

1.    tree_find_complex( root , real , imaginary );

2.    complex_struct.real = real;
      complex_struct.imaginary = imaginary;
      tree_find_complex( root , complex_struct );

I have the tendency to go with the struct.  But I just want to make sure
that I'm not overlooking some established standards.

--
 --    *-----------------------------*      Phil Howard KA9WGN       *    --
  --   | Inturnet, Inc.              | Director of Internet Services |   --
   --  | Business Internet Solutions |       eng at intur.net        |  --
    -- *-----------------------------*      philh at intur.net       * --



Sun, 21 Jan 2001 03:00:00 GMT  
 complex numbers - most common ways?

   The function I am writing builds binary trees to collect data items.
   If you were needing to collect and retrieve by value complex numbers,
   possibly associated with other data, would you tend to use structs to
   make the complex numbers, or just separate variables?  Would calling
   a function to do a lookup based on a complex number be easier by one
   or the other of these methods (or by some way I had not considered)?

   1.    tree_find_complex( root , real , imaginary );

Convenient if you often use fixed complex values.  i.e., you can just
call tree_find_complex (root, 1, 1) to get 1 + i.

Inconvenient if you need to pass variable complex values often,
because you have to use two arguments to do it in.

   2.    complex_struct.real = real;
         complex_struct.imaginary = imaginary;
         tree_find_complex( root , complex_struct );

The opposite caveats apply here.
--
(supporter of the campaign for grumpiness where grumpiness is due in c.l.c)

Please: do not email me copies of your posts to comp.lang.c
        do not ask me C questions via email; post them instead



Sun, 21 Jan 2001 03:00:00 GMT  
 complex numbers - most common ways?
For complex numbers, you might want to consider C++ or even fortran90.  Both
of those put C to shame in that category.  Here is the complex header
documentation for complex templates in C++:
http://www.dinkumware.com/htm_cpl/complex.html
But, as for normal usage, you will find the struct is more common.  The
Cephes library at http://www.netlib.org has a bunch of complex math routines
and structures already worked out for you.  You might give that a look-see
if you want to do it in C.
--
Hypertext C-FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-FAQ ftp: ftp://rtfm.mit.edu, C-FAQ Book: ISBN 0-201-84519-9
Try "C Programming: A Modern Approach" ISBN 0-393-96945-2
Want Software?  Algorithms?  Pubs? http://www.infoseek.com

Quote:

>I am developing a set of functions to do some data manipulation of values
>and I personally have some need to do this with complex numbers.  So I
>will be including them.  But I do not yet have an established means of
>how I use complex numbers.  What I would like to know is what is the
>most common methods, and what would be most convenient to other programmers
>of C programs that do or may involve complex numbers.

>The function I am writing builds binary trees to collect data items.
>If you were needing to collect and retrieve by value complex numbers,
>possibly associated with other data, would you tend to use structs to
>make the complex numbers, or just separate variables?  Would calling
>a function to do a lookup based on a complex number be easier by one
>or the other of these methods (or by some way I had not considered)?

>1.    tree_find_complex( root , real , imaginary );

>2.    complex_struct.real = real;
>      complex_struct.imaginary = imaginary;
>      tree_find_complex( root , complex_struct );

>I have the tendency to go with the struct.  But I just want to make sure
>that I'm not overlooking some established standards.

>--
> --    *-----------------------------*      Phil Howard KA9WGN
   *    --
>  --   | Inturnet, Inc.              | Director of Internet Services |   --
>   --  | Business Internet Solutions |       eng at intur.net        |  --
>    -- *-----------------------------*      philh at intur.net       * --



Sun, 21 Jan 2001 03:00:00 GMT  
 complex numbers - most common ways?
The most common way to handle complex numbers is to create a structure
to represent them:

struct complex_num
{
  double  real;
  double  imaginary;

Quote:
};

Next, write functions to perform common arithmetic and input / output
using this structure.  The input and output should include binary as
well as ASCII formats.

I suggest placing the structure in a header file along with the function
prototypes and place the functions in a single file.  These could be
compiled and linked into a library for further use.

Also, design and code your functions so that they can be used by
anybody; keep the interfaces simple and general.  Eliminate any and all
side-effects, document the rest.  Remember to test for boundary
conditions and plan an error recovery scheme.

By the way, there are existing libraries for using complex numbers in
C.  Search the web for "complex" and "C language".

Try the following web sites:
http://www.snippets.org
http://www.shareware.com
http://www.iro.umontreal.ca/%7Eratib/code/

Why reinvent the wheel?

--
Thomas Matthews



Mon, 22 Jan 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. gcc and complex numbers

2. Complex numbers in C

3. Complex and Imaginary Numbers

4. Complex numbers

5. Complex numbers C libraries!

6. Complex number manipulation

7. A new twist on the old problem with complex numbers

8. Complex Numbers and C

9. complex numbers

10. complex numbers on C9X

11. complex numbers?

12. library for complex numbers

 

 
Powered by phpBB® Forum Software