\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \le 5.439241435777368432723079605465494539941 \cdot 10^{56}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;d \le 1.575208864443191563671446123909282396196 \cdot 10^{75}:\\
\;\;\;\;\frac{a}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;d \le 5.272132631092594325115160667769206679109 \cdot 10^{143}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\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 r70023 = a;
double r70024 = c;
double r70025 = r70023 * r70024;
double r70026 = b;
double r70027 = d;
double r70028 = r70026 * r70027;
double r70029 = r70025 + r70028;
double r70030 = r70024 * r70024;
double r70031 = r70027 * r70027;
double r70032 = r70030 + r70031;
double r70033 = r70029 / r70032;
return r70033;
}
double f(double a, double b, double c, double d) {
double r70034 = d;
double r70035 = 5.439241435777368e+56;
bool r70036 = r70034 <= r70035;
double r70037 = a;
double r70038 = c;
double r70039 = b;
double r70040 = r70039 * r70034;
double r70041 = fma(r70037, r70038, r70040);
double r70042 = hypot(r70038, r70034);
double r70043 = r70041 / r70042;
double r70044 = r70043 / r70042;
double r70045 = 1.5752088644431916e+75;
bool r70046 = r70034 <= r70045;
double r70047 = r70037 / r70042;
double r70048 = 5.272132631092594e+143;
bool r70049 = r70034 <= r70048;
double r70050 = r70039 / r70042;
double r70051 = r70049 ? r70044 : r70050;
double r70052 = r70046 ? r70047 : r70051;
double r70053 = r70036 ? r70044 : r70052;
return r70053;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.3 |
|---|---|
| Target | 0.5 |
| Herbie | 15.6 |
if d < 5.439241435777368e+56 or 1.5752088644431916e+75 < d < 5.272132631092594e+143Initial program 23.5
Simplified23.5
rmApplied add-sqr-sqrt23.5
Applied *-un-lft-identity23.5
Applied times-frac23.5
Simplified23.5
Simplified15.3
rmApplied *-un-lft-identity15.3
Applied add-sqr-sqrt15.3
Applied times-frac15.3
Applied associate-*l*15.3
Simplified15.2
if 5.439241435777368e+56 < d < 1.5752088644431916e+75Initial program 20.8
Simplified20.8
rmApplied add-sqr-sqrt20.8
Applied *-un-lft-identity20.8
Applied times-frac20.8
Simplified20.8
Simplified12.1
rmApplied *-un-lft-identity12.1
Applied add-sqr-sqrt12.1
Applied times-frac12.1
Applied associate-*l*12.1
Simplified12.0
Taylor expanded around inf 50.1
if 5.272132631092594e+143 < d Initial program 44.4
Simplified44.4
rmApplied add-sqr-sqrt44.4
Applied *-un-lft-identity44.4
Applied times-frac44.4
Simplified44.4
Simplified29.8
rmApplied *-un-lft-identity29.8
Applied add-sqr-sqrt29.8
Applied times-frac29.8
Applied associate-*l*29.8
Simplified29.8
Taylor expanded around 0 13.9
Final simplification15.6
herbie shell --seed 2019322 +o rules:numerics
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
: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))))