Next: Checkoff
Up: Numeric Applications
Previous: DOUBLE PRECISION

Complex Numbers

Fortran supports complex numbers, which can be used (among other things) to represent the square roots of negative numbers. They are used extensively in electrical engineering to describe the behavior of circuits.

Take a look at ``rsqrt.f'' (or view it directly), which reads real numbers from the keyboard and prints out their REAL square roots. Run it a few times, and notice that ``NaN'' is printed out when you enter a negative number. (That stands for ``not a number.'')

Now compare that program to ``csqrt.f'' (or view it directly), which calculates and prints out the COMPLEX square roots of REAL numbers. What are the differences?

Click here for the answer

Notice that Fortran prints a complex number as a pair of real numbers enclosed in parentheses and separated by a comma. If you read COMPLEX numbers with an unformatted READ statement, you enter them from the keyboard in the same way. And if you need to write a COMPLEX constant into your program, you can write it the same way.

Using formatted I/O with complex numbers is quite a bit trickier. You can look at the examples in your book for details.


Next: Checkoff
Up: Numeric Applications
Previous: DOUBLE PRECISION

Hamlet Project
hamlet@cs.utah.edu