
(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
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
public static double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
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
public static double code(double a, double b, double c, double d) {
return ((b * c) - (a * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((b * c) - (a * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(b * c) - Float64(a * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((b * c) - (a * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(b * c), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\end{array}
(FPCore (a b c d) :precision binary64 (if (<= d -7.2e+25) (/ (- (* (/ b d) c) a) d) (if (<= d 1.22e-53) (/ (- b (/ (* d a) c)) c) (/ (- (* b (/ c d)) a) d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -7.2e+25) {
tmp = (((b / d) * c) - a) / d;
} else if (d <= 1.22e-53) {
tmp = (b - ((d * a) / c)) / c;
} else {
tmp = ((b * (c / d)) - a) / 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
real(8) :: tmp
if (d <= (-7.2d+25)) then
tmp = (((b / d) * c) - a) / d
else if (d <= 1.22d-53) then
tmp = (b - ((d * a) / c)) / c
else
tmp = ((b * (c / d)) - a) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -7.2e+25) {
tmp = (((b / d) * c) - a) / d;
} else if (d <= 1.22e-53) {
tmp = (b - ((d * a) / c)) / c;
} else {
tmp = ((b * (c / d)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -7.2e+25: tmp = (((b / d) * c) - a) / d elif d <= 1.22e-53: tmp = (b - ((d * a) / c)) / c else: tmp = ((b * (c / d)) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -7.2e+25) tmp = Float64(Float64(Float64(Float64(b / d) * c) - a) / d); elseif (d <= 1.22e-53) tmp = Float64(Float64(b - Float64(Float64(d * a) / c)) / c); else tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -7.2e+25) tmp = (((b / d) * c) - a) / d; elseif (d <= 1.22e-53) tmp = (b - ((d * a) / c)) / c; else tmp = ((b * (c / d)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -7.2e+25], N[(N[(N[(N[(b / d), $MachinePrecision] * c), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 1.22e-53], N[(N[(b - N[(N[(d * a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -7.2 \cdot 10^{+25}:\\
\;\;\;\;\frac{\frac{b}{d} \cdot c - a}{d}\\
\mathbf{elif}\;d \leq 1.22 \cdot 10^{-53}:\\
\;\;\;\;\frac{b - \frac{d \cdot a}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\end{array}
\end{array}
if d < -7.20000000000000031e25Initial program 55.4%
fma-define55.4%
Simplified55.4%
Taylor expanded in c around 0 82.1%
+-commutative82.1%
mul-1-neg82.1%
unsub-neg82.1%
unpow282.1%
associate-/r*82.3%
div-sub82.3%
associate-/l*84.4%
Simplified84.4%
clear-num84.5%
un-div-inv84.5%
Applied egg-rr84.5%
associate-/r/87.5%
Applied egg-rr87.5%
if -7.20000000000000031e25 < d < 1.22000000000000003e-53Initial program 74.4%
fma-define74.4%
Simplified74.4%
Taylor expanded in c around inf 90.0%
associate-*r/90.0%
neg-mul-190.0%
distribute-rgt-neg-in90.0%
Simplified90.0%
if 1.22000000000000003e-53 < d Initial program 50.7%
fma-define50.7%
Simplified50.7%
Taylor expanded in c around 0 74.2%
+-commutative74.2%
mul-1-neg74.2%
unsub-neg74.2%
unpow274.2%
associate-/r*77.1%
div-sub77.1%
associate-/l*78.5%
Simplified78.5%
Final simplification85.8%
(FPCore (a b c d) :precision binary64 (if (or (<= d -1.8e+26) (not (<= d 1.3e-53))) (/ (- (* b (/ c d)) a) d) (/ (- b (* a (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.8e+26) || !(d <= 1.3e-53)) {
tmp = ((b * (c / d)) - a) / d;
} else {
tmp = (b - (a * (d / c))) / c;
}
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
real(8) :: tmp
if ((d <= (-1.8d+26)) .or. (.not. (d <= 1.3d-53))) then
tmp = ((b * (c / d)) - a) / d
else
tmp = (b - (a * (d / c))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -1.8e+26) || !(d <= 1.3e-53)) {
tmp = ((b * (c / d)) - a) / d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -1.8e+26) or not (d <= 1.3e-53): tmp = ((b * (c / d)) - a) / d else: tmp = (b - (a * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -1.8e+26) || !(d <= 1.3e-53)) tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); else tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -1.8e+26) || ~((d <= 1.3e-53))) tmp = ((b * (c / d)) - a) / d; else tmp = (b - (a * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -1.8e+26], N[Not[LessEqual[d, 1.3e-53]], $MachinePrecision]], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.8 \cdot 10^{+26} \lor \neg \left(d \leq 1.3 \cdot 10^{-53}\right):\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -1.80000000000000012e26 or 1.29999999999999998e-53 < d Initial program 52.7%
fma-define52.7%
Simplified52.7%
Taylor expanded in c around 0 77.6%
+-commutative77.6%
mul-1-neg77.6%
unsub-neg77.6%
unpow277.6%
associate-/r*79.3%
div-sub79.3%
associate-/l*81.0%
Simplified81.0%
if -1.80000000000000012e26 < d < 1.29999999999999998e-53Initial program 74.4%
fma-define74.4%
Simplified74.4%
Taylor expanded in c around inf 90.0%
mul-1-neg90.0%
unsub-neg90.0%
associate-/l*90.0%
Simplified90.0%
Final simplification85.1%
(FPCore (a b c d) :precision binary64 (if (or (<= d -3.2e+26) (not (<= d 8.5e-39))) (/ (- a) d) (/ (- b (* a (/ d c))) c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -3.2e+26) || !(d <= 8.5e-39)) {
tmp = -a / d;
} else {
tmp = (b - (a * (d / c))) / c;
}
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
real(8) :: tmp
if ((d <= (-3.2d+26)) .or. (.not. (d <= 8.5d-39))) then
tmp = -a / d
else
tmp = (b - (a * (d / c))) / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -3.2e+26) || !(d <= 8.5e-39)) {
tmp = -a / d;
} else {
tmp = (b - (a * (d / c))) / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -3.2e+26) or not (d <= 8.5e-39): tmp = -a / d else: tmp = (b - (a * (d / c))) / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -3.2e+26) || !(d <= 8.5e-39)) tmp = Float64(Float64(-a) / d); else tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -3.2e+26) || ~((d <= 8.5e-39))) tmp = -a / d; else tmp = (b - (a * (d / c))) / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -3.2e+26], N[Not[LessEqual[d, 8.5e-39]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -3.2 \cdot 10^{+26} \lor \neg \left(d \leq 8.5 \cdot 10^{-39}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\end{array}
\end{array}
if d < -3.20000000000000029e26 or 8.5000000000000005e-39 < d Initial program 51.7%
fma-define51.7%
Simplified51.7%
Taylor expanded in c around 0 72.4%
associate-*r/72.4%
neg-mul-172.4%
Simplified72.4%
if -3.20000000000000029e26 < d < 8.5000000000000005e-39Initial program 75.0%
fma-define75.0%
Simplified75.0%
Taylor expanded in c around inf 88.7%
mul-1-neg88.7%
unsub-neg88.7%
associate-/l*88.6%
Simplified88.6%
Final simplification80.0%
(FPCore (a b c d) :precision binary64 (if (<= d -1.2e+28) (/ (- (* (/ b d) c) a) d) (if (<= d 1.3e-53) (/ (- b (* a (/ d c))) c) (/ (- (* b (/ c d)) a) d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.2e+28) {
tmp = (((b / d) * c) - a) / d;
} else if (d <= 1.3e-53) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = ((b * (c / d)) - a) / 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
real(8) :: tmp
if (d <= (-1.2d+28)) then
tmp = (((b / d) * c) - a) / d
else if (d <= 1.3d-53) then
tmp = (b - (a * (d / c))) / c
else
tmp = ((b * (c / d)) - a) / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -1.2e+28) {
tmp = (((b / d) * c) - a) / d;
} else if (d <= 1.3e-53) {
tmp = (b - (a * (d / c))) / c;
} else {
tmp = ((b * (c / d)) - a) / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -1.2e+28: tmp = (((b / d) * c) - a) / d elif d <= 1.3e-53: tmp = (b - (a * (d / c))) / c else: tmp = ((b * (c / d)) - a) / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -1.2e+28) tmp = Float64(Float64(Float64(Float64(b / d) * c) - a) / d); elseif (d <= 1.3e-53) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / c); else tmp = Float64(Float64(Float64(b * Float64(c / d)) - a) / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -1.2e+28) tmp = (((b / d) * c) - a) / d; elseif (d <= 1.3e-53) tmp = (b - (a * (d / c))) / c; else tmp = ((b * (c / d)) - a) / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -1.2e+28], N[(N[(N[(N[(b / d), $MachinePrecision] * c), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[d, 1.3e-53], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision] - a), $MachinePrecision] / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -1.2 \cdot 10^{+28}:\\
\;\;\;\;\frac{\frac{b}{d} \cdot c - a}{d}\\
\mathbf{elif}\;d \leq 1.3 \cdot 10^{-53}:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot \frac{c}{d} - a}{d}\\
\end{array}
\end{array}
if d < -1.19999999999999991e28Initial program 55.4%
fma-define55.4%
Simplified55.4%
Taylor expanded in c around 0 82.1%
+-commutative82.1%
mul-1-neg82.1%
unsub-neg82.1%
unpow282.1%
associate-/r*82.3%
div-sub82.3%
associate-/l*84.4%
Simplified84.4%
clear-num84.5%
un-div-inv84.5%
Applied egg-rr84.5%
associate-/r/87.5%
Applied egg-rr87.5%
if -1.19999999999999991e28 < d < 1.29999999999999998e-53Initial program 74.4%
fma-define74.4%
Simplified74.4%
Taylor expanded in c around inf 90.0%
mul-1-neg90.0%
unsub-neg90.0%
associate-/l*90.0%
Simplified90.0%
if 1.29999999999999998e-53 < d Initial program 50.7%
fma-define50.7%
Simplified50.7%
Taylor expanded in c around 0 74.2%
+-commutative74.2%
mul-1-neg74.2%
unsub-neg74.2%
unpow274.2%
associate-/r*77.1%
div-sub77.1%
associate-/l*78.5%
Simplified78.5%
(FPCore (a b c d) :precision binary64 (if (or (<= d -2.7e+29) (not (<= d 8e-39))) (/ (- a) d) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.7e+29) || !(d <= 8e-39)) {
tmp = -a / d;
} else {
tmp = b / c;
}
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
real(8) :: tmp
if ((d <= (-2.7d+29)) .or. (.not. (d <= 8d-39))) then
tmp = -a / d
else
tmp = b / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -2.7e+29) || !(d <= 8e-39)) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -2.7e+29) or not (d <= 8e-39): tmp = -a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -2.7e+29) || !(d <= 8e-39)) tmp = Float64(Float64(-a) / d); else tmp = Float64(b / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if ((d <= -2.7e+29) || ~((d <= 8e-39))) tmp = -a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -2.7e+29], N[Not[LessEqual[d, 8e-39]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -2.7 \cdot 10^{+29} \lor \neg \left(d \leq 8 \cdot 10^{-39}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -2.7e29 or 7.99999999999999943e-39 < d Initial program 51.7%
fma-define51.7%
Simplified51.7%
Taylor expanded in c around 0 72.4%
associate-*r/72.4%
neg-mul-172.4%
Simplified72.4%
if -2.7e29 < d < 7.99999999999999943e-39Initial program 75.0%
fma-define75.0%
Simplified75.0%
Taylor expanded in c around inf 71.5%
Final simplification72.0%
(FPCore (a b c d) :precision binary64 (if (<= d -4.4e+246) (/ a d) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -4.4e+246) {
tmp = a / d;
} else {
tmp = b / c;
}
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
real(8) :: tmp
if (d <= (-4.4d+246)) then
tmp = a / d
else
tmp = b / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -4.4e+246) {
tmp = a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -4.4e+246: tmp = a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -4.4e+246) tmp = Float64(a / d); else tmp = Float64(b / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -4.4e+246) tmp = a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -4.4e+246], N[(a / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -4.4 \cdot 10^{+246}:\\
\;\;\;\;\frac{a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -4.39999999999999976e246Initial program 43.5%
fma-define43.5%
Simplified43.5%
Taylor expanded in c around 0 93.6%
associate-*r/93.6%
neg-mul-193.6%
Simplified93.6%
div-inv93.6%
add-sqr-sqrt40.0%
sqrt-unprod50.9%
sqr-neg50.9%
sqrt-unprod24.2%
add-sqr-sqrt44.7%
Applied egg-rr44.7%
associate-*r/44.7%
*-rgt-identity44.7%
Simplified44.7%
if -4.39999999999999976e246 < d Initial program 63.7%
fma-define63.7%
Simplified63.7%
Taylor expanded in c around inf 46.2%
(FPCore (a b c d) :precision binary64 (/ a d))
double code(double a, double b, double c, double d) {
return a / 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 / d
end function
public static double code(double a, double b, double c, double d) {
return a / d;
}
def code(a, b, c, d): return a / d
function code(a, b, c, d) return Float64(a / d) end
function tmp = code(a, b, c, d) tmp = a / d; end
code[a_, b_, c_, d_] := N[(a / d), $MachinePrecision]
\begin{array}{l}
\\
\frac{a}{d}
\end{array}
Initial program 62.5%
fma-define62.5%
Simplified62.5%
Taylor expanded in c around 0 45.2%
associate-*r/45.2%
neg-mul-145.2%
Simplified45.2%
div-inv45.0%
add-sqr-sqrt20.6%
sqrt-unprod22.9%
sqr-neg22.9%
sqrt-unprod6.0%
add-sqr-sqrt10.0%
Applied egg-rr10.0%
associate-*r/10.0%
*-rgt-identity10.0%
Simplified10.0%
(FPCore (a b c d) :precision binary64 (if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (fabs(d) < fabs(c)) {
tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (-a + (b * (c / d))) / (d + (c * (c / 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
real(8) :: tmp
if (abs(d) < abs(c)) then
tmp = (b - (a * (d / c))) / (c + (d * (d / c)))
else
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (Math.abs(d) < Math.abs(c)) {
tmp = (b - (a * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (-a + (b * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if math.fabs(d) < math.fabs(c): tmp = (b - (a * (d / c))) / (c + (d * (d / c))) else: tmp = (-a + (b * (c / d))) / (d + (c * (c / d))) return tmp
function code(a, b, c, d) tmp = 0.0 if (abs(d) < abs(c)) tmp = Float64(Float64(b - Float64(a * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c)))); else tmp = Float64(Float64(Float64(-a) + Float64(b * Float64(c / d))) / Float64(d + Float64(c * Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (abs(d) < abs(c)) tmp = (b - (a * (d / c))) / (c + (d * (d / c))); else tmp = (-a + (b * (c / d))) / (d + (c * (c / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Less[N[Abs[d], $MachinePrecision], N[Abs[c], $MachinePrecision]], N[(N[(b - N[(a * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-a) + N[(b * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d + N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|d\right| < \left|c\right|:\\
\;\;\;\;\frac{b - a \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-a\right) + b \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
herbie shell --seed 2024145
(FPCore (a b c d)
:name "Complex division, imag part"
:precision binary64
:alt
(! :herbie-platform default (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))))