\[\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\]
↓
\[\begin{array}{l}
t_0 := c \cdot c + d \cdot d\\
t_1 := a \cdot \frac{-d}{t_0}\\
t_2 := \frac{b}{c} + t_1\\
t_3 := b \cdot \frac{c}{t_0}\\
\mathbf{if}\;c \leq -3.6 \cdot 10^{+68}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;c \leq -8.2 \cdot 10^{-122}:\\
\;\;\;\;t_1 - c \cdot \frac{-b}{t_0}\\
\mathbf{elif}\;c \leq 1.12 \cdot 10^{-112}:\\
\;\;\;\;t_3 + a \cdot \frac{-1}{d}\\
\mathbf{elif}\;c \leq 3 \cdot 10^{+153}:\\
\;\;\;\;t_3 + t_1\\
\mathbf{else}:\\
\;\;\;\;t_2\\
\end{array}
\]
(FPCore (a b c d)
:precision binary64
(/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
↓
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (+ (* c c) (* d d)))
(t_1 (* a (/ (- d) t_0)))
(t_2 (+ (/ b c) t_1))
(t_3 (* b (/ c t_0))))
(if (<= c -3.6e+68)
t_2
(if (<= c -8.2e-122)
(- t_1 (* c (/ (- b) t_0)))
(if (<= c 1.12e-112)
(+ t_3 (* a (/ -1.0 d)))
(if (<= c 3e+153) (+ t_3 t_1) t_2))))))
double code(double a, double b, double c, double d) {
return ((b * c) - (a * 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 = ((b * c) - (a * 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) :: t_3
real(8) :: tmp
t_0 = (c * c) + (d * d)
t_1 = a * (-d / t_0)
t_2 = (b / c) + t_1
t_3 = b * (c / t_0)
if (c <= (-3.6d+68)) then
tmp = t_2
else if (c <= (-8.2d-122)) then
tmp = t_1 - (c * (-b / t_0))
else if (c <= 1.12d-112) then
tmp = t_3 + (a * ((-1.0d0) / d))
else if (c <= 3d+153) then
tmp = t_3 + t_1
else
tmp = t_2
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
return ((b * c) - (a * 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 * (-d / t_0);
double t_2 = (b / c) + t_1;
double t_3 = b * (c / t_0);
double tmp;
if (c <= -3.6e+68) {
tmp = t_2;
} else if (c <= -8.2e-122) {
tmp = t_1 - (c * (-b / t_0));
} else if (c <= 1.12e-112) {
tmp = t_3 + (a * (-1.0 / d));
} else if (c <= 3e+153) {
tmp = t_3 + t_1;
} else {
tmp = t_2;
}
return tmp;
}
def code(a, b, c, d):
return ((b * c) - (a * d)) / ((c * c) + (d * d))
↓
def code(a, b, c, d):
t_0 = (c * c) + (d * d)
t_1 = a * (-d / t_0)
t_2 = (b / c) + t_1
t_3 = b * (c / t_0)
tmp = 0
if c <= -3.6e+68:
tmp = t_2
elif c <= -8.2e-122:
tmp = t_1 - (c * (-b / t_0))
elif c <= 1.12e-112:
tmp = t_3 + (a * (-1.0 / d))
elif c <= 3e+153:
tmp = t_3 + t_1
else:
tmp = t_2
return tmp
function code(a, b, c, d)
return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d)))
end
herbie shell --seed 2023096
(FPCore (a b c d)
:name "Complex division, imag part"
:precision binary64
:herbie-target
(if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d)))))
(/ (- (* b c) (* a d)) (+ (* c c) (* d d))))