Average Error: 33.9 → 9.7
Time: 14.6s
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.8342337024011525 \cdot 10^{+138}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{elif}\;b \leq 2.900768719258459 \cdot 10^{-65}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}}\\ \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 -1.8342337024011525 \cdot 10^{+138}:\\
\;\;\;\;-\frac{b}{a}\\

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

\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 -1.8342337024011525e+138)
   (- (/ b a))
   (if (<= b 2.900768719258459e-65)
     (/ 1.0 (/ (* a 2.0) (- (sqrt (- (* b b) (* (* a 4.0) c))) b)))
     (- (/ 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 <= -1.8342337024011525e+138) {
		tmp = -(b / a);
	} else if (b <= 2.900768719258459e-65) {
		tmp = 1.0 / ((a * 2.0) / (sqrt((b * b) - ((a * 4.0) * c)) - b));
	} else {
		tmp = -(c / b);
	}
	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 3 regimes
  2. if b < -1.83423370240115254e138

    1. Initial program 57.7

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

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

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

    if -1.83423370240115254e138 < b < 2.9007687192584592e-65

    1. Initial program 12.4

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Simplified12.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 clear-num_binary64_7712.5

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

    if 2.9007687192584592e-65 < b

    1. Initial program 54.1

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.8342337024011525 \cdot 10^{+138}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{elif}\;b \leq 2.900768719258459 \cdot 10^{-65}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

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