\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
\mathbf{if}\;c \leq -9.06783613733096 \cdot 10^{+79}:\\
\;\;\;\;\frac{-\mathsf{fma}\left(\frac{d}{c}, b, a\right)}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{elif}\;c \leq -3.44433832248687 \cdot 10^{-174}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(d, b, c \cdot a\right)}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{elif}\;c \leq 2.7560140316565585 \cdot 10^{-220}:\\
\;\;\;\;\frac{b}{d} + \frac{c \cdot a}{{d}^{2}}\\
\mathbf{elif}\;c \leq 3.5151647360045185 \cdot 10^{+96}:\\
\;\;\;\;\frac{\frac{d \cdot b}{\mathsf{hypot}\left(d, c\right)} + \frac{c \cdot a}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{b}{c}, \frac{d}{c}, \frac{a}{c}\right)\\
\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 -9.06783613733096e+79)
(/ (- (fma (/ d c) b a)) (hypot d c))
(if (<= c -3.44433832248687e-174)
(/ (/ (fma d b (* c a)) (hypot d c)) (hypot d c))
(if (<= c 2.7560140316565585e-220)
(+ (/ b d) (/ (* c a) (pow d 2.0)))
(if (<= c 3.5151647360045185e+96)
(/ (+ (/ (* d b) (hypot d c)) (/ (* c a) (hypot d c))) (hypot d c))
(fma (/ b c) (/ d c) (/ 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 <= -9.06783613733096e+79) {
tmp = -fma((d / c), b, a) / hypot(d, c);
} else if (c <= -3.44433832248687e-174) {
tmp = (fma(d, b, (c * a)) / hypot(d, c)) / hypot(d, c);
} else if (c <= 2.7560140316565585e-220) {
tmp = (b / d) + ((c * a) / pow(d, 2.0));
} else if (c <= 3.5151647360045185e+96) {
tmp = (((d * b) / hypot(d, c)) + ((c * a) / hypot(d, c))) / hypot(d, c);
} else {
tmp = fma((b / c), (d / c), (a / c));
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.9 |
|---|---|
| Target | 0.5 |
| Herbie | 10.3 |
if c < -9.06783613733096029e79Initial program 38.3
Simplified38.3
Applied add-sqr-sqrt_binary6438.3
Applied *-un-lft-identity_binary6438.3
Applied times-frac_binary6438.3
Simplified38.3
Simplified26.8
Applied associate-*r/_binary6426.8
Taylor expanded in c around -inf 14.0
Simplified10.3
if -9.06783613733096029e79 < c < -3.4443383224868699e-174Initial program 16.7
Simplified16.7
Applied add-sqr-sqrt_binary6416.7
Applied *-un-lft-identity_binary6416.7
Applied times-frac_binary6416.7
Simplified16.7
Simplified11.7
Applied associate-*l/_binary6411.6
if -3.4443383224868699e-174 < c < 2.756014031656558e-220Initial program 23.0
Simplified23.0
Taylor expanded in c around 0 8.1
if 2.756014031656558e-220 < c < 3.5151647360045185e96Initial program 16.7
Simplified16.7
Applied add-sqr-sqrt_binary6416.7
Applied *-un-lft-identity_binary6416.7
Applied times-frac_binary6416.7
Simplified16.7
Simplified10.4
Applied associate-*r/_binary6410.3
Applied fma-udef_binary6410.3
Applied distribute-rgt-in_binary6410.3
Simplified10.3
Simplified10.2
if 3.5151647360045185e96 < c Initial program 38.3
Simplified38.3
Applied add-sqr-sqrt_binary6438.3
Applied *-un-lft-identity_binary6438.3
Applied times-frac_binary6438.3
Simplified38.3
Simplified26.7
Taylor expanded in d around 0 16.4
Simplified10.9
Final simplification10.3
herbie shell --seed 2021220
(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))))