Average Error: 34.3 → 10.5
Time: 16.3s
Precision: binary64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
\[\begin{array}{l} \mathbf{if}\;b \leq -1.0122084336907998 \cdot 10^{+145}:\\ \;\;\;\;\frac{\frac{b \cdot -2}{3}}{a}\\ \mathbf{elif}\;b \leq 6.659820644835131 \cdot 10^{-129}:\\ \;\;\;\;\frac{{\left(b \cdot b - \left(3 \cdot a\right) \cdot c\right)}^{0.5} - b}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \leq -1.0122084336907998 \cdot 10^{+145}:\\
\;\;\;\;\frac{\frac{b \cdot -2}{3}}{a}\\

\mathbf{elif}\;b \leq 6.659820644835131 \cdot 10^{-129}:\\
\;\;\;\;\frac{{\left(b \cdot b - \left(3 \cdot a\right) \cdot c\right)}^{0.5} - b}{3 \cdot a}\\

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


\end{array}
(FPCore (a b c)
 :precision binary64
 (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))
(FPCore (a b c)
 :precision binary64
 (if (<= b -1.0122084336907998e+145)
   (/ (/ (* b -2.0) 3.0) a)
   (if (<= b 6.659820644835131e-129)
     (/ (- (pow (- (* b b) (* (* 3.0 a) c)) 0.5) b) (* 3.0 a))
     (* -0.5 (/ c b)))))
double code(double a, double b, double c) {
	return (-b + sqrt((b * b) - ((3.0 * a) * c))) / (3.0 * a);
}
double code(double a, double b, double c) {
	double tmp;
	if (b <= -1.0122084336907998e+145) {
		tmp = ((b * -2.0) / 3.0) / a;
	} else if (b <= 6.659820644835131e-129) {
		tmp = (pow(((b * b) - ((3.0 * a) * c)), 0.5) - b) / (3.0 * a);
	} else {
		tmp = -0.5 * (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.01220843369079976e145

    1. Initial program 60.9

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Applied associate-/r*_binary6460.9

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

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

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

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

    if -1.01220843369079976e145 < b < 6.65982064483513139e-129

    1. Initial program 11.4

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

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

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

    if 6.65982064483513139e-129 < b

    1. Initial program 51.0

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
    2. Taylor expanded in b around inf 11.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.0122084336907998 \cdot 10^{+145}:\\ \;\;\;\;\frac{\frac{b \cdot -2}{3}}{a}\\ \mathbf{elif}\;b \leq 6.659820644835131 \cdot 10^{-129}:\\ \;\;\;\;\frac{{\left(b \cdot b - \left(3 \cdot a\right) \cdot c\right)}^{0.5} - b}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]

Reproduce

herbie shell --seed 2021215 
(FPCore (a b c)
  :name "Cubic critical"
  :precision binary64
  (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))