Average Error: 34.0 → 13.6
Time: 7.1s
Precision: binary64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
\[\begin{array}{l} t_0 := \frac{-c}{b}\\ t_1 := \frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_1 \leq -5 \cdot 10^{-267}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_1 \leq 0:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+274}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
(FPCore (a b c)
 :precision binary64
 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
(FPCore (a b c)
 :precision binary64
 (let* ((t_0 (/ (- c) b))
        (t_1 (/ (- (sqrt (+ (* b b) (* c (* a -4.0)))) b) (* a 2.0))))
   (if (<= t_1 (- INFINITY))
     t_0
     (if (<= t_1 -5e-267)
       t_1
       (if (<= t_1 0.0) t_0 (if (<= t_1 2e+274) t_1 t_0))))))
double code(double a, double b, double c) {
	return (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
double code(double a, double b, double c) {
	double t_0 = -c / b;
	double t_1 = (sqrt(((b * b) + (c * (a * -4.0)))) - b) / (a * 2.0);
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = t_0;
	} else if (t_1 <= -5e-267) {
		tmp = t_1;
	} else if (t_1 <= 0.0) {
		tmp = t_0;
	} else if (t_1 <= 2e+274) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
public static double code(double a, double b, double c) {
	return (-b + Math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
public static double code(double a, double b, double c) {
	double t_0 = -c / b;
	double t_1 = (Math.sqrt(((b * b) + (c * (a * -4.0)))) - b) / (a * 2.0);
	double tmp;
	if (t_1 <= -Double.POSITIVE_INFINITY) {
		tmp = t_0;
	} else if (t_1 <= -5e-267) {
		tmp = t_1;
	} else if (t_1 <= 0.0) {
		tmp = t_0;
	} else if (t_1 <= 2e+274) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(a, b, c):
	return (-b + math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a)
def code(a, b, c):
	t_0 = -c / b
	t_1 = (math.sqrt(((b * b) + (c * (a * -4.0)))) - b) / (a * 2.0)
	tmp = 0
	if t_1 <= -math.inf:
		tmp = t_0
	elif t_1 <= -5e-267:
		tmp = t_1
	elif t_1 <= 0.0:
		tmp = t_0
	elif t_1 <= 2e+274:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(a, b, c)
	return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a))
end
function code(a, b, c)
	t_0 = Float64(Float64(-c) / b)
	t_1 = Float64(Float64(sqrt(Float64(Float64(b * b) + Float64(c * Float64(a * -4.0)))) - b) / Float64(a * 2.0))
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = t_0;
	elseif (t_1 <= -5e-267)
		tmp = t_1;
	elseif (t_1 <= 0.0)
		tmp = t_0;
	elseif (t_1 <= 2e+274)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp = code(a, b, c)
	tmp = (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
end
function tmp_2 = code(a, b, c)
	t_0 = -c / b;
	t_1 = (sqrt(((b * b) + (c * (a * -4.0)))) - b) / (a * 2.0);
	tmp = 0.0;
	if (t_1 <= -Inf)
		tmp = t_0;
	elseif (t_1 <= -5e-267)
		tmp = t_1;
	elseif (t_1 <= 0.0)
		tmp = t_0;
	elseif (t_1 <= 2e+274)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_] := Block[{t$95$0 = N[((-c) / b), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], t$95$0, If[LessEqual[t$95$1, -5e-267], t$95$1, If[LessEqual[t$95$1, 0.0], t$95$0, If[LessEqual[t$95$1, 2e+274], t$95$1, t$95$0]]]]]]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\begin{array}{l}
t_0 := \frac{-c}{b}\\
t_1 := \frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;t_0\\

\mathbf{elif}\;t_1 \leq -5 \cdot 10^{-267}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_1 \leq 0:\\
\;\;\;\;t_0\\

\mathbf{elif}\;t_1 \leq 2 \cdot 10^{+274}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 2 regimes
  2. if (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) < -inf.0 or -4.9999999999999999e-267 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) < 0.0 or 1.99999999999999984e274 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a))

    1. Initial program 59.7

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Taylor expanded in b around inf 21.8

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}} \]
    3. Simplified21.8

      \[\leadsto \color{blue}{\frac{-c}{b}} \]

    if -inf.0 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) < -4.9999999999999999e-267 or 0.0 < (/.f64 (+.f64 (neg.f64 b) (sqrt.f64 (-.f64 (*.f64 b b) (*.f64 (*.f64 4 a) c)))) (*.f64 2 a)) < 1.99999999999999984e274

    1. Initial program 4.0

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification13.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2} \leq -\infty:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2} \leq -5 \cdot 10^{-267}:\\ \;\;\;\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\ \mathbf{elif}\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2} \leq 0:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2} \leq 2 \cdot 10^{+274}:\\ \;\;\;\;\frac{\sqrt{b \cdot b + c \cdot \left(a \cdot -4\right)} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]

Reproduce

herbie shell --seed 2022162 
(FPCore (a b c)
  :name "Quadratic roots, full range"
  :precision binary64
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))