\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -7.72381449609585197339080432829350912947 \cdot 10^{66}:\\
\;\;\;\;\frac{-1 \cdot a}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\mathbf{elif}\;c \le 2.28477586604815435652148617808763730008 \cdot 10^{70}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, 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 r117240 = a;
double r117241 = c;
double r117242 = r117240 * r117241;
double r117243 = b;
double r117244 = d;
double r117245 = r117243 * r117244;
double r117246 = r117242 + r117245;
double r117247 = r117241 * r117241;
double r117248 = r117244 * r117244;
double r117249 = r117247 + r117248;
double r117250 = r117246 / r117249;
return r117250;
}
double f(double a, double b, double c, double d) {
double r117251 = c;
double r117252 = -7.723814496095852e+66;
bool r117253 = r117251 <= r117252;
double r117254 = -1.0;
double r117255 = a;
double r117256 = r117254 * r117255;
double r117257 = d;
double r117258 = hypot(r117251, r117257);
double r117259 = 1.0;
double r117260 = r117258 * r117259;
double r117261 = r117256 / r117260;
double r117262 = 2.2847758660481544e+70;
bool r117263 = r117251 <= r117262;
double r117264 = b;
double r117265 = r117264 * r117257;
double r117266 = fma(r117255, r117251, r117265);
double r117267 = r117266 / r117258;
double r117268 = r117267 / r117260;
double r117269 = r117255 / r117260;
double r117270 = r117263 ? r117268 : r117269;
double r117271 = r117253 ? r117261 : r117270;
return r117271;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.9 |
|---|---|
| Target | 0.5 |
| Herbie | 13.6 |
if c < -7.723814496095852e+66Initial program 36.2
rmApplied add-sqr-sqrt36.2
Applied *-un-lft-identity36.2
Applied times-frac36.2
Simplified36.2
Simplified24.1
rmApplied associate-*r/24.1
Simplified24.0
Taylor expanded around -inf 18.2
if -7.723814496095852e+66 < c < 2.2847758660481544e+70Initial program 18.0
rmApplied add-sqr-sqrt18.0
Applied *-un-lft-identity18.0
Applied times-frac18.0
Simplified18.0
Simplified10.6
rmApplied associate-*r/10.5
Simplified10.5
if 2.2847758660481544e+70 < c Initial program 37.9
rmApplied add-sqr-sqrt37.9
Applied *-un-lft-identity37.9
Applied times-frac37.9
Simplified37.9
Simplified25.3
rmApplied associate-*r/25.3
Simplified25.2
Taylor expanded around inf 18.1
Final simplification13.6
herbie shell --seed 2019353 +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))))