\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -3.77697139995080395 \cdot 10^{155}:\\
\;\;\;\;\frac{-1 \cdot a}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\mathbf{elif}\;c \le 3.559188999299462 \cdot 10^{84}:\\
\;\;\;\;\frac{\frac{1}{\frac{\mathsf{hypot}\left(c, d\right)}{\mathsf{fma}\left(a, c, b \cdot d\right)}}}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\end{array}double f(double a, double b, double c, double d) {
double r110196 = a;
double r110197 = c;
double r110198 = r110196 * r110197;
double r110199 = b;
double r110200 = d;
double r110201 = r110199 * r110200;
double r110202 = r110198 + r110201;
double r110203 = r110197 * r110197;
double r110204 = r110200 * r110200;
double r110205 = r110203 + r110204;
double r110206 = r110202 / r110205;
return r110206;
}
double f(double a, double b, double c, double d) {
double r110207 = c;
double r110208 = -3.776971399950804e+155;
bool r110209 = r110207 <= r110208;
double r110210 = -1.0;
double r110211 = a;
double r110212 = r110210 * r110211;
double r110213 = d;
double r110214 = hypot(r110207, r110213);
double r110215 = 1.0;
double r110216 = r110214 * r110215;
double r110217 = r110212 / r110216;
double r110218 = 3.559188999299462e+84;
bool r110219 = r110207 <= r110218;
double r110220 = b;
double r110221 = r110220 * r110213;
double r110222 = fma(r110211, r110207, r110221);
double r110223 = r110214 / r110222;
double r110224 = r110215 / r110223;
double r110225 = r110224 / r110216;
double r110226 = r110211 / r110216;
double r110227 = r110219 ? r110225 : r110226;
double r110228 = r110209 ? r110217 : r110227;
return r110228;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.3 |
|---|---|
| Target | 0.5 |
| Herbie | 13.2 |
if c < -3.776971399950804e+155Initial program 45.9
rmApplied add-sqr-sqrt45.9
Applied *-un-lft-identity45.9
Applied times-frac45.9
Simplified45.9
Simplified28.9
rmApplied associate-*r/28.9
Simplified28.9
Taylor expanded around -inf 14.2
if -3.776971399950804e+155 < c < 3.559188999299462e+84Initial program 18.7
rmApplied add-sqr-sqrt18.7
Applied *-un-lft-identity18.7
Applied times-frac18.7
Simplified18.7
Simplified11.7
rmApplied associate-*r/11.7
Simplified11.6
rmApplied clear-num11.7
if 3.559188999299462e+84 < c Initial program 39.4
rmApplied add-sqr-sqrt39.4
Applied *-un-lft-identity39.4
Applied times-frac39.4
Simplified39.4
Simplified26.8
rmApplied associate-*r/26.8
Simplified26.8
Taylor expanded around inf 17.6
Final simplification13.2
herbie shell --seed 2020056 +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))))