Exercise 6.1: Quadratic Roots Function
Given: three real values, a, b, and c, and the furmula for the roots of a quadratic equation
x1 = b + (b**2-4ac)**0.5/2a and
x2 = b - (b**2-4ac)**0.5/2a;
Compose: a function of a, b, and c that calculates and returns the roots or some flag values if the roots cannot be calculated.
function quad.roots( a, b, c : real returns real, real )
let denom = 2.0 * a;
discrim := b * b - 4.0 * a * c;
in if discrim >= 0.0 then
b + sqrt( discrim ) / denom,
b - sqrt( discrim ) / denom
else -9.99e99, -9.99e99
end if
end let
end function
Previous Section
If you have any questions about this page, or want more information about the
Sisal Language Project, contact:
John Feo at (510) 422-6389 or feo@diego.llnl.gov, or
Tom DeBoni at (510) 423-3793 or deboni@llnl.gov.
The Sisal Language Project has been approved as a Designated Unclassified Subject Area (DUSA) K19222, as of 07 August, 1991.
LLNL Disclaimer
UCRL-MI-122601