Average Error: 34.4 → 6.7
Time: 4.3s
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 -5.948493915058576 \cdot 10^{+108}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq -2.6603754368549326 \cdot 10^{-241}:\\ \;\;\;\;\left(\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b\right) \cdot \frac{0.5}{a}\\ \mathbf{elif}\;b \leq 2.4801938863971876 \cdot 10^{+91}:\\ \;\;\;\;-2 \cdot \frac{c}{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}\\ \mathbf{else}:\\ \;\;\;\;-\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 \leq -5.948493915058576 \cdot 10^{+108}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

\mathbf{elif}\;b \leq -2.6603754368549326 \cdot 10^{-241}:\\
\;\;\;\;\left(\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b\right) \cdot \frac{0.5}{a}\\

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

\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 -5.948493915058576e+108)
   (- (/ c b) (/ b a))
   (if (<= b -2.6603754368549326e-241)
     (* (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (/ 0.5 a))
     (if (<= b 2.4801938863971876e+91)
       (* -2.0 (/ c (+ b (sqrt (- (* b b) (* c (* a 4.0)))))))
       (- (/ c b))))))
double code(double a, double b, double c) {
	return (((double) (((double) -(b)) + ((double) sqrt(((double) (((double) (b * b)) - ((double) (((double) (4.0 * a)) * c)))))))) / ((double) (2.0 * a)));
}
double code(double a, double b, double c) {
	double tmp;
	if ((b <= -5.948493915058576e+108)) {
		tmp = ((double) ((c / b) - (b / a)));
	} else {
		double tmp_1;
		if ((b <= -2.6603754368549326e-241)) {
			tmp_1 = ((double) (((double) (((double) sqrt(((double) (((double) (b * b)) - ((double) (c * ((double) (a * 4.0)))))))) - b)) * (0.5 / a)));
		} else {
			double tmp_2;
			if ((b <= 2.4801938863971876e+91)) {
				tmp_2 = ((double) (-2.0 * (c / ((double) (b + ((double) sqrt(((double) (((double) (b * b)) - ((double) (c * ((double) (a * 4.0)))))))))))));
			} else {
				tmp_2 = ((double) -((c / b)));
			}
			tmp_1 = tmp_2;
		}
		tmp = tmp_1;
	}
	return tmp;
}

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.948493915058576e108

    1. Initial program 49.6

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

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

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

    if -5.948493915058576e108 < b < -2.66037543685493258e-241

    1. Initial program 8.4

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

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

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

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

    if -2.66037543685493258e-241 < b < 2.4801938863971876e91

    1. Initial program 30.1

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

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

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

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

      \[\leadsto \frac{\frac{a \cdot \left(c \cdot -4\right)}{\color{blue}{b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}{a \cdot 2}\]
    7. Using strategy rm
    8. Applied *-un-lft-identity_binary6416.2

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

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

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

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

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

    if 2.4801938863971876e91 < b

    1. Initial program 59.2

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -5.948493915058576 \cdot 10^{+108}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq -2.6603754368549326 \cdot 10^{-241}:\\ \;\;\;\;\left(\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b\right) \cdot \frac{0.5}{a}\\ \mathbf{elif}\;b \leq 2.4801938863971876 \cdot 10^{+91}:\\ \;\;\;\;-2 \cdot \frac{c}{b + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

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