
(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
(let* ((t_0
(fma
(fma
(- (* (/ a (pow c 4.0)) d) (/ b (pow c 3.0)))
d
(/ (/ (- a) c) c))
d
(/ b c))))
(if (<= c -9e-10)
t_0
(if (<= c 2.05e-79)
(/ (fma (/ c d) b (- a)) d)
(if (<= c 9e+153)
(* (/ (fma (/ d b) (- a) c) (fma d d (* c c))) b)
t_0)))))
double code(double a, double b, double c, double d) {
double t_0 = fma(fma((((a / pow(c, 4.0)) * d) - (b / pow(c, 3.0))), d, ((-a / c) / c)), d, (b / c));
double tmp;
if (c <= -9e-10) {
tmp = t_0;
} else if (c <= 2.05e-79) {
tmp = fma((c / d), b, -a) / d;
} else if (c <= 9e+153) {
tmp = (fma((d / b), -a, c) / fma(d, d, (c * c))) * b;
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(fma(Float64(Float64(Float64(a / (c ^ 4.0)) * d) - Float64(b / (c ^ 3.0))), d, Float64(Float64(Float64(-a) / c) / c)), d, Float64(b / c)) tmp = 0.0 if (c <= -9e-10) tmp = t_0; elseif (c <= 2.05e-79) tmp = Float64(fma(Float64(c / d), b, Float64(-a)) / d); elseif (c <= 9e+153) tmp = Float64(Float64(fma(Float64(d / b), Float64(-a), c) / fma(d, d, Float64(c * c))) * b); else tmp = t_0; end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(N[(N[(a / N[Power[c, 4.0], $MachinePrecision]), $MachinePrecision] * d), $MachinePrecision] - N[(b / N[Power[c, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * d + N[(N[((-a) / c), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] * d + N[(b / c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -9e-10], t$95$0, If[LessEqual[c, 2.05e-79], N[(N[(N[(c / d), $MachinePrecision] * b + (-a)), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 9e+153], N[(N[(N[(N[(d / b), $MachinePrecision] * (-a) + c), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\mathsf{fma}\left(\frac{a}{{c}^{4}} \cdot d - \frac{b}{{c}^{3}}, d, \frac{\frac{-a}{c}}{c}\right), d, \frac{b}{c}\right)\\
\mathbf{if}\;c \leq -9 \cdot 10^{-10}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 2.05 \cdot 10^{-79}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, b, -a\right)}{d}\\
\mathbf{elif}\;c \leq 9 \cdot 10^{+153}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{b}, -a, c\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot b\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -8.9999999999999999e-10 or 9.0000000000000002e153 < c Initial program 39.6%
Taylor expanded in d around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites83.9%
if -8.9999999999999999e-10 < c < 2.04999999999999997e-79Initial program 70.5%
Taylor expanded in b around inf
*-commutativeN/A
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
associate-*l/N/A
associate-*r/N/A
mul-1-negN/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-inN/A
Applied rewrites60.2%
Taylor expanded in c around 0
Applied rewrites88.1%
if 2.04999999999999997e-79 < c < 9.0000000000000002e153Initial program 68.8%
Taylor expanded in b around inf
*-commutativeN/A
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
associate-*l/N/A
associate-*r/N/A
mul-1-negN/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-inN/A
Applied rewrites80.1%
Final simplification84.8%
(FPCore (a b c d)
:precision binary64
(if (<= c -9e-10)
(/ (fma (/ (- d) c) a b) c)
(if (<= c 2.05e-79)
(/ (fma (/ c d) b (- a)) d)
(if (<= c 9e+153)
(* (/ (fma (/ d b) (- a) c) (fma d d (* c c))) b)
(/ (- b (* (/ d c) a)) c)))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -9e-10) {
tmp = fma((-d / c), a, b) / c;
} else if (c <= 2.05e-79) {
tmp = fma((c / d), b, -a) / d;
} else if (c <= 9e+153) {
tmp = (fma((d / b), -a, c) / fma(d, d, (c * c))) * b;
} else {
tmp = (b - ((d / c) * a)) / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -9e-10) tmp = Float64(fma(Float64(Float64(-d) / c), a, b) / c); elseif (c <= 2.05e-79) tmp = Float64(fma(Float64(c / d), b, Float64(-a)) / d); elseif (c <= 9e+153) tmp = Float64(Float64(fma(Float64(d / b), Float64(-a), c) / fma(d, d, Float64(c * c))) * b); else tmp = Float64(Float64(b - Float64(Float64(d / c) * a)) / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -9e-10], N[(N[(N[((-d) / c), $MachinePrecision] * a + b), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 2.05e-79], N[(N[(N[(c / d), $MachinePrecision] * b + (-a)), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 9e+153], N[(N[(N[(N[(d / b), $MachinePrecision] * (-a) + c), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision], N[(N[(b - N[(N[(d / c), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -9 \cdot 10^{-10}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{-d}{c}, a, b\right)}{c}\\
\mathbf{elif}\;c \leq 2.05 \cdot 10^{-79}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, b, -a\right)}{d}\\
\mathbf{elif}\;c \leq 9 \cdot 10^{+153}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{d}{b}, -a, c\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)} \cdot b\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{d}{c} \cdot a}{c}\\
\end{array}
\end{array}
if c < -8.9999999999999999e-10Initial program 52.9%
Taylor expanded in c around inf
lower-/.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6479.9
Applied rewrites79.9%
Applied rewrites80.1%
Applied rewrites80.1%
if -8.9999999999999999e-10 < c < 2.04999999999999997e-79Initial program 70.5%
Taylor expanded in b around inf
*-commutativeN/A
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
associate-*l/N/A
associate-*r/N/A
mul-1-negN/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-inN/A
Applied rewrites60.2%
Taylor expanded in c around 0
Applied rewrites88.1%
if 2.04999999999999997e-79 < c < 9.0000000000000002e153Initial program 68.8%
Taylor expanded in b around inf
*-commutativeN/A
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
associate-*l/N/A
associate-*r/N/A
mul-1-negN/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-inN/A
Applied rewrites80.1%
if 9.0000000000000002e153 < c Initial program 23.8%
Taylor expanded in c around inf
lower-/.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6477.5
Applied rewrites77.5%
Applied rewrites87.9%
Final simplification84.8%
(FPCore (a b c d) :precision binary64 (if (or (<= c -9e-10) (not (<= c 9.2e+23))) (/ (- b (* (/ d c) a)) c) (/ (fma (/ c d) b (- a)) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -9e-10) || !(c <= 9.2e+23)) {
tmp = (b - ((d / c) * a)) / c;
} else {
tmp = fma((c / d), b, -a) / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if ((c <= -9e-10) || !(c <= 9.2e+23)) tmp = Float64(Float64(b - Float64(Float64(d / c) * a)) / c); else tmp = Float64(fma(Float64(c / d), b, Float64(-a)) / d); end return tmp end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -9e-10], N[Not[LessEqual[c, 9.2e+23]], $MachinePrecision]], N[(N[(b - N[(N[(d / c), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(N[(N[(c / d), $MachinePrecision] * b + (-a)), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -9 \cdot 10^{-10} \lor \neg \left(c \leq 9.2 \cdot 10^{+23}\right):\\
\;\;\;\;\frac{b - \frac{d}{c} \cdot a}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, b, -a\right)}{d}\\
\end{array}
\end{array}
if c < -8.9999999999999999e-10 or 9.2000000000000002e23 < c Initial program 45.2%
Taylor expanded in c around inf
lower-/.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6477.9
Applied rewrites77.9%
Applied rewrites81.7%
if -8.9999999999999999e-10 < c < 9.2000000000000002e23Initial program 71.3%
Taylor expanded in b around inf
*-commutativeN/A
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
associate-*l/N/A
associate-*r/N/A
mul-1-negN/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-inN/A
Applied rewrites61.9%
Taylor expanded in c around 0
Applied rewrites84.6%
Final simplification83.1%
(FPCore (a b c d) :precision binary64 (if (or (<= c -9e-10) (not (<= c 5.2e+29))) (/ b c) (/ (fma (/ c d) b (- a)) d)))
double code(double a, double b, double c, double d) {
double tmp;
if ((c <= -9e-10) || !(c <= 5.2e+29)) {
tmp = b / c;
} else {
tmp = fma((c / d), b, -a) / d;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if ((c <= -9e-10) || !(c <= 5.2e+29)) tmp = Float64(b / c); else tmp = Float64(fma(Float64(c / d), b, Float64(-a)) / d); end return tmp end
code[a_, b_, c_, d_] := If[Or[LessEqual[c, -9e-10], N[Not[LessEqual[c, 5.2e+29]], $MachinePrecision]], N[(b / c), $MachinePrecision], N[(N[(N[(c / d), $MachinePrecision] * b + (-a)), $MachinePrecision] / d), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -9 \cdot 10^{-10} \lor \neg \left(c \leq 5.2 \cdot 10^{+29}\right):\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, b, -a\right)}{d}\\
\end{array}
\end{array}
if c < -8.9999999999999999e-10 or 5.2e29 < c Initial program 45.2%
Taylor expanded in c around inf
lower-/.f6469.4
Applied rewrites69.4%
if -8.9999999999999999e-10 < c < 5.2e29Initial program 71.3%
Taylor expanded in b around inf
*-commutativeN/A
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
associate-*l/N/A
associate-*r/N/A
mul-1-negN/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-inN/A
Applied rewrites61.9%
Taylor expanded in c around 0
Applied rewrites84.6%
Final simplification76.7%
(FPCore (a b c d) :precision binary64 (if (<= c -9e-10) (/ (fma (/ (- d) c) a b) c) (if (<= c 9.2e+23) (/ (fma (/ c d) b (- a)) d) (/ (- b (* (/ d c) a)) c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -9e-10) {
tmp = fma((-d / c), a, b) / c;
} else if (c <= 9.2e+23) {
tmp = fma((c / d), b, -a) / d;
} else {
tmp = (b - ((d / c) * a)) / c;
}
return tmp;
}
function code(a, b, c, d) tmp = 0.0 if (c <= -9e-10) tmp = Float64(fma(Float64(Float64(-d) / c), a, b) / c); elseif (c <= 9.2e+23) tmp = Float64(fma(Float64(c / d), b, Float64(-a)) / d); else tmp = Float64(Float64(b - Float64(Float64(d / c) * a)) / c); end return tmp end
code[a_, b_, c_, d_] := If[LessEqual[c, -9e-10], N[(N[(N[((-d) / c), $MachinePrecision] * a + b), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[c, 9.2e+23], N[(N[(N[(c / d), $MachinePrecision] * b + (-a)), $MachinePrecision] / d), $MachinePrecision], N[(N[(b - N[(N[(d / c), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -9 \cdot 10^{-10}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{-d}{c}, a, b\right)}{c}\\
\mathbf{elif}\;c \leq 9.2 \cdot 10^{+23}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{c}{d}, b, -a\right)}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - \frac{d}{c} \cdot a}{c}\\
\end{array}
\end{array}
if c < -8.9999999999999999e-10Initial program 52.9%
Taylor expanded in c around inf
lower-/.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6479.9
Applied rewrites79.9%
Applied rewrites80.1%
Applied rewrites80.1%
if -8.9999999999999999e-10 < c < 9.2000000000000002e23Initial program 71.3%
Taylor expanded in b around inf
*-commutativeN/A
+-commutativeN/A
remove-double-negN/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
mul-1-negN/A
associate-*l/N/A
associate-*r/N/A
mul-1-negN/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-inN/A
Applied rewrites61.9%
Taylor expanded in c around 0
Applied rewrites84.6%
if 9.2000000000000002e23 < c Initial program 39.6%
Taylor expanded in c around inf
lower-/.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6476.4
Applied rewrites76.4%
Applied rewrites82.8%
Final simplification83.1%
(FPCore (a b c d) :precision binary64 (if (or (<= d -6.2e+83) (not (<= d 2.2e+23))) (/ (- a) d) (/ b c)))
double code(double a, double b, double c, double d) {
double tmp;
if ((d <= -6.2e+83) || !(d <= 2.2e+23)) {
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 <= (-6.2d+83)) .or. (.not. (d <= 2.2d+23))) 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 <= -6.2e+83) || !(d <= 2.2e+23)) {
tmp = -a / d;
} else {
tmp = b / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if (d <= -6.2e+83) or not (d <= 2.2e+23): tmp = -a / d else: tmp = b / c return tmp
function code(a, b, c, d) tmp = 0.0 if ((d <= -6.2e+83) || !(d <= 2.2e+23)) 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 <= -6.2e+83) || ~((d <= 2.2e+23))) tmp = -a / d; else tmp = b / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Or[LessEqual[d, -6.2e+83], N[Not[LessEqual[d, 2.2e+23]], $MachinePrecision]], N[((-a) / d), $MachinePrecision], N[(b / c), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -6.2 \cdot 10^{+83} \lor \neg \left(d \leq 2.2 \cdot 10^{+23}\right):\\
\;\;\;\;\frac{-a}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\end{array}
\end{array}
if d < -6.19999999999999984e83 or 2.20000000000000008e23 < d Initial program 45.5%
Taylor expanded in c around 0
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6472.7
Applied rewrites72.7%
if -6.19999999999999984e83 < d < 2.20000000000000008e23Initial program 65.3%
Taylor expanded in c around inf
lower-/.f6465.4
Applied rewrites65.4%
Final simplification68.2%
(FPCore (a b c d) :precision binary64 (/ b c))
double code(double a, double b, double c, double d) {
return b / c;
}
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
end function
public static double code(double a, double b, double c, double d) {
return b / c;
}
def code(a, b, c, d): return b / c
function code(a, b, c, d) return Float64(b / c) end
function tmp = code(a, b, c, d) tmp = b / c; end
code[a_, b_, c_, d_] := N[(b / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{b}{c}
\end{array}
Initial program 57.8%
Taylor expanded in c around inf
lower-/.f6447.1
Applied rewrites47.1%
(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 2024344
(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))))