-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuadraticHelper.cs
More file actions
31 lines (24 loc) · 805 Bytes
/
QuadraticHelper.cs
File metadata and controls
31 lines (24 loc) · 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
namespace ModuleTests
{
public static class QuadraticHelper
{
public static double[] SolveIncompleteQuadraticEquation(double b)
{
if (b < 0)
return new double[0];
var res = Math.Sqrt(b);
return new double[] { res, res * -1 };
}
public static double[] Solve(double a, double b, double c)
{
if (a == default)
throw new ArgumentException("Argument a can not be 0");
double d = b * b - 4 * a * c;
if (d.EqualsExact(0))
throw new ArgumentException("Diskriminant is 0");
var x1 = (-b + Math.Sqrt(d)) / 2 * a;
var x2 = (-b - Math.Sqrt(d)) / 2 * a;
return new double[] { x1, x2 };
}
}
}