\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -1.68397146889473803549156226978795498139 \cdot 10^{152}:\\
\;\;\;\;e^{\mathsf{fma}\left(-2, \log \left(\mathsf{hypot}\left(d, c\right)\right), \log \left(\mathsf{fma}\left(c, a, d \cdot b\right)\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}\\
\end{array}double f(double a, double b, double c, double d) {
double r4493474 = a;
double r4493475 = c;
double r4493476 = r4493474 * r4493475;
double r4493477 = b;
double r4493478 = d;
double r4493479 = r4493477 * r4493478;
double r4493480 = r4493476 + r4493479;
double r4493481 = r4493475 * r4493475;
double r4493482 = r4493478 * r4493478;
double r4493483 = r4493481 + r4493482;
double r4493484 = r4493480 / r4493483;
return r4493484;
}
double f(double a, double b, double c, double d) {
double r4493485 = c;
double r4493486 = -1.683971468894738e+152;
bool r4493487 = r4493485 <= r4493486;
double r4493488 = -2.0;
double r4493489 = d;
double r4493490 = hypot(r4493489, r4493485);
double r4493491 = log(r4493490);
double r4493492 = a;
double r4493493 = b;
double r4493494 = r4493489 * r4493493;
double r4493495 = fma(r4493485, r4493492, r4493494);
double r4493496 = log(r4493495);
double r4493497 = fma(r4493488, r4493491, r4493496);
double r4493498 = exp(r4493497);
double r4493499 = fma(r4493492, r4493485, r4493494);
double r4493500 = r4493485 * r4493485;
double r4493501 = fma(r4493489, r4493489, r4493500);
double r4493502 = sqrt(r4493501);
double r4493503 = r4493499 / r4493502;
double r4493504 = r4493503 / r4493502;
double r4493505 = r4493487 ? r4493498 : r4493504;
return r4493505;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.1 |
|---|---|
| Target | 0.4 |
| Herbie | 26.4 |
if c < -1.683971468894738e+152Initial program 44.8
Simplified44.8
rmApplied add-sqr-sqrt44.8
rmApplied add-exp-log44.9
Applied add-exp-log44.9
Applied prod-exp44.9
Applied add-exp-log54.6
Applied div-exp54.6
Simplified48.1
if -1.683971468894738e+152 < c Initial program 23.3
Simplified23.3
rmApplied add-sqr-sqrt23.3
Applied associate-/r*23.2
Final simplification26.4
herbie shell --seed 2019179 +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))))