\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -1.264168133681399 \cdot 10^{+152}:\\
\;\;\;\;\frac{-a}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{elif}\;c \le 1.4672736653528514 \cdot 10^{+187}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{\mathsf{hypot}\left(d, c\right)}\\
\end{array}double f(double a, double b, double c, double d) {
double r3836220 = a;
double r3836221 = c;
double r3836222 = r3836220 * r3836221;
double r3836223 = b;
double r3836224 = d;
double r3836225 = r3836223 * r3836224;
double r3836226 = r3836222 + r3836225;
double r3836227 = r3836221 * r3836221;
double r3836228 = r3836224 * r3836224;
double r3836229 = r3836227 + r3836228;
double r3836230 = r3836226 / r3836229;
return r3836230;
}
double f(double a, double b, double c, double d) {
double r3836231 = c;
double r3836232 = -1.264168133681399e+152;
bool r3836233 = r3836231 <= r3836232;
double r3836234 = a;
double r3836235 = -r3836234;
double r3836236 = d;
double r3836237 = hypot(r3836236, r3836231);
double r3836238 = r3836235 / r3836237;
double r3836239 = 1.4672736653528514e+187;
bool r3836240 = r3836231 <= r3836239;
double r3836241 = b;
double r3836242 = r3836236 * r3836241;
double r3836243 = fma(r3836234, r3836231, r3836242);
double r3836244 = r3836243 / r3836237;
double r3836245 = r3836244 / r3836237;
double r3836246 = r3836234 / r3836237;
double r3836247 = r3836240 ? r3836245 : r3836246;
double r3836248 = r3836233 ? r3836238 : r3836247;
return r3836248;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.6 |
|---|---|
| Target | 0.6 |
| Herbie | 12.6 |
if c < -1.264168133681399e+152Initial program 43.7
Simplified43.7
rmApplied add-sqr-sqrt43.7
Applied associate-/r*43.7
rmApplied fma-udef43.7
Applied hypot-def43.7
rmApplied fma-udef43.7
Applied hypot-def28.2
Taylor expanded around -inf 13.6
Simplified13.6
if -1.264168133681399e+152 < c < 1.4672736653528514e+187Initial program 19.9
Simplified19.9
rmApplied add-sqr-sqrt19.9
Applied associate-/r*19.8
rmApplied fma-udef19.8
Applied hypot-def19.8
rmApplied fma-udef19.8
Applied hypot-def12.6
if 1.4672736653528514e+187 < c Initial program 42.9
Simplified42.9
rmApplied add-sqr-sqrt42.9
Applied associate-/r*42.9
rmApplied fma-udef42.9
Applied hypot-def42.9
Taylor expanded around inf 11.6
Final simplification12.6
herbie shell --seed 2019135 +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))))