\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -4.379830691407506152483526105989468908471 \cdot 10^{106}:\\
\;\;\;\;\frac{-a}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \le 9.741722452995778162218720265388181385737 \cdot 10^{95}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\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 r69155 = a;
double r69156 = c;
double r69157 = r69155 * r69156;
double r69158 = b;
double r69159 = d;
double r69160 = r69158 * r69159;
double r69161 = r69157 + r69160;
double r69162 = r69156 * r69156;
double r69163 = r69159 * r69159;
double r69164 = r69162 + r69163;
double r69165 = r69161 / r69164;
return r69165;
}
double f(double a, double b, double c, double d) {
double r69166 = c;
double r69167 = -4.379830691407506e+106;
bool r69168 = r69166 <= r69167;
double r69169 = a;
double r69170 = -r69169;
double r69171 = d;
double r69172 = hypot(r69166, r69171);
double r69173 = r69170 / r69172;
double r69174 = 9.741722452995778e+95;
bool r69175 = r69166 <= r69174;
double r69176 = 1.0;
double r69177 = r69176 / r69172;
double r69178 = b;
double r69179 = r69178 * r69171;
double r69180 = fma(r69169, r69166, r69179);
double r69181 = r69180 / r69172;
double r69182 = r69177 * r69181;
double r69183 = r69169 / r69172;
double r69184 = r69175 ? r69182 : r69183;
double r69185 = r69168 ? r69173 : r69184;
return r69185;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.0 |
|---|---|
| Target | 0.4 |
| Herbie | 13.0 |
if c < -4.379830691407506e+106Initial program 41.0
rmApplied add-sqr-sqrt41.0
Applied *-un-lft-identity41.0
Applied times-frac41.0
Simplified41.0
Simplified28.5
rmApplied *-un-lft-identity28.5
Applied add-cube-cbrt28.5
Applied times-frac28.5
Applied associate-*l*28.5
Simplified28.4
rmApplied clear-num28.4
Taylor expanded around -inf 16.0
Simplified16.0
if -4.379830691407506e+106 < c < 9.741722452995778e+95Initial program 18.4
rmApplied add-sqr-sqrt18.4
Applied *-un-lft-identity18.4
Applied times-frac18.5
Simplified18.5
Simplified11.2
if 9.741722452995778e+95 < c Initial program 39.1
rmApplied add-sqr-sqrt39.1
Applied *-un-lft-identity39.1
Applied times-frac39.1
Simplified39.1
Simplified27.3
rmApplied *-un-lft-identity27.3
Applied add-cube-cbrt27.3
Applied times-frac27.3
Applied associate-*l*27.3
Simplified27.2
Taylor expanded around 0 16.6
Final simplification13.0
herbie shell --seed 2019209 +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))))