\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \le 9.936266958075772 \cdot 10^{+94}:\\
\;\;\;\;\frac{\frac{1}{\frac{\mathsf{hypot}\left(d, c\right)}{\mathsf{fma}\left(a, c, b \cdot d\right)}}}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{\mathsf{hypot}\left(d, c\right)}\\
\end{array}double f(double a, double b, double c, double d) {
double r3106301 = a;
double r3106302 = c;
double r3106303 = r3106301 * r3106302;
double r3106304 = b;
double r3106305 = d;
double r3106306 = r3106304 * r3106305;
double r3106307 = r3106303 + r3106306;
double r3106308 = r3106302 * r3106302;
double r3106309 = r3106305 * r3106305;
double r3106310 = r3106308 + r3106309;
double r3106311 = r3106307 / r3106310;
return r3106311;
}
double f(double a, double b, double c, double d) {
double r3106312 = d;
double r3106313 = 9.936266958075772e+94;
bool r3106314 = r3106312 <= r3106313;
double r3106315 = 1.0;
double r3106316 = c;
double r3106317 = hypot(r3106312, r3106316);
double r3106318 = a;
double r3106319 = b;
double r3106320 = r3106319 * r3106312;
double r3106321 = fma(r3106318, r3106316, r3106320);
double r3106322 = r3106317 / r3106321;
double r3106323 = r3106315 / r3106322;
double r3106324 = r3106323 / r3106317;
double r3106325 = r3106319 / r3106317;
double r3106326 = r3106314 ? r3106324 : r3106325;
return r3106326;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.8 |
|---|---|
| Target | 0.4 |
| Herbie | 14.6 |
if d < 9.936266958075772e+94Initial program 22.9
Simplified22.9
rmApplied add-sqr-sqrt22.9
Applied associate-/r*22.8
rmApplied fma-udef22.8
Applied hypot-def22.8
rmApplied fma-udef22.8
Applied hypot-def14.0
rmApplied clear-num14.1
if 9.936266958075772e+94 < d Initial program 38.8
Simplified38.8
rmApplied add-sqr-sqrt38.8
Applied associate-/r*38.7
rmApplied fma-udef38.7
Applied hypot-def38.7
rmApplied fma-udef38.7
Applied hypot-def25.9
Taylor expanded around 0 16.7
Final simplification14.6
herbie shell --seed 2019138 +o rules:numerics
(FPCore (a b c d)
:name "Complex division, real part"
: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))))