Average Error: 33.2 → 10.4
Time: 10.0s
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.2276371444500064 \cdot 10^{+37}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 3.7582348055294276 \cdot 10^{-87}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}{a} \cdot 0.5\\ \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 -3.2276371444500064 \cdot 10^{+37}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\

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

\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 -3.2276371444500064e+37)
   (- (/ c b) (/ b a))
   (if (<= b 3.7582348055294276e-87)
     (* (/ (- (sqrt (- (* b b) (* 4.0 (* c a)))) b) a) 0.5)
     (- (/ 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.2276371444500064e+37) {
		tmp = (c / b) - (b / a);
	} else if (b <= 3.7582348055294276e-87) {
		tmp = ((sqrt((b * b) - (4.0 * (c * a))) - b) / a) * 0.5;
	} 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 < -3.22763714445000636e37

    1. Initial program 34.0

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

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

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

    if -3.22763714445000636e37 < b < 3.7582348055294276e-87

    1. Initial program 13.5

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

      \[\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_binary6413.6

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

      \[\leadsto \frac{1}{\color{blue}{\frac{a}{\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{2}}}}\]
    6. Using strategy rm
    7. Applied associate-/r/_binary6413.6

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

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

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

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

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

    if 3.7582348055294276e-87 < b

    1. Initial program 52.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -3.2276371444500064 \cdot 10^{+37}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \leq 3.7582348055294276 \cdot 10^{-87}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}{a} \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

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