\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \le 2.05713225699940855 \cdot 10^{121}:\\
\;\;\;\;\frac{\mathsf{fma}\left(c, a, b \cdot d\right) \cdot \frac{1}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}double f(double a, double b, double c, double d) {
double r77325 = a;
double r77326 = c;
double r77327 = r77325 * r77326;
double r77328 = b;
double r77329 = d;
double r77330 = r77328 * r77329;
double r77331 = r77327 + r77330;
double r77332 = r77326 * r77326;
double r77333 = r77329 * r77329;
double r77334 = r77332 + r77333;
double r77335 = r77331 / r77334;
return r77335;
}
double f(double a, double b, double c, double d) {
double r77336 = d;
double r77337 = 2.0571322569994085e+121;
bool r77338 = r77336 <= r77337;
double r77339 = c;
double r77340 = a;
double r77341 = b;
double r77342 = r77341 * r77336;
double r77343 = fma(r77339, r77340, r77342);
double r77344 = 1.0;
double r77345 = hypot(r77339, r77336);
double r77346 = r77344 / r77345;
double r77347 = r77343 * r77346;
double r77348 = r77347 / r77345;
double r77349 = r77341 / r77345;
double r77350 = r77338 ? r77348 : r77349;
return r77350;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.3 |
|---|---|
| Target | 0.5 |
| Herbie | 15.2 |
if d < 2.0571322569994085e+121Initial program 23.5
Simplified23.5
rmApplied add-sqr-sqrt23.5
Applied *-un-lft-identity23.5
Applied times-frac23.5
Simplified23.5
Simplified15.2
rmApplied associate-*r/15.2
Simplified15.1
rmApplied div-inv15.2
if 2.0571322569994085e+121 < d Initial program 41.4
Simplified41.4
rmApplied add-sqr-sqrt41.4
Applied *-un-lft-identity41.4
Applied times-frac41.4
Simplified41.4
Simplified26.4
rmApplied associate-*r/26.4
Simplified26.3
Taylor expanded around 0 15.4
Final simplification15.2
herbie shell --seed 2019199 +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))))