\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -1.1443562208296078 \cdot 10^{+200}:\\
\;\;\;\;\frac{-a}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{elif}\;c \le 1.3614475866611724 \cdot 10^{+128}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, c, \left(d \cdot b\right)\right) \cdot \frac{1}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{\mathsf{hypot}\left(d, c\right)}\\
\end{array}double f(double a, double b, double c, double d) {
double r3417366 = a;
double r3417367 = c;
double r3417368 = r3417366 * r3417367;
double r3417369 = b;
double r3417370 = d;
double r3417371 = r3417369 * r3417370;
double r3417372 = r3417368 + r3417371;
double r3417373 = r3417367 * r3417367;
double r3417374 = r3417370 * r3417370;
double r3417375 = r3417373 + r3417374;
double r3417376 = r3417372 / r3417375;
return r3417376;
}
double f(double a, double b, double c, double d) {
double r3417377 = c;
double r3417378 = -1.1443562208296078e+200;
bool r3417379 = r3417377 <= r3417378;
double r3417380 = a;
double r3417381 = -r3417380;
double r3417382 = d;
double r3417383 = hypot(r3417382, r3417377);
double r3417384 = r3417381 / r3417383;
double r3417385 = 1.3614475866611724e+128;
bool r3417386 = r3417377 <= r3417385;
double r3417387 = b;
double r3417388 = r3417382 * r3417387;
double r3417389 = fma(r3417380, r3417377, r3417388);
double r3417390 = 1.0;
double r3417391 = r3417390 / r3417383;
double r3417392 = r3417389 * r3417391;
double r3417393 = r3417392 / r3417383;
double r3417394 = r3417380 / r3417383;
double r3417395 = r3417386 ? r3417393 : r3417394;
double r3417396 = r3417379 ? r3417384 : r3417395;
return r3417396;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.1 |
|---|---|
| Target | 0.4 |
| Herbie | 13.0 |
if c < -1.1443562208296078e+200Initial program 41.6
Simplified41.6
rmApplied add-sqr-sqrt41.6
Applied associate-/r*41.6
rmApplied fma-udef41.6
Applied hypot-def41.6
rmApplied fma-udef41.6
Applied hypot-def28.5
Taylor expanded around -inf 10.3
Simplified10.3
if -1.1443562208296078e+200 < c < 1.3614475866611724e+128Initial program 20.9
Simplified20.9
rmApplied add-sqr-sqrt20.9
Applied associate-/r*20.8
rmApplied fma-udef20.8
Applied hypot-def20.8
rmApplied fma-udef20.8
Applied hypot-def12.9
rmApplied div-inv13.0
if 1.3614475866611724e+128 < c Initial program 42.4
Simplified42.4
rmApplied add-sqr-sqrt42.4
Applied associate-/r*42.4
rmApplied fma-udef42.4
Applied hypot-def42.4
rmApplied fma-udef42.4
Applied hypot-def28.2
Taylor expanded around inf 14.6
Final simplification13.0
herbie shell --seed 2019133 +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))))