Home
Username:
Password:
Advanced C Programming Tutorials

Types of Data / Complex & Imaginary

Subtitles of the Movie

As C was becoming popular through the 1980's and 90's, it had lots of critics and people found all sorts of shortcomings. One of the criticisms was from the scientific community complaining that C had no complex data types. Fortran had them so it was obviously superior. Well, it's true that Fortran has an extremely sophisticated library of mathematical functions. But it was easy enough to write C code that performed complex operations so several people did it. But to do it requires a library of functions. The people who needed complex numbers, and there were not that many of them, wrote their own. They almost all defined the macros named Complex and Imaginary for their declarations. The C99 standards committee decided to add these two new data types to C but there was a problem. Lots of code had already been written and a new standard with these two key words would break the existing code so they gave their names sort of funny spellings. They named them Complex and Imaginary, but they capitalize the first letter of the names and put underscore characters in front of them. These are now language key words. That may seem a bit clumsy to you so if you include the header complex.h, the lowercase simpler names are defined as macros and you can use them instead. I'm not going to try to explain how the complex and imaginary numbers work. That's a number theory I don't want to go into but for those of you who want to be able to perform complex arithmetic, there is a library of C functions for you to do just that. For example, to take the absolute value of a complex number, you call the function C Abs. You might notice that this function call accepts the complex argument and returns a regular floating point number. The same is true for C Arg, which returns the phase angle of N. The function C-E-X-P return the value of E to the nth power where E is the base for natural logarithms. This is C imag which returns the imaginary portion of the complex number and C log return the complex natural logarithm of N. This function returns the complex conjugate of N, the C Pow function returns the complex value raised to the power of B. The function C P-R-O-J returns the projection of N onto the remans sphere. C real returns the real portion of N. The function C Square Root returns the complex square root of the complex value of N. There is also a set of complex trig functions. Functions exist for the complex sine, co-sine and tangent of complex values and also the arc sine, arc co-sine and arc co-tangent. Also functions exist for hyperbolic sine, co-sine and tangent as well as hyperbolic arc sine, arc co-sine and arc co-tangent. But that's not all. Each of these functions has three forms. I showed you one form where all the arguments are doubles. If you use the same function names with the letter F appended on the end, it's defined for floats. For example, the log function is defined for doubles but by using the same function with a letter F, it's defined for floats. Or by appending an L on the name, it's defined for long doubles. I know this means nothing to you if you don't understand or work with complex or imaginary numbers. You can ignore this until you need it. But if you ever do need it, it's here. You don't have to write your own complex function anymore.

Tutorial Information

Course: Advanced C Programming
Author: Arthur Griffith
SKU: 33965
ISBN: 1-935320-24-6
Release Date: 2009-01-30
Duration: 5.5 hrs / 82 lessons
Work Files: Yes
Captions: Available on CD and Online University
Compatibility: Vista/XP/2000, OS X, Linux
QuickTime 7, Flash 8

VTC Sign up & Benefits

  • Unlimited Access
  • 98,729 Video Tutorials (23,265 free)
  • Video Available as Flash or QuickTime
  • Over 1026 Courses
  • $30 for One Month Access
  • Multi-User Discounts Available