\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\]
↓
\[\begin{array}{l}
t_0 := \frac{b}{d} + a \cdot \frac{c}{{d}^{2}}\\
t_1 := c \cdot c + d \cdot d\\
\mathbf{if}\;c \leq -1.85 \cdot 10^{+52}:\\
\;\;\;\;\frac{a}{c} + d \cdot \frac{b}{{c}^{2}}\\
\mathbf{elif}\;c \leq -4.5:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq -2.35 \cdot 10^{-135}:\\
\;\;\;\;\frac{1}{\frac{t_1}{c \cdot a + d \cdot b}}\\
\mathbf{elif}\;c \leq 2.4 \cdot 10^{-132}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 1.3 \cdot 10^{+139}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{t_1}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + b \cdot \frac{d}{{c}^{2}}\\
\end{array}
\]
(FPCore (a b c d)
:precision binary64
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
↓
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (+ (/ b d) (* a (/ c (pow d 2.0))))) (t_1 (+ (* c c) (* d d))))
(if (<= c -1.85e+52)
(+ (/ a c) (* d (/ b (pow c 2.0))))
(if (<= c -4.5)
t_0
(if (<= c -2.35e-135)
(/ 1.0 (/ t_1 (+ (* c a) (* d b))))
(if (<= c 2.4e-132)
t_0
(if (<= c 1.3e+139)
(/ (+ (* a c) (* b d)) t_1)
(+ (/ a c) (* b (/ d (pow c 2.0)))))))))))
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 t_0 = (b / d) + (a * (c / pow(d, 2.0)));
double t_1 = (c * c) + (d * d);
double tmp;
if (c <= -1.85e+52) {
tmp = (a / c) + (d * (b / pow(c, 2.0)));
} else if (c <= -4.5) {
tmp = t_0;
} else if (c <= -2.35e-135) {
tmp = 1.0 / (t_1 / ((c * a) + (d * b)));
} else if (c <= 2.4e-132) {
tmp = t_0;
} else if (c <= 1.3e+139) {
tmp = ((a * c) + (b * d)) / t_1;
} else {
tmp = (a / c) + (b * (d / pow(c, 2.0)));
}
return tmp;
}
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
↓
real(8) function code(a, b, c, d)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = (b / d) + (a * (c / (d ** 2.0d0)))
t_1 = (c * c) + (d * d)
if (c <= (-1.85d+52)) then
tmp = (a / c) + (d * (b / (c ** 2.0d0)))
else if (c <= (-4.5d0)) then
tmp = t_0
else if (c <= (-2.35d-135)) then
tmp = 1.0d0 / (t_1 / ((c * a) + (d * b)))
else if (c <= 2.4d-132) then
tmp = t_0
else if (c <= 1.3d+139) then
tmp = ((a * c) + (b * d)) / t_1
else
tmp = (a / c) + (b * (d / (c ** 2.0d0)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
↓
public static double code(double a, double b, double c, double d) {
double t_0 = (b / d) + (a * (c / Math.pow(d, 2.0)));
double t_1 = (c * c) + (d * d);
double tmp;
if (c <= -1.85e+52) {
tmp = (a / c) + (d * (b / Math.pow(c, 2.0)));
} else if (c <= -4.5) {
tmp = t_0;
} else if (c <= -2.35e-135) {
tmp = 1.0 / (t_1 / ((c * a) + (d * b)));
} else if (c <= 2.4e-132) {
tmp = t_0;
} else if (c <= 1.3e+139) {
tmp = ((a * c) + (b * d)) / t_1;
} else {
tmp = (a / c) + (b * (d / Math.pow(c, 2.0)));
}
return tmp;
}
herbie shell --seed 2023074
(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))))