Article submitted by: Thomas Bejstam for the Delphi Programming Quickies Contest.
Complex Mathematics
When using Delphi to develop engineering applications, you'll often find that the mathematics support in the development environment is not enough. So, what's the way out?
I was dealing with impedances on transmission lines, and the basic formulas for this can be found in most text-books on the subject. However, the mathematics requires complex capabilities, and I decided to write my own
component to support this, TComplexMath.
All complex number has a real and an imaginary part. Therefore the most logical implementation was to use a record, consisting of two real type variables, one for the real part and one for the imaginary part.
The rules for complex mathematics are not any different than those for non-complex mathematics. I actually prefer to see the "normal" non-complex math as a special case. Try using the complex math routines with real
numbers (zero imaginary part), and you'll come up with familiar results. Very simple!
Some properties that can be applied to real numbers, e.g. larger than, smaller than, etc., does not exist for complex numbers, since a complex number is not defined by its size.
I hope this component will turn out useful to you. Go complex!
Download full source code!