\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \leq -4.962548969300428 \cdot 10^{+153}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq -1.7482251795713455 \cdot 10^{-17}:\\
\;\;\;\;\frac{\left(-a\right) - \frac{d \cdot b}{c}}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{elif}\;c \leq 1.1035576422910915 \cdot 10^{-08}:\\
\;\;\;\;\frac{b}{d} + \frac{c \cdot a}{{d}^{2}}\\
\mathbf{elif}\;c \leq 1.3319656876646648 \cdot 10^{+161}:\\
\;\;\;\;\frac{\frac{d \cdot b + c \cdot a}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
(FPCore (a b c d)
:precision binary64
(if (<= c -4.962548969300428e+153)
(/ a c)
(if (<= c -1.7482251795713455e-17)
(/ (- (- a) (/ (* d b) c)) (sqrt (+ (* c c) (* d d))))
(if (<= c 1.1035576422910915e-08)
(+ (/ b d) (/ (* c a) (pow d 2.0)))
(if (<= c 1.3319656876646648e+161)
(/
(/ (+ (* d b) (* c a)) (sqrt (+ (* c c) (* d d))))
(sqrt (+ (* c c) (* d d))))
(/ a c))))))double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -4.962548969300428e+153) {
tmp = a / c;
} else if (c <= -1.7482251795713455e-17) {
tmp = (-a - ((d * b) / c)) / sqrt((c * c) + (d * d));
} else if (c <= 1.1035576422910915e-08) {
tmp = (b / d) + ((c * a) / pow(d, 2.0));
} else if (c <= 1.3319656876646648e+161) {
tmp = (((d * b) + (c * a)) / sqrt((c * c) + (d * d))) / sqrt((c * c) + (d * d));
} else {
tmp = a / c;
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.0 |
|---|---|
| Target | 0.5 |
| Herbie | 16.1 |
if c < -4.96254896930042763e153 or 1.33196568766466476e161 < c Initial program 44.5
rmApplied *-un-lft-identity_binary6444.5
Applied *-un-lft-identity_binary6444.5
Applied times-frac_binary6444.5
Simplified44.5
Simplified44.5
Taylor expanded around 0 12.7
if -4.96254896930042763e153 < c < -1.7482251795713455e-17Initial program 20.0
rmApplied add-sqr-sqrt_binary6420.0
Applied associate-/r*_binary6419.9
Simplified19.9
Taylor expanded around -inf 20.7
Simplified20.7
if -1.7482251795713455e-17 < c < 1.103557642291092e-8Initial program 19.1
rmApplied *-un-lft-identity_binary6419.1
Applied *-un-lft-identity_binary6419.1
Applied times-frac_binary6419.1
Simplified19.1
Simplified19.1
Taylor expanded around inf 15.2
if 1.103557642291092e-8 < c < 1.33196568766466476e161Initial program 20.2
rmApplied add-sqr-sqrt_binary6420.2
Applied associate-/r*_binary6420.1
Final simplification16.1
herbie shell --seed 2021175
(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))))