
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
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
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
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
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ (* a c) (* d b)) (+ (* c c) (* d d))))
(t_1 (/ (+ b (* (/ a d) c)) d)))
(if (<= d -4e+80)
t_1
(if (<= d -8.8e-112)
t_0
(if (<= d 3.5e-164)
(/ (+ a (/ (* d b) c)) c)
(if (<= d 2.8e+25) t_0 t_1))))))
double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (d * b)) / ((c * c) + (d * d));
double t_1 = (b + ((a / d) * c)) / d;
double tmp;
if (d <= -4e+80) {
tmp = t_1;
} else if (d <= -8.8e-112) {
tmp = t_0;
} else if (d <= 3.5e-164) {
tmp = (a + ((d * b) / c)) / c;
} else if (d <= 2.8e+25) {
tmp = t_0;
} else {
tmp = t_1;
}
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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = ((a * c) + (d * b)) / ((c * c) + (d * d))
t_1 = (b + ((a / d) * c)) / d
if (d <= (-4d+80)) then
tmp = t_1
else if (d <= (-8.8d-112)) then
tmp = t_0
else if (d <= 3.5d-164) then
tmp = (a + ((d * b) / c)) / c
else if (d <= 2.8d+25) then
tmp = t_0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = ((a * c) + (d * b)) / ((c * c) + (d * d));
double t_1 = (b + ((a / d) * c)) / d;
double tmp;
if (d <= -4e+80) {
tmp = t_1;
} else if (d <= -8.8e-112) {
tmp = t_0;
} else if (d <= 3.5e-164) {
tmp = (a + ((d * b) / c)) / c;
} else if (d <= 2.8e+25) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(a, b, c, d): t_0 = ((a * c) + (d * b)) / ((c * c) + (d * d)) t_1 = (b + ((a / d) * c)) / d tmp = 0 if d <= -4e+80: tmp = t_1 elif d <= -8.8e-112: tmp = t_0 elif d <= 3.5e-164: tmp = (a + ((d * b) / c)) / c elif d <= 2.8e+25: tmp = t_0 else: tmp = t_1 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(Float64(a * c) + Float64(d * b)) / Float64(Float64(c * c) + Float64(d * d))) t_1 = Float64(Float64(b + Float64(Float64(a / d) * c)) / d) tmp = 0.0 if (d <= -4e+80) tmp = t_1; elseif (d <= -8.8e-112) tmp = t_0; elseif (d <= 3.5e-164) tmp = Float64(Float64(a + Float64(Float64(d * b) / c)) / c); elseif (d <= 2.8e+25) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = ((a * c) + (d * b)) / ((c * c) + (d * d)); t_1 = (b + ((a / d) * c)) / d; tmp = 0.0; if (d <= -4e+80) tmp = t_1; elseif (d <= -8.8e-112) tmp = t_0; elseif (d <= 3.5e-164) tmp = (a + ((d * b) / c)) / c; elseif (d <= 2.8e+25) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(N[(a * c), $MachinePrecision] + N[(d * b), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(b + N[(N[(a / d), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -4e+80], t$95$1, If[LessEqual[d, -8.8e-112], t$95$0, If[LessEqual[d, 3.5e-164], N[(N[(a + N[(N[(d * b), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], If[LessEqual[d, 2.8e+25], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a \cdot c + d \cdot b}{c \cdot c + d \cdot d}\\
t_1 := \frac{b + \frac{a}{d} \cdot c}{d}\\
\mathbf{if}\;d \leq -4 \cdot 10^{+80}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;d \leq -8.8 \cdot 10^{-112}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 3.5 \cdot 10^{-164}:\\
\;\;\;\;\frac{a + \frac{d \cdot b}{c}}{c}\\
\mathbf{elif}\;d \leq 2.8 \cdot 10^{+25}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if d < -4e80 or 2.8000000000000002e25 < d Initial program 40.9%
Taylor expanded in d around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f6480.7%
Simplified80.7%
associate-/l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
/-lowering-/.f6483.1%
Applied egg-rr83.1%
if -4e80 < d < -8.80000000000000085e-112 or 3.5e-164 < d < 2.8000000000000002e25Initial program 84.1%
if -8.80000000000000085e-112 < d < 3.5e-164Initial program 59.4%
Taylor expanded in c around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f6492.7%
Simplified92.7%
Final simplification86.3%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (+ b (* (/ a d) c)) d)))
(if (<= d -270000000000.0)
t_0
(if (<= d 3.9e+87) (/ (+ a (/ (* d b) c)) c) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = (b + ((a / d) * c)) / d;
double tmp;
if (d <= -270000000000.0) {
tmp = t_0;
} else if (d <= 3.9e+87) {
tmp = (a + ((d * b) / c)) / c;
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = (b + ((a / d) * c)) / d
if (d <= (-270000000000.0d0)) then
tmp = t_0
else if (d <= 3.9d+87) then
tmp = (a + ((d * b) / c)) / c
else
tmp = t_0
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = (b + ((a / d) * c)) / d;
double tmp;
if (d <= -270000000000.0) {
tmp = t_0;
} else if (d <= 3.9e+87) {
tmp = (a + ((d * b) / c)) / c;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (b + ((a / d) * c)) / d tmp = 0 if d <= -270000000000.0: tmp = t_0 elif d <= 3.9e+87: tmp = (a + ((d * b) / c)) / c else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(b + Float64(Float64(a / d) * c)) / d) tmp = 0.0 if (d <= -270000000000.0) tmp = t_0; elseif (d <= 3.9e+87) tmp = Float64(Float64(a + Float64(Float64(d * b) / c)) / c); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (b + ((a / d) * c)) / d; tmp = 0.0; if (d <= -270000000000.0) tmp = t_0; elseif (d <= 3.9e+87) tmp = (a + ((d * b) / c)) / c; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(b + N[(N[(a / d), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision]}, If[LessEqual[d, -270000000000.0], t$95$0, If[LessEqual[d, 3.9e+87], N[(N[(a + N[(N[(d * b), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b + \frac{a}{d} \cdot c}{d}\\
\mathbf{if}\;d \leq -270000000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;d \leq 3.9 \cdot 10^{+87}:\\
\;\;\;\;\frac{a + \frac{d \cdot b}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if d < -2.7e11 or 3.9000000000000002e87 < d Initial program 50.2%
Taylor expanded in d around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f6482.9%
Simplified82.9%
associate-/l*N/A
*-commutativeN/A
*-lowering-*.f64N/A
/-lowering-/.f6485.0%
Applied egg-rr85.0%
if -2.7e11 < d < 3.9000000000000002e87Initial program 68.2%
Taylor expanded in c around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f6474.7%
Simplified74.7%
Final simplification78.5%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ (+ a (/ (* d b) c)) c))) (if (<= c -4.2e+72) t_0 (if (<= c 1.9e+31) (/ (+ b (* a (/ c d))) d) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = (a + ((d * b) / c)) / c;
double tmp;
if (c <= -4.2e+72) {
tmp = t_0;
} else if (c <= 1.9e+31) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = (a + ((d * b) / c)) / c
if (c <= (-4.2d+72)) then
tmp = t_0
else if (c <= 1.9d+31) then
tmp = (b + (a * (c / d))) / d
else
tmp = t_0
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = (a + ((d * b) / c)) / c;
double tmp;
if (c <= -4.2e+72) {
tmp = t_0;
} else if (c <= 1.9e+31) {
tmp = (b + (a * (c / d))) / d;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (a + ((d * b) / c)) / c tmp = 0 if c <= -4.2e+72: tmp = t_0 elif c <= 1.9e+31: tmp = (b + (a * (c / d))) / d else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(a + Float64(Float64(d * b) / c)) / c) tmp = 0.0 if (c <= -4.2e+72) tmp = t_0; elseif (c <= 1.9e+31) tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / d); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (a + ((d * b) / c)) / c; tmp = 0.0; if (c <= -4.2e+72) tmp = t_0; elseif (c <= 1.9e+31) tmp = (b + (a * (c / d))) / d; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a + N[(N[(d * b), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -4.2e+72], t$95$0, If[LessEqual[c, 1.9e+31], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a + \frac{d \cdot b}{c}}{c}\\
\mathbf{if}\;c \leq -4.2 \cdot 10^{+72}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.9 \cdot 10^{+31}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -4.2000000000000003e72 or 1.9000000000000001e31 < c Initial program 49.0%
Taylor expanded in c around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f6477.4%
Simplified77.4%
if -4.2000000000000003e72 < c < 1.9000000000000001e31Initial program 69.9%
Taylor expanded in d around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
*-commutativeN/A
*-lowering-*.f6478.9%
Simplified78.9%
*-commutativeN/A
associate-/l*N/A
*-lowering-*.f64N/A
/-lowering-/.f6479.1%
Applied egg-rr79.1%
Final simplification78.4%
(FPCore (a b c d) :precision binary64 (if (<= d -7e+16) (/ b d) (if (<= d 2.35e+82) (/ (+ a (/ (* d b) c)) c) (/ b d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -7e+16) {
tmp = b / d;
} else if (d <= 2.35e+82) {
tmp = (a + ((d * b) / c)) / c;
} 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
real(8) :: tmp
if (d <= (-7d+16)) then
tmp = b / d
else if (d <= 2.35d+82) then
tmp = (a + ((d * b) / c)) / c
else
tmp = b / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -7e+16) {
tmp = b / d;
} else if (d <= 2.35e+82) {
tmp = (a + ((d * b) / c)) / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -7e+16: tmp = b / d elif d <= 2.35e+82: tmp = (a + ((d * b) / c)) / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -7e+16) tmp = Float64(b / d); elseif (d <= 2.35e+82) tmp = Float64(Float64(a + Float64(Float64(d * b) / c)) / c); else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -7e+16) tmp = b / d; elseif (d <= 2.35e+82) tmp = (a + ((d * b) / c)) / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -7e+16], N[(b / d), $MachinePrecision], If[LessEqual[d, 2.35e+82], N[(N[(a + N[(N[(d * b), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(b / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -7 \cdot 10^{+16}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 2.35 \cdot 10^{+82}:\\
\;\;\;\;\frac{a + \frac{d \cdot b}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -7e16 or 2.35e82 < d Initial program 50.2%
Taylor expanded in c around 0
/-lowering-/.f6473.0%
Simplified73.0%
if -7e16 < d < 2.35e82Initial program 68.2%
Taylor expanded in c around inf
/-lowering-/.f64N/A
+-lowering-+.f64N/A
/-lowering-/.f64N/A
*-lowering-*.f6474.7%
Simplified74.7%
Final simplification74.1%
(FPCore (a b c d) :precision binary64 (if (<= c -4.3e+72) (/ a c) (if (<= c 3.2e+33) (/ b d) (/ a c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -4.3e+72) {
tmp = a / c;
} else if (c <= 3.2e+33) {
tmp = b / d;
} else {
tmp = a / 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 (c <= (-4.3d+72)) then
tmp = a / c
else if (c <= 3.2d+33) then
tmp = b / d
else
tmp = a / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -4.3e+72) {
tmp = a / c;
} else if (c <= 3.2e+33) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -4.3e+72: tmp = a / c elif c <= 3.2e+33: tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -4.3e+72) tmp = Float64(a / c); elseif (c <= 3.2e+33) tmp = Float64(b / d); else tmp = Float64(a / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -4.3e+72) tmp = a / c; elseif (c <= 3.2e+33) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -4.3e+72], N[(a / c), $MachinePrecision], If[LessEqual[c, 3.2e+33], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -4.3 \cdot 10^{+72}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 3.2 \cdot 10^{+33}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -4.3000000000000001e72 or 3.20000000000000017e33 < c Initial program 49.0%
Taylor expanded in c around inf
/-lowering-/.f6468.0%
Simplified68.0%
if -4.3000000000000001e72 < c < 3.20000000000000017e33Initial program 69.9%
Taylor expanded in c around 0
/-lowering-/.f6465.2%
Simplified65.2%
(FPCore (a b c d) :precision binary64 (/ a c))
double code(double a, double b, double c, double d) {
return a / 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 = a / c
end function
public static double code(double a, double b, double c, double d) {
return a / c;
}
def code(a, b, c, d): return a / c
function code(a, b, c, d) return Float64(a / c) end
function tmp = code(a, b, c, d) tmp = a / c; end
code[a_, b_, c_, d_] := N[(a / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{a}{c}
\end{array}
Initial program 61.5%
Taylor expanded in c around inf
/-lowering-/.f6440.2%
Simplified40.2%
(FPCore (a b c d) :precision binary64 (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (fabs(d) < fabs(c)) {
tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (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 = (a + (b * (d / c))) / (c + (d * (d / c)))
else
tmp = (b + (a * (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 = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if math.fabs(d) < math.fabs(c): tmp = (a + (b * (d / c))) / (c + (d * (d / c))) else: tmp = (b + (a * (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(a + Float64(b * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c)))); else tmp = Float64(Float64(b + Float64(a * 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 = (a + (b * (d / c))) / (c + (d * (d / c))); else tmp = (b + (a * (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[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * 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{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
herbie shell --seed 2024139
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
:alt
(! :herbie-platform default (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))))