\[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\]
↓
\[\begin{array}{l}
t_0 := \frac{b}{d} + c \cdot \left({\left(\frac{1}{d}\right)}^{2} \cdot a\right)\\
\mathbf{if}\;d \leq -3.1 \cdot 10^{+53}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq -4.5 \cdot 10^{-152}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 1.5 \cdot 10^{-81}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\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) (* c (* (pow (/ 1.0 d) 2.0) a)))))
(if (<= d -3.1e+53)
t_0
(if (<= d -4.5e-152)
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d)))
(if (<= d 1.5e-81) (/ a c) t_0)))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
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) :: tmp
t_0 = (b / d) + (c * (((1.0d0 / d) ** 2.0d0) * a))
if (d <= (-3.1d+53)) then
tmp = t_0
else if (d <= (-4.5d-152)) then
tmp = ((a * c) + (b * d)) / ((c * c) + (d * d))
else if (d <= 1.5d-81) then
tmp = a / c
else
tmp = t_0
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));
}
herbie shell --seed 2023033
(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))))