\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -1.286184118088981486051285346181269334181 \cdot 10^{163}:\\
\;\;\;\;\frac{-a}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \le 1.036864426879663678952022222917679113002 \cdot 10^{207}:\\
\;\;\;\;\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)}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}double f(double a, double b, double c, double d) {
double r84322 = a;
double r84323 = c;
double r84324 = r84322 * r84323;
double r84325 = b;
double r84326 = d;
double r84327 = r84325 * r84326;
double r84328 = r84324 + r84327;
double r84329 = r84323 * r84323;
double r84330 = r84326 * r84326;
double r84331 = r84329 + r84330;
double r84332 = r84328 / r84331;
return r84332;
}
double f(double a, double b, double c, double d) {
double r84333 = c;
double r84334 = -1.2861841180889815e+163;
bool r84335 = r84333 <= r84334;
double r84336 = a;
double r84337 = -r84336;
double r84338 = d;
double r84339 = hypot(r84333, r84338);
double r84340 = r84337 / r84339;
double r84341 = 1.0368644268796637e+207;
bool r84342 = r84333 <= r84341;
double r84343 = 1.0;
double r84344 = b;
double r84345 = r84344 * r84338;
double r84346 = fma(r84336, r84333, r84345);
double r84347 = r84339 / r84346;
double r84348 = r84343 / r84347;
double r84349 = r84348 / r84339;
double r84350 = r84336 / r84339;
double r84351 = r84342 ? r84349 : r84350;
double r84352 = r84335 ? r84340 : r84351;
return r84352;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.0 |
|---|---|
| Target | 0.5 |
| Herbie | 13.0 |
if c < -1.2861841180889815e+163Initial program 46.8
Simplified46.8
rmApplied add-sqr-sqrt46.8
Applied *-un-lft-identity46.8
Applied times-frac46.8
Simplified46.8
Simplified32.5
rmApplied *-un-lft-identity32.5
Applied associate-*l*32.5
Simplified32.4
Taylor expanded around -inf 15.1
Simplified15.1
if -1.2861841180889815e+163 < c < 1.0368644268796637e+207Initial program 20.8
Simplified20.8
rmApplied add-sqr-sqrt20.8
Applied *-un-lft-identity20.8
Applied times-frac20.9
Simplified20.9
Simplified13.0
rmApplied *-un-lft-identity13.0
Applied associate-*l*13.0
Simplified12.9
rmApplied clear-num13.0
if 1.0368644268796637e+207 < c Initial program 42.2
Simplified42.2
rmApplied add-sqr-sqrt42.2
Applied *-un-lft-identity42.2
Applied times-frac42.2
Simplified42.2
Simplified30.3
rmApplied *-un-lft-identity30.3
Applied associate-*l*30.3
Simplified30.2
Taylor expanded around inf 10.7
Final simplification13.0
herbie shell --seed 2019303 +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))))