\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \le -1.696889279647290237234578100884848526295 \cdot 10^{245}:\\
\;\;\;\;\frac{-1}{\mathsf{hypot}\left(d, c\right)} \cdot b\\
\mathbf{elif}\;d \le 7.009208612122958667307700471256846817647 \cdot 10^{165}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(c, a, b \cdot d\right)}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{else}:\\
\;\;\;\;b \cdot \frac{1}{\mathsf{hypot}\left(d, c\right)}\\
\end{array}double f(double a, double b, double c, double d) {
double r5372317 = a;
double r5372318 = c;
double r5372319 = r5372317 * r5372318;
double r5372320 = b;
double r5372321 = d;
double r5372322 = r5372320 * r5372321;
double r5372323 = r5372319 + r5372322;
double r5372324 = r5372318 * r5372318;
double r5372325 = r5372321 * r5372321;
double r5372326 = r5372324 + r5372325;
double r5372327 = r5372323 / r5372326;
return r5372327;
}
double f(double a, double b, double c, double d) {
double r5372328 = d;
double r5372329 = -1.6968892796472902e+245;
bool r5372330 = r5372328 <= r5372329;
double r5372331 = -1.0;
double r5372332 = c;
double r5372333 = hypot(r5372328, r5372332);
double r5372334 = r5372331 / r5372333;
double r5372335 = b;
double r5372336 = r5372334 * r5372335;
double r5372337 = 7.009208612122959e+165;
bool r5372338 = r5372328 <= r5372337;
double r5372339 = a;
double r5372340 = r5372335 * r5372328;
double r5372341 = fma(r5372332, r5372339, r5372340);
double r5372342 = r5372341 / r5372333;
double r5372343 = r5372342 / r5372333;
double r5372344 = 1.0;
double r5372345 = r5372344 / r5372333;
double r5372346 = r5372335 * r5372345;
double r5372347 = r5372338 ? r5372343 : r5372346;
double r5372348 = r5372330 ? r5372336 : r5372347;
return r5372348;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.6 |
|---|---|
| Target | 0.5 |
| Herbie | 13.5 |
if d < -1.6968892796472902e+245Initial program 41.8
Simplified41.8
rmApplied clear-num41.8
rmApplied *-un-lft-identity41.8
Applied add-sqr-sqrt41.8
Applied times-frac41.8
Applied add-cube-cbrt41.8
Applied times-frac41.8
Simplified41.8
Simplified34.2
Taylor expanded around -inf 8.9
Simplified8.9
if -1.6968892796472902e+245 < d < 7.009208612122959e+165Initial program 23.0
Simplified23.0
rmApplied clear-num23.1
rmApplied *-un-lft-identity23.1
Applied add-sqr-sqrt23.1
Applied times-frac23.1
Applied add-cube-cbrt23.1
Applied times-frac23.0
Simplified23.0
Simplified14.0
rmApplied associate-*r/14.0
Simplified13.9
if 7.009208612122959e+165 < d Initial program 45.0
Simplified45.0
rmApplied clear-num45.0
rmApplied *-un-lft-identity45.0
Applied add-sqr-sqrt45.0
Applied times-frac45.0
Applied add-cube-cbrt45.0
Applied times-frac45.0
Simplified45.0
Simplified29.8
Taylor expanded around inf 12.7
Final simplification13.5
herbie shell --seed 2019171 +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))))