Average Error: 33.8 → 9.7
Time: 6.2s
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 -9.91160972146253504 \cdot 10^{93}:\\ \;\;\;\;\left(2 \cdot \frac{c}{b} - 2 \cdot \frac{b}{a}\right) \cdot \frac{\sqrt{1}}{2}\\ \mathbf{elif}\;b \le 3.86815523717705745 \cdot 10^{-95}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a} \cdot \frac{\sqrt{1}}{2}\\ \mathbf{else}:\\ \;\;\;\;\left(-2 \cdot \frac{c}{b}\right) \cdot \frac{\sqrt{1}}{2}\\ \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 -9.91160972146253504 \cdot 10^{93}:\\
\;\;\;\;\left(2 \cdot \frac{c}{b} - 2 \cdot \frac{b}{a}\right) \cdot \frac{\sqrt{1}}{2}\\

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

\mathbf{else}:\\
\;\;\;\;\left(-2 \cdot \frac{c}{b}\right) \cdot \frac{\sqrt{1}}{2}\\

\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 <= -9.911609721462535e+93)) {
		temp = (((2.0 * (c / b)) - (2.0 * (b / a))) * (sqrt(1.0) / 2.0));
	} else {
		double temp_1;
		if ((b <= 3.8681552371770574e-95)) {
			temp_1 = (((-b + sqrt(((b * b) - ((4.0 * a) * c)))) / a) * (sqrt(1.0) / 2.0));
		} else {
			temp_1 = ((-2.0 * (c / b)) * (sqrt(1.0) / 2.0));
		}
		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 3 regimes
  2. if b < -9.911609721462535e+93

    1. Initial program 45.2

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

      \[\leadsto \color{blue}{\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2 \cdot a}}\]
    4. Using strategy rm
    5. Applied *-commutative45.3

      \[\leadsto \left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{\color{blue}{a \cdot 2}}\]
    6. Applied add-sqr-sqrt45.3

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

      \[\leadsto \left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \color{blue}{\left(\frac{\sqrt{1}}{a} \cdot \frac{\sqrt{1}}{2}\right)}\]
    8. Applied associate-*r*45.3

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

      \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a}} \cdot \frac{\sqrt{1}}{2}\]
    10. Taylor expanded around -inf 3.4

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

    if -9.911609721462535e+93 < b < 3.8681552371770574e-95

    1. Initial program 12.5

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

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

      \[\leadsto \left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{\color{blue}{a \cdot 2}}\]
    6. Applied add-sqr-sqrt12.6

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

      \[\leadsto \left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \color{blue}{\left(\frac{\sqrt{1}}{a} \cdot \frac{\sqrt{1}}{2}\right)}\]
    8. Applied associate-*r*12.6

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

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

    if 3.8681552371770574e-95 < b

    1. Initial program 52.5

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

      \[\leadsto \color{blue}{\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2 \cdot a}}\]
    4. Using strategy rm
    5. Applied *-commutative52.5

      \[\leadsto \left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{\color{blue}{a \cdot 2}}\]
    6. Applied add-sqr-sqrt52.5

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

      \[\leadsto \left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \color{blue}{\left(\frac{\sqrt{1}}{a} \cdot \frac{\sqrt{1}}{2}\right)}\]
    8. Applied associate-*r*52.5

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

      \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a}} \cdot \frac{\sqrt{1}}{2}\]
    10. Taylor expanded around inf 9.2

      \[\leadsto \color{blue}{\left(-2 \cdot \frac{c}{b}\right)} \cdot \frac{\sqrt{1}}{2}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification9.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -9.91160972146253504 \cdot 10^{93}:\\ \;\;\;\;\left(2 \cdot \frac{c}{b} - 2 \cdot \frac{b}{a}\right) \cdot \frac{\sqrt{1}}{2}\\ \mathbf{elif}\;b \le 3.86815523717705745 \cdot 10^{-95}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a} \cdot \frac{\sqrt{1}}{2}\\ \mathbf{else}:\\ \;\;\;\;\left(-2 \cdot \frac{c}{b}\right) \cdot \frac{\sqrt{1}}{2}\\ \end{array}\]

Reproduce

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