\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \leq 3.3068320798254434 \cdot 10^{+305}:\\
\;\;\;\;\frac{\frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sqrt[3]{c \cdot c + d \cdot d} \cdot \sqrt[3]{c \cdot c + d \cdot d}} \cdot \left(\left(a \cdot c\right) \cdot \sqrt[3]{\frac{1}{d \cdot d}} + b \cdot \sqrt[3]{d}\right)\\
\end{array}(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
(FPCore (a b c d)
:precision binary64
(if (<= (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) 3.3068320798254434e+305)
(/
(/ (+ (* a c) (* b d)) (sqrt (+ (* c c) (* d d))))
(sqrt (+ (* c c) (* d d))))
(*
(/ 1.0 (* (cbrt (+ (* c c) (* d d))) (cbrt (+ (* c c) (* d d)))))
(+ (* (* a c) (cbrt (/ 1.0 (* d d)))) (* b (cbrt d))))))double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
double code(double a, double b, double c, double d) {
double tmp;
if ((((a * c) + (b * d)) / ((c * c) + (d * d))) <= 3.3068320798254434e+305) {
tmp = (((a * c) + (b * d)) / sqrt((c * c) + (d * d))) / sqrt((c * c) + (d * d));
} else {
tmp = (1.0 / (cbrt((c * c) + (d * d)) * cbrt((c * c) + (d * d)))) * (((a * c) * cbrt(1.0 / (d * d))) + (b * cbrt(d)));
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 25.8 |
|---|---|
| Target | 0.4 |
| Herbie | 25.2 |
if (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 3.30683207982544344e305Initial program 13.9
rmApplied add-sqr-sqrt_binary64_285313.9
Applied associate-/r*_binary64_277513.8
if 3.30683207982544344e305 < (/.f64 (+.f64 (*.f64 a c) (*.f64 b d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 63.9
rmApplied add-cube-cbrt_binary64_286663.9
Applied *-un-lft-identity_binary64_283163.9
Applied times-frac_binary64_283763.9
Taylor expanded around 0 62.8
Simplified61.4
Final simplification25.2
herbie shell --seed 2020281
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
:herbie-target
(if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d)))))
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))