Average Error: 33.7 → 14.0
Time: 7.7s
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.3104263752164671 \cdot 10^{+126}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{elif}\;b \leq 5.206062075003178 \cdot 10^{-7}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \frac{4 \cdot a}{\frac{1}{c}}}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;0.25 \cdot \frac{\left(c \cdot a\right) \cdot -4}{a \cdot 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.3104263752164671e+126)
   (- (/ b a))
   (if (<= b 5.206062075003178e-7)
     (/ (+ (- b) (sqrt (- (* b b) (/ (* 4.0 a) (/ 1.0 c))))) (* 2.0 a))
     (* 0.25 (/ (* (* c a) -4.0) (* a 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.3104263752164671e+126) {
		tmp = -(b / a);
	} else if (b <= 5.206062075003178e-7) {
		tmp = (-b + sqrt(((b * b) - ((4.0 * a) / (1.0 / c))))) / (2.0 * a);
	} else {
		tmp = 0.25 * (((c * a) * -4.0) / (a * b));
	}
	return tmp;
}
real(8) function code(a, b, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    code = (-b + sqrt(((b * b) - ((4.0d0 * a) * c)))) / (2.0d0 * a)
end function
real(8) function code(a, b, c)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8), intent (in) :: c
    real(8) :: tmp
    if (b <= (-1.3104263752164671d+126)) then
        tmp = -(b / a)
    else if (b <= 5.206062075003178d-7) then
        tmp = (-b + sqrt(((b * b) - ((4.0d0 * a) / (1.0d0 / c))))) / (2.0d0 * a)
    else
        tmp = 0.25d0 * (((c * a) * (-4.0d0)) / (a * b))
    end if
    code = tmp
end function
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 tmp;
	if (b <= -1.3104263752164671e+126) {
		tmp = -(b / a);
	} else if (b <= 5.206062075003178e-7) {
		tmp = (-b + Math.sqrt(((b * b) - ((4.0 * a) / (1.0 / c))))) / (2.0 * a);
	} else {
		tmp = 0.25 * (((c * a) * -4.0) / (a * b));
	}
	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):
	tmp = 0
	if b <= -1.3104263752164671e+126:
		tmp = -(b / a)
	elif b <= 5.206062075003178e-7:
		tmp = (-b + math.sqrt(((b * b) - ((4.0 * a) / (1.0 / c))))) / (2.0 * a)
	else:
		tmp = 0.25 * (((c * a) * -4.0) / (a * 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.3104263752164671e+126)
		tmp = Float64(-Float64(b / a));
	elseif (b <= 5.206062075003178e-7)
		tmp = Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) / Float64(1.0 / c))))) / Float64(2.0 * a));
	else
		tmp = Float64(0.25 * Float64(Float64(Float64(c * a) * -4.0) / Float64(a * b)));
	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)
	tmp = 0.0;
	if (b <= -1.3104263752164671e+126)
		tmp = -(b / a);
	elseif (b <= 5.206062075003178e-7)
		tmp = (-b + sqrt(((b * b) - ((4.0 * a) / (1.0 / c))))) / (2.0 * a);
	else
		tmp = 0.25 * (((c * a) * -4.0) / (a * b));
	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_] := If[LessEqual[b, -1.3104263752164671e+126], (-N[(b / a), $MachinePrecision]), If[LessEqual[b, 5.206062075003178e-7], N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] / N[(1.0 / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(0.25 * N[(N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision] / N[(a * b), $MachinePrecision]), $MachinePrecision]), $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.3104263752164671 \cdot 10^{+126}:\\
\;\;\;\;-\frac{b}{a}\\

\mathbf{elif}\;b \leq 5.206062075003178 \cdot 10^{-7}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \frac{4 \cdot a}{\frac{1}{c}}}}{2 \cdot a}\\

\mathbf{else}:\\
\;\;\;\;0.25 \cdot \frac{\left(c \cdot a\right) \cdot -4}{a \cdot b}\\


\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 3 regimes
  2. if b < -1.3104263752164671e126

    1. Initial program 53.8

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

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left({\left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)}^{0.25}, {\left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)}^{0.25}, -b\right)}}{2 \cdot a} \]
    3. Applied egg-rr35.0

      \[\leadsto \frac{\color{blue}{\mathsf{hypot}\left(b, \sqrt{-\left(4 \cdot a\right) \cdot c}\right) + \left(-b\right)}}{2 \cdot a} \]
    4. Taylor expanded in b around -inf 3.2

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}} \]
    5. Simplified3.2

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

    if -1.3104263752164671e126 < b < 5.20606207500317804e-7

    1. Initial program 15.3

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

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

    if 5.20606207500317804e-7 < b

    1. Initial program 55.4

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

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left({\left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)}^{0.25}, {\left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)}^{0.25}, -b\right)}}{2 \cdot a} \]
    3. Applied egg-rr48.3

      \[\leadsto \frac{\color{blue}{\mathsf{hypot}\left(b, \sqrt{-\left(4 \cdot a\right) \cdot c}\right) + \left(-b\right)}}{2 \cdot a} \]
    4. Taylor expanded in b around inf 37.1

      \[\leadsto \color{blue}{0.25 \cdot \frac{{\left(\sqrt{-4 \cdot \left(c \cdot a\right)}\right)}^{2}}{a \cdot b}} \]
    5. Simplified16.0

      \[\leadsto \color{blue}{0.25 \cdot \frac{\left(c \cdot a\right) \cdot -4}{a \cdot b}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification14.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.3104263752164671 \cdot 10^{+126}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{elif}\;b \leq 5.206062075003178 \cdot 10^{-7}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \frac{4 \cdot a}{\frac{1}{c}}}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;0.25 \cdot \frac{\left(c \cdot a\right) \cdot -4}{a \cdot b}\\ \end{array} \]

Reproduce

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