Average Error: 33.8 → 6.8
Time: 11.4s
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 -3.7715774085615172 \cdot 10^{+37}:\\ \;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_0 := \sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c}\\ \mathbf{if}\;b \leq -1.9357207753357807 \cdot 10^{-308}:\\ \;\;\;\;\frac{t_0}{2 \cdot a} - \frac{b}{2 \cdot a}\\ \mathbf{elif}\;b \leq 2.3431308109665615 \cdot 10^{+85}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - t_0}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\\ \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 -3.7715774085615172 \cdot 10^{+37}:\\
\;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_0 := \sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c}\\
\mathbf{if}\;b \leq -1.9357207753357807 \cdot 10^{-308}:\\
\;\;\;\;\frac{t_0}{2 \cdot a} - \frac{b}{2 \cdot a}\\

\mathbf{elif}\;b \leq 2.3431308109665615 \cdot 10^{+85}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - t_0}\\

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


\end{array}\\


\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 -3.7715774085615172e+37)
   (/ (- (- b) b) (* 2.0 a))
   (let* ((t_0 (sqrt (- (* b b) (* (* a 4.0) c)))))
     (if (<= b -1.9357207753357807e-308)
       (- (/ t_0 (* 2.0 a)) (/ b (* 2.0 a)))
       (if (<= b 2.3431308109665615e+85)
         (/ (* 2.0 c) (- (- b) t_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 <= -3.7715774085615172e+37) {
		tmp = (-b - b) / (2.0 * a);
	} else {
		double t_0 = sqrt((b * b) - ((a * 4.0) * c));
		double tmp_1;
		if (b <= -1.9357207753357807e-308) {
			tmp_1 = (t_0 / (2.0 * a)) - (b / (2.0 * a));
		} else if (b <= 2.3431308109665615e+85) {
			tmp_1 = (2.0 * c) / (-b - t_0);
		} else {
			tmp_1 = -(c / b);
		}
		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 < -3.7715774085615172e37

    1. Initial program 35.7

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

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

    if -3.7715774085615172e37 < b < -1.9357207753357807e-308

    1. Initial program 9.3

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

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

      \[\leadsto \frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \color{blue}{\left(0 - b\right)}}{2 \cdot a} \]
    4. Applied associate-+r-_binary649.3

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

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

    if -1.9357207753357807e-308 < b < 2.34313081096656152e85

    1. Initial program 31.4

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

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

      \[\leadsto \frac{1}{\frac{2 \cdot a}{\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}}}}} \]
    4. Applied associate-/r/_binary6431.5

      \[\leadsto \frac{1}{\color{blue}{\frac{2 \cdot a}{\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}} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}} \]
    5. Applied associate-/r*_binary6431.5

      \[\leadsto \color{blue}{\frac{\frac{1}{\frac{2 \cdot a}{\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}}} \]
    6. Simplified15.8

      \[\leadsto \frac{\color{blue}{\left(4 \cdot \left(c \cdot a\right)\right) \cdot \frac{0.5}{a}}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}} \]
    7. Taylor expanded in c around 0 8.8

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

    if 2.34313081096656152e85 < b

    1. Initial program 58.0

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -3.7715774085615172 \cdot 10^{+37}:\\ \;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\ \mathbf{elif}\;b \leq -1.9357207753357807 \cdot 10^{-308}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c}}{2 \cdot a} - \frac{b}{2 \cdot a}\\ \mathbf{elif}\;b \leq 2.3431308109665615 \cdot 10^{+85}:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array} \]

Reproduce

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