Average Error: 34.0 → 9.9
Time: 7.8s
Precision: binary64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
\[\begin{array}{l} \mathbf{if}\;b \leq -1.2624005950379626 \cdot 10^{+150}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq -1.4196138185551953 \cdot 10^{-103}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)} - b}{a \cdot 2}\\ \mathbf{elif}\;b \leq 1.648410596510835 \cdot 10^{-47}:\\ \;\;\;\;\frac{\mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -4\right)}\right) - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \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
 (if (<= b -1.2624005950379626e+150)
   (/ (- b) a)
   (if (<= b -1.4196138185551953e-103)
     (/ (- (sqrt (fma b b (* c (* a -4.0)))) b) (* a 2.0))
     (if (<= b 1.648410596510835e-47)
       (/ (- (hypot b (sqrt (* a (* c -4.0)))) b) (* a 2.0))
       (/ (- c) b)))))
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 tmp;
	if (b <= -1.2624005950379626e+150) {
		tmp = -b / a;
	} else if (b <= -1.4196138185551953e-103) {
		tmp = (sqrt(fma(b, b, (c * (a * -4.0)))) - b) / (a * 2.0);
	} else if (b <= 1.648410596510835e-47) {
		tmp = (hypot(b, sqrt((a * (c * -4.0)))) - b) / (a * 2.0);
	} else {
		tmp = -c / b;
	}
	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)
	tmp = 0.0
	if (b <= -1.2624005950379626e+150)
		tmp = Float64(Float64(-b) / a);
	elseif (b <= -1.4196138185551953e-103)
		tmp = Float64(Float64(sqrt(fma(b, b, Float64(c * Float64(a * -4.0)))) - b) / Float64(a * 2.0));
	elseif (b <= 1.648410596510835e-47)
		tmp = Float64(Float64(hypot(b, sqrt(Float64(a * Float64(c * -4.0)))) - b) / Float64(a * 2.0));
	else
		tmp = Float64(Float64(-c) / b);
	end
	return 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_] := If[LessEqual[b, -1.2624005950379626e+150], N[((-b) / a), $MachinePrecision], If[LessEqual[b, -1.4196138185551953e-103], N[(N[(N[Sqrt[N[(b * b + N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.648410596510835e-47], N[(N[(N[Sqrt[b ^ 2 + N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] ^ 2], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \leq -1.2624005950379626 \cdot 10^{+150}:\\
\;\;\;\;\frac{-b}{a}\\

\mathbf{elif}\;b \leq -1.4196138185551953 \cdot 10^{-103}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)} - b}{a \cdot 2}\\

\mathbf{elif}\;b \leq 1.648410596510835 \cdot 10^{-47}:\\
\;\;\;\;\frac{\mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -4\right)}\right) - b}{a \cdot 2}\\

\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\


\end{array}

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 4 regimes
  2. if b < -1.26240059503796264e150

    1. Initial program 61.4

      \[\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 2.3

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}} \]
    3. Simplified2.3

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

    if -1.26240059503796264e150 < b < -1.4196138185551953e-103

    1. Initial program 5.8

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Applied egg-rr5.8

      \[\leadsto \frac{\color{blue}{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)} - b}}{2 \cdot a} \]

    if -1.4196138185551953e-103 < b < 1.64841059651083504e-47

    1. Initial program 18.9

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
    2. Simplified19.0

      \[\leadsto \color{blue}{\left(\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -4\right)\right)} - b\right) \cdot \frac{0.5}{a}} \]
    3. Applied egg-rr18.5

      \[\leadsto \color{blue}{\frac{\mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -4\right)}\right) - b}{a \cdot 2}} \]

    if 1.64841059651083504e-47 < b

    1. Initial program 54.6

      \[\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 7.8

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

      \[\leadsto \color{blue}{\frac{-c}{b}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification9.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.2624005950379626 \cdot 10^{+150}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \leq -1.4196138185551953 \cdot 10^{-103}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)} - b}{a \cdot 2}\\ \mathbf{elif}\;b \leq 1.648410596510835 \cdot 10^{-47}:\\ \;\;\;\;\frac{\mathsf{hypot}\left(b, \sqrt{a \cdot \left(c \cdot -4\right)}\right) - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array} \]

Reproduce

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