\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\]
↓
\[\begin{array}{l}
t_0 := a \cdot c + b \cdot d\\
t_1 := c \cdot c + d \cdot d\\
t_2 := \frac{a}{c} + d \cdot \frac{b}{{c}^{2}}\\
\mathbf{if}\;c \leq -5.2 \cdot 10^{+134}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq -3.8 \cdot 10^{-162}:\\
\;\;\;\;\frac{t_0}{t_1}\\
\mathbf{elif}\;c \leq 2.6 \cdot 10^{-110}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;c \leq 1.9 \cdot 10^{+34}:\\
\;\;\;\;\frac{1}{t_1} \cdot t_0\\
\mathbf{else}:\\
\;\;\;\;3 \cdot t_2 - 2 \cdot t_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 (+ (* a c) (* b d)))
(t_1 (+ (* c c) (* d d)))
(t_2 (+ (/ a c) (* d (/ b (pow c 2.0))))))
(if (<= c -5.2e+134)
(/ a c)
(if (<= c -3.8e-162)
(/ t_0 t_1)
(if (<= c 2.6e-110)
(/ b d)
(if (<= c 1.9e+34)
(* (/ 1.0 t_1) t_0)
(- (* 3.0 t_2) (* 2.0 t_2))))))))
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 = (a * c) + (b * d);
double t_1 = (c * c) + (d * d);
double t_2 = (a / c) + (d * (b / pow(c, 2.0)));
double tmp;
if (c <= -5.2e+134) {
tmp = a / c;
} else if (c <= -3.8e-162) {
tmp = t_0 / t_1;
} else if (c <= 2.6e-110) {
tmp = b / d;
} else if (c <= 1.9e+34) {
tmp = (1.0 / t_1) * t_0;
} else {
tmp = (3.0 * t_2) - (2.0 * t_2);
}
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) :: t_2
real(8) :: tmp
t_0 = (a * c) + (b * d)
t_1 = (c * c) + (d * d)
t_2 = (a / c) + (d * (b / (c ** 2.0d0)))
if (c <= (-5.2d+134)) then
tmp = a / c
else if (c <= (-3.8d-162)) then
tmp = t_0 / t_1
else if (c <= 2.6d-110) then
tmp = b / d
else if (c <= 1.9d+34) then
tmp = (1.0d0 / t_1) * t_0
else
tmp = (3.0d0 * t_2) - (2.0d0 * t_2)
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 = (a * c) + (b * d);
double t_1 = (c * c) + (d * d);
double t_2 = (a / c) + (d * (b / Math.pow(c, 2.0)));
double tmp;
if (c <= -5.2e+134) {
tmp = a / c;
} else if (c <= -3.8e-162) {
tmp = t_0 / t_1;
} else if (c <= 2.6e-110) {
tmp = b / d;
} else if (c <= 1.9e+34) {
tmp = (1.0 / t_1) * t_0;
} else {
tmp = (3.0 * t_2) - (2.0 * t_2);
}
return tmp;
}
herbie shell --seed 2023096
(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))))