This task has been clarified. Its programming examples are in need of review to ensure that they still fit the requirements of the task.
Write a program to find the roots of a quadratic equation, i.e., solve the equation 



a

x

2


+
b
x
+
c
=
0


{\displaystyle ax^{2}+bx+c=0}

.
Your program must correctly handle non-real roots, but it need not check that 



a
≠
0


{\displaystyle a\neq 0}

.

The problem of solving a quadratic equation is a good example of how dangerous it can be to ignore the peculiarities of floating-point arithmetic.
The obvious way to implement the quadratic formula suffers catastrophic loss of accuracy when one of the roots to be found is much closer to 0 than the other.
In their classic textbook on numeric methods Computer Methods for Mathematical Computations, George Forsythe, Michael Malcolm, and Cleve Moler suggest trying the naive algorithm with 



a
=
1


{\displaystyle a=1}

, 



b
=
−

10

5




{\displaystyle b=-10^{5}}

, and 



c
=
1


{\displaystyle c=1}

.
(For double-precision floats, set 



b
=
−

10

9




{\displaystyle b=-10^{9}}

.)
Consider the following implementation in Ada:

with Ada.Text_IO;                        use Ada.Text_IO;
with Ada.Numerics.Elementary_Functions;  use Ada.Numerics.Elementary_Functions;
 
procedure Quadratic_Equation is
   type Roots is array (1..2) of Float;
   function Solve (A, B, C : Float) return Roots is
      SD : constant Float := sqrt (B**2 - 4.0 * A * C);
      AA : constant Float := 2.0 * A;
   begin
      return ((- B + SD) / AA, (- B - SD) / AA);
   end Solve;
 
   R : constant Roots := Solve (1.0, -10.0E5, 1.0);
begin
   Put_Line ("X1 =" & Float'Image (R (1)) & " X2 =" & Float'Image (R (2)));
end Quadratic_Equation;

Output:
X1 = 1.00000E+06 X2 = 0.00000E+00
As we can see, the second root has lost all significant figures. The right answer is that X2 is about 




10

−
6




{\displaystyle 10^{-6}}

. The naive method is numerically unstable.

Suggested by Middlebrook (D-OA), a better numerical method: to define two parameters 



q
=


a
c



/

b


{\displaystyle q={\sqrt {ac}}/b}

 and 



f
=
1

/

2
+


1
−
4

q

2





/

2


{\displaystyle f=1/2+{\sqrt {1-4q^{2}}}/2}



and the two roots of the quardratic are: 






−
b

a


f


{\displaystyle {\frac {-b}{a}}f}

 and 






−
c


b
f





{\displaystyle {\frac {-c}{bf}}}




Task: do it better. This means that given 



a
=
1


{\displaystyle a=1}

, 



b
=
−

10

9




{\displaystyle b=-10^{9}}

, and 



c
=
1


{\displaystyle c=1}

, both of the roots your program returns should be greater than 




10

−
11




{\displaystyle 10^{-11}}

. Or, if your language can't do floating-point arithmetic any more precisely than single precision, your program should be able to handle 



b
=
−

10

6




{\displaystyle b=-10^{6}}

. Either way, show what your program gives as the roots of the quadratic in question. See page 9 of
"What Every Scientist Should Know About Floating-Point Arithmetic" for a possible algorithm.

' version 20-12-2020
' compile with: fbc -s console
 
#Include Once "gmp.bi"
 
Sub solvequadratic_n(a As Double ,b As Double, c As Double)
 
    Dim As Double f, d = b ^ 2 - 4 * a * c
 
    Select Case Sgn(d)
        Case 0
            Print "1: the single root is "; -b / 2 / a
        Case 1
            Print "1: the real roots are "; (-b + Sqr(d)) / 2 * a; " and ";(-b - Sqr(d)) / 2 * a
        Case -1
            Print "1: the complex roots are "; -b / 2 / a; " +/- "; Sqr(-d) / 2 / a; "*i"
    End Select
 
End Sub
 
Sub solvequadratic_c(a As Double ,b As Double, c As Double)
 
    Dim As Double f, d = b ^ 2 - 4 * a * c
    Select Case Sgn(d)
        Case 0
            Print "2: the single root is "; -b / 2 / a
        Case 1
            f = (1 + Sqr(1 - 4 * a *c / b ^ 2)) / 2
            Print "2: the real roots are ";  -f * b / a; " and "; -c / b / f
        Case -1
            Print "2: the complex roots are "; -b / 2 / a; " +/- "; Sqr(-d) / 2 / a; "*i"
    End Select
End Sub
 
Sub solvequadratic_gmp(a_ As Double ,b_ As Double, c_ As Double)
 
    #Define PRECISION 1024 ' about 300 digits
    #Define MAX 25
 
    Dim As ZString Ptr text
    text = Callocate (1000)
    Mpf_set_default_prec(PRECISION)
 
    Dim As Mpf_ptr a, b, c, d, t
    a = Allocate(Len(__mpf_struct)) : Mpf_init_set_d(a, a_)
    b = Allocate(Len(__mpf_struct)) : Mpf_init_set_d(b, b_)
    c = Allocate(Len(__mpf_struct)) : Mpf_init_set_d(c, c_)
    d = Allocate(Len(__mpf_struct)) : Mpf_init(d)
    t = Allocate(Len(__mpf_struct)) : Mpf_init(t)
 
    mpf_mul(d, b, b)
    mpf_set_ui(t, 4)
    mpf_mul(t, t, a)
    mpf_mul(t, t, c)
    mpf_sub(d, d, t)
 
    Select Case mpf_sgn(d)
        Case 0
            mpf_neg(t, b)
            mpf_div_ui(t, t, 2)
            mpf_div(t, t, a)
            Gmp_sprintf(text,"%.*Fe", MAX, t)
            Print "3: the single root is "; *text
        Case Is > 0
            mpf_sqrt(d, d)
            mpf_add(a, a, a)
            mpf_neg(t, b)
            mpf_add(t, t, d)
            mpf_div(t, t, a)
            Gmp_sprintf(text,"%.*Fe", MAX, t)
            Print "3: the real roots are "; *text; " and ";
            mpf_neg(t, b)
            mpf_sub(t, t, d)
            mpf_div(t, t, a)
            Gmp_sprintf(text,"%.*Fe", MAX, t)
            Print *text
        Case Is < 0
            mpf_neg(t, b)
            mpf_div_ui(t, t, 2)
            mpf_div(t, t, a)
            Gmp_sprintf(text,"%.*Fe", MAX, t)
            Print "3: the complex roots are "; *text; " +/- ";
            mpf_neg(t, d)
            mpf_sqrt(t, t)
            mpf_div_ui(t, t, 2)
            mpf_div(t, t, a)
            Gmp_sprintf(text,"%.*Fe", MAX, t)
            Print *text; "*i"
    End Select
 
End Sub
 
' ------=< MAIN >=------
 
Dim As Double a, b, c
Print "1: is the naieve way"
Print "2: is the cautious way"
Print "3: is the naieve way with help of GMP"
Print
 
For i As Integer = 1 To 10
    Read a, b, c
    Print "Find root(s) for "; Str(a); "X^2"; IIf(b < 0, "", "+");
    Print Str(b); "X"; IIf(c < 0, "", "+"); Str(c)
    solvequadratic_n(a, b , c)
    solvequadratic_c(a, b , c)
    solvequadratic_gmp(a, b , c)
    Print
Next
 
' empty keyboard buffer
While Inkey <> "" : Wend
Print : Print "hit any key to end program"
Sleep
End
 
Data 1, -1E9, 1
Data 1, 0, 1
Data 2, -1, -6
Data 1, 2, -2
Data 0.5, 1.4142135623731, 1
Data 1, 3, 2
Data 3, 4, 5
Data 1, -1e100, 1
Data 1, -1e200, 1
Data 1, -1e300, 1