Skip to content

Instantly share code, notes, and snippets.

@macinnir
Created June 14, 2019 00:55
Show Gist options
  • Save macinnir/b65d06af148ab2a59b74a4eec377017d to your computer and use it in GitHub Desktop.
Save macinnir/b65d06af148ab2a59b74a4eec377017d to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"math"
)
func quadratic(a, b, c float64) (d, e float64) {
discriminant := math.Pow(b, 2.0) - 4.0*a*c
divisor := 2.0 * a
d = (-b + math.Sqrt(discriminant)) / divisor
e = (-b - math.Sqrt(discriminant)) / divisor
return
}
func main() {
// 5x^2 + 6x + 1
x1, x2 := quadratic(5, 6, 1)
// -0.2
fmt.Printf("x1 %f\n", x1)
// -1
fmt.Printf("x2 %f\n", x2)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment