Average Error: 34.2 → 6.8
Time: 5.3s
Precision: 64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -5.2389466313579672 \cdot 10^{127}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.78597839720700856 \cdot 10^{-284}:\\ \;\;\;\;\frac{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2}}{a}\\ \mathbf{elif}\;b \le 3.3471968526963819 \cdot 10^{84}:\\ \;\;\;\;\frac{\sqrt[3]{1}}{\frac{\frac{\frac{2}{4}}{c}}{\sqrt[3]{1}}} \cdot \frac{\sqrt[3]{1}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \le -5.2389466313579672 \cdot 10^{127}:\\
\;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\

\mathbf{elif}\;b \le 1.78597839720700856 \cdot 10^{-284}:\\
\;\;\;\;\frac{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2}}{a}\\

\mathbf{elif}\;b \le 3.3471968526963819 \cdot 10^{84}:\\
\;\;\;\;\frac{\sqrt[3]{1}}{\frac{\frac{\frac{2}{4}}{c}}{\sqrt[3]{1}}} \cdot \frac{\sqrt[3]{1}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\

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

\end{array}
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 temp;
	if ((b <= -5.238946631357967e+127)) {
		temp = (1.0 * ((c / b) - (b / a)));
	} else {
		double temp_1;
		if ((b <= 1.7859783972070086e-284)) {
			temp_1 = (((-b + sqrt(((b * b) - ((4.0 * a) * c)))) / 2.0) / a);
		} else {
			double temp_2;
			if ((b <= 3.347196852696382e+84)) {
				temp_2 = ((cbrt(1.0) / (((2.0 / 4.0) / c) / cbrt(1.0))) * (cbrt(1.0) / (-b - sqrt(((b * b) - ((4.0 * a) * c))))));
			} else {
				temp_2 = (-1.0 * (c / b));
			}
			temp_1 = temp_2;
		}
		temp = temp_1;
	}
	return temp;
}

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 4 regimes
  2. if b < -5.238946631357967e+127

    1. Initial program 54.2

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

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

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

    if -5.238946631357967e+127 < b < 1.7859783972070086e-284

    1. Initial program 8.6

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied associate-/r*8.6

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

    if 1.7859783972070086e-284 < b < 3.347196852696382e+84

    1. Initial program 33.1

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied flip-+33.2

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

      \[\leadsto \frac{\frac{\color{blue}{0 + 4 \cdot \left(a \cdot c\right)}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\]
    5. Using strategy rm
    6. Applied clear-num16.7

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

      \[\leadsto \frac{1}{\color{blue}{\frac{2 \cdot a}{4 \cdot \left(a \cdot c\right)} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}\]
    8. Using strategy rm
    9. Applied times-frac16.1

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

      \[\leadsto \frac{1}{\left(\frac{2}{4} \cdot \color{blue}{\frac{1}{c}}\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}\]
    11. Using strategy rm
    12. Applied add-cube-cbrt10.0

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}}{\left(\frac{2}{4} \cdot \frac{1}{c}\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}\]
    13. Applied times-frac9.8

      \[\leadsto \color{blue}{\frac{\sqrt[3]{1} \cdot \sqrt[3]{1}}{\frac{2}{4} \cdot \frac{1}{c}} \cdot \frac{\sqrt[3]{1}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}\]
    14. Simplified9.8

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

    if 3.347196852696382e+84 < b

    1. Initial program 58.6

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification6.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -5.2389466313579672 \cdot 10^{127}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.78597839720700856 \cdot 10^{-284}:\\ \;\;\;\;\frac{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2}}{a}\\ \mathbf{elif}\;b \le 3.3471968526963819 \cdot 10^{84}:\\ \;\;\;\;\frac{\sqrt[3]{1}}{\frac{\frac{\frac{2}{4}}{c}}{\sqrt[3]{1}}} \cdot \frac{\sqrt[3]{1}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;-1 \cdot \frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2020056 +o rules:numerics
(FPCore (a b c)
  :name "Quadratic roots, full range"
  :precision binary64
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))