Roots of a quadratic function: Difference between revisions
Content added Content deleted
MaiconSoft (talk | contribs) m (Added Delphi reference to Pascal code) |
m (→{{header|Haskell}}: Tidied, applying Ormolu.) |
||
Line 998: | Line 998: | ||
quadraticRoots :: (CD, CD, CD) -> (CD, CD) |
quadraticRoots :: (CD, CD, CD) -> (CD, CD) |
||
quadraticRoots (a, b, c) |
quadraticRoots (a, b, c) |
||
| 0 < realPart b = |
|||
( (2 * c) / (- b - d), |
|||
(- b - d) / (2 * a) |
|||
) |
|||
| otherwise = |
|||
( (- b + d) / (2 * a), |
|||
(2 * c) / (- b + d) |
|||
) |
|||
where |
where |
||
d = sqrt $ b ^ 2 - 4 * a * c |
d = sqrt $ b ^ 2 - 4 * a * c |
||
Line 1,009: | Line 1,014: | ||
mapM_ |
mapM_ |
||
(print . quadraticRoots) |
(print . quadraticRoots) |
||
[(3, 4, 4 / 3), |
[ (3, 4, 4 / 3), |
||
(3, 2, -1), |
|||
(3, 2, 1), |
|||
(1, -10e5, 1), |
|||
(1, -10e9, 1) |
|||
]</lang> |
|||
{{Out}} |
{{Out}} |
||
<pre>((-0.6666666666666666) :+ 0.0,(-0.6666666666666666) :+ 0.0) |
<pre>((-0.6666666666666666) :+ 0.0,(-0.6666666666666666) :+ 0.0) |