Created
March 31, 2010 10:52
-
-
Save spockz/350193 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
solveQuadratic :: Double -> Double -> Double -> Intersections | |
solveQuadratic a b c = | |
case compare discr 0.0 of | |
LT -> [] | |
EQ -> [-b / (2 * a)] | |
GT -> [abc (-), abc (+)] | |
where discr = b ^ 2 - 4 * a * c | |
abc op = (-b `op` sqrt discr) / (2 * a) | |
-- vs | |
solveQuadratic :: Double -> Double -> Double -> [Double] | |
solveQuadratic a b c = | |
case compare discr 0.0 of | |
LT -> [] | |
EQ -> [-b / (2 * a)] | |
GT -> [abc (-), abc (+)] | |
where discr = b ^ 2 - 4 * a * c | |
sqrtdiscr = sqrt discr | |
a2 = 2*a | |
abc op = (-b `op` sqrtdiscr) / a2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment