NOTE: This program is in the file complx.cpp.
The roots of a polynomial
are given by the formula:
The following program takes as input three double precision numbers, and returns the complex roots as a pair of values.
typedef complex<double> dcomplex; pair<dcomplex, dcomplex> quadratic (dcomplex a, dcomplex b, dcomplex c) // return the roots of a quadratic equation { dcomplex root = sqrt(b * b - 4.0 * a * c); a *= 2.0; return make_pair( (-b + root)/a, (-b - root)/a); }
OEM Edition, OEM Edition, ©Copyright 1999, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.