\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\]
↓
\[\begin{array}{l}
t_0 := c \cdot c + d \cdot d\\
t_1 := a \cdot c + b \cdot d\\
\mathbf{if}\;d \leq -8.5 \cdot 10^{+102}:\\
\;\;\;\;\frac{b}{d} + c \cdot \frac{a}{{d}^{2}}\\
\mathbf{elif}\;d \leq -4.8 \cdot 10^{-127}:\\
\;\;\;\;\frac{1}{t_0} \cdot t_1\\
\mathbf{elif}\;d \leq 1.6 \cdot 10^{-104}:\\
\;\;\;\;\frac{a}{c} + \frac{b}{\frac{{c}^{2}}{d}}\\
\mathbf{elif}\;d \leq 4 \cdot 10^{+136}:\\
\;\;\;\;\frac{t_1}{t_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\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 (+ (* c c) (* d d))) (t_1 (+ (* a c) (* b d))))
(if (<= d -8.5e+102)
(+ (/ b d) (* c (/ a (pow d 2.0))))
(if (<= d -4.8e-127)
(* (/ 1.0 t_0) t_1)
(if (<= d 1.6e-104)
(+ (/ a c) (/ b (/ (pow c 2.0) d)))
(if (<= d 4e+136) (/ t_1 t_0) (/ b d)))))))
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 = (c * c) + (d * d);
double t_1 = (a * c) + (b * d);
double tmp;
if (d <= -8.5e+102) {
tmp = (b / d) + (c * (a / pow(d, 2.0)));
} else if (d <= -4.8e-127) {
tmp = (1.0 / t_0) * t_1;
} else if (d <= 1.6e-104) {
tmp = (a / c) + (b / (pow(c, 2.0) / d));
} else if (d <= 4e+136) {
tmp = t_1 / t_0;
} else {
tmp = b / d;
}
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 = (c * c) + (d * d)
t_1 = (a * c) + (b * d)
if (d <= (-8.5d+102)) then
tmp = (b / d) + (c * (a / (d ** 2.0d0)))
else if (d <= (-4.8d-127)) then
tmp = (1.0d0 / t_0) * t_1
else if (d <= 1.6d-104) then
tmp = (a / c) + (b / ((c ** 2.0d0) / d))
else if (d <= 4d+136) then
tmp = t_1 / t_0
else
tmp = b / d
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 = (c * c) + (d * d);
double t_1 = (a * c) + (b * d);
double tmp;
if (d <= -8.5e+102) {
tmp = (b / d) + (c * (a / Math.pow(d, 2.0)));
} else if (d <= -4.8e-127) {
tmp = (1.0 / t_0) * t_1;
} else if (d <= 1.6e-104) {
tmp = (a / c) + (b / (Math.pow(c, 2.0) / d));
} else if (d <= 4e+136) {
tmp = t_1 / t_0;
} else {
tmp = b / d;
}
return tmp;
}
herbie shell --seed 2023065
(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))))