double f(double a, double b, double c, double d) {
double r17324927 = b;
double r17324928 = c;
double r17324929 = r17324927 * r17324928;
double r17324930 = a;
double r17324931 = d;
double r17324932 = r17324930 * r17324931;
double r17324933 = r17324929 - r17324932;
double r17324934 = r17324928 * r17324928;
double r17324935 = r17324931 * r17324931;
double r17324936 = r17324934 + r17324935;
double r17324937 = r17324933 / r17324936;
return r17324937;
}
double f(double a, double b, double c, double d) {
double r17324938 = c;
double r17324939 = -4.5554482331281827e+198;
bool r17324940 = r17324938 <= r17324939;
double r17324941 = b;
double r17324942 = -r17324941;
double r17324943 = d;
double r17324944 = hypot(r17324943, r17324938);
double r17324945 = r17324942 / r17324944;
double r17324946 = 2.251215078496209e+155;
bool r17324947 = r17324938 <= r17324946;
double r17324948 = r17324941 * r17324938;
double r17324949 = a;
double r17324950 = r17324943 * r17324949;
double r17324951 = r17324948 - r17324950;
double r17324952 = r17324951 / r17324944;
double r17324953 = 1.0;
double r17324954 = r17324953 / r17324944;
double r17324955 = r17324952 * r17324954;
double r17324956 = r17324941 / r17324944;
double r17324957 = r17324947 ? r17324955 : r17324956;
double r17324958 = r17324940 ? r17324945 : r17324957;
return r17324958;
}
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -4.5554482331281827 \cdot 10^{+198}:\\
\;\;\;\;\frac{-b}{\sqrt{d^2 + c^2}^*}\\
\mathbf{elif}\;c \le 2.251215078496209 \cdot 10^{+155}:\\
\;\;\;\;\frac{b \cdot c - d \cdot a}{\sqrt{d^2 + c^2}^*} \cdot \frac{1}{\sqrt{d^2 + c^2}^*}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{\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.5 |
|---|---|
| Target | 0.4 |
| Herbie | 12.6 |
if c < -4.5554482331281827e+198Initial program 42.2
Simplified42.2
rmApplied add-sqr-sqrt42.2
Applied associate-/r*42.2
rmApplied fma-udef42.2
Applied hypot-def42.2
rmApplied fma-udef42.2
Applied hypot-def28.4
Taylor expanded around -inf 11.7
Simplified11.7
if -4.5554482331281827e+198 < c < 2.251215078496209e+155Initial program 20.6
Simplified20.6
rmApplied add-sqr-sqrt20.6
Applied associate-/r*20.5
rmApplied fma-udef20.5
Applied hypot-def20.5
rmApplied fma-udef20.5
Applied hypot-def12.2
rmApplied div-inv12.4
if 2.251215078496209e+155 < c Initial program 44.2
Simplified44.2
rmApplied add-sqr-sqrt44.2
Applied associate-/r*44.2
rmApplied fma-udef44.2
Applied hypot-def44.2
rmApplied fma-udef44.2
Applied hypot-def28.2
Taylor expanded around inf 14.6
Final simplification12.6
herbie shell --seed 2019101 +o rules:numerics
(FPCore (a b c d)
:name "Complex division, imag part"
:herbie-target
(if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d)))))
(/ (- (* b c) (* a d)) (+ (* c c) (* d d))))