double f(double a, double b, double c, double d) {
double r15462325 = a;
double r15462326 = c;
double r15462327 = r15462325 * r15462326;
double r15462328 = b;
double r15462329 = d;
double r15462330 = r15462328 * r15462329;
double r15462331 = r15462327 + r15462330;
double r15462332 = r15462326 * r15462326;
double r15462333 = r15462329 * r15462329;
double r15462334 = r15462332 + r15462333;
double r15462335 = r15462331 / r15462334;
return r15462335;
}
double f(double a, double b, double c, double d) {
double r15462336 = c;
double r15462337 = -1.1649944572964785e+191;
bool r15462338 = r15462336 <= r15462337;
double r15462339 = a;
double r15462340 = -r15462339;
double r15462341 = d;
double r15462342 = hypot(r15462341, r15462336);
double r15462343 = r15462340 / r15462342;
double r15462344 = 6.443797861366497e+143;
bool r15462345 = r15462336 <= r15462344;
double r15462346 = b;
double r15462347 = r15462341 * r15462346;
double r15462348 = fma(r15462339, r15462336, r15462347);
double r15462349 = r15462348 / r15462342;
double r15462350 = r15462349 / r15462342;
double r15462351 = r15462339 / r15462342;
double r15462352 = r15462345 ? r15462350 : r15462351;
double r15462353 = r15462338 ? r15462343 : r15462352;
return r15462353;
}
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -1.1649944572964785 \cdot 10^{+191}:\\
\;\;\;\;\frac{-a}{\sqrt{d^2 + c^2}^*}\\
\mathbf{elif}\;c \le 6.443797861366497 \cdot 10^{+143}:\\
\;\;\;\;\frac{\frac{(a \cdot c + \left(d \cdot b\right))_*}{\sqrt{d^2 + c^2}^*}}{\sqrt{d^2 + c^2}^*}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{\sqrt{d^2 + c^2}^*}\\
\end{array}



Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.8 |
|---|---|
| Target | 0.4 |
| Herbie | 12.5 |
if c < -1.1649944572964785e+191Initial program 43.0
Simplified43.0
rmApplied add-sqr-sqrt43.0
Applied associate-/r*43.0
rmApplied fma-udef43.0
Applied hypot-def43.0
rmApplied fma-udef43.0
Applied hypot-def29.7
Taylor expanded around -inf 10.9
Simplified10.9
if -1.1649944572964785e+191 < c < 6.443797861366497e+143Initial program 20.5
Simplified20.5
rmApplied add-sqr-sqrt20.5
Applied associate-/r*20.4
rmApplied fma-udef20.4
Applied hypot-def20.4
rmApplied fma-udef20.4
Applied hypot-def12.4
if 6.443797861366497e+143 < c Initial program 43.2
Simplified43.2
rmApplied add-sqr-sqrt43.2
Applied associate-/r*43.2
rmApplied fma-udef43.2
Applied hypot-def43.2
rmApplied fma-udef43.2
Applied hypot-def26.9
Taylor expanded around inf 14.7
Final simplification12.5
herbie shell --seed 2019101 +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))))