Math FPCore C Julia Wolfram TeX \[\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\]
↓
\[\begin{array}{l}
t_0 := \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}\\
t_1 := \frac{a}{c} + \frac{b}{c} \cdot \frac{d}{c}\\
\mathbf{if}\;c \leq -5.7 \cdot 10^{+181}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \leq -3.2 \cdot 10^{-147}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 10^{-126}:\\
\;\;\;\;\frac{b}{d} + a \cdot \frac{\frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq 5 \cdot 10^{+44}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\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 (* (/ 1.0 (hypot c d)) (/ (fma a c (* b d)) (hypot c d))))
(t_1 (+ (/ a c) (* (/ b c) (/ d c)))))
(if (<= c -5.7e+181)
t_1
(if (<= c -3.2e-147)
t_0
(if (<= c 1e-126)
(+ (/ b d) (* a (/ (/ c d) d)))
(if (<= c 5e+44) t_0 t_1)))))) double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
↓
double code(double a, double b, double c, double d) {
double t_0 = (1.0 / hypot(c, d)) * (fma(a, c, (b * d)) / hypot(c, d));
double t_1 = (a / c) + ((b / c) * (d / c));
double tmp;
if (c <= -5.7e+181) {
tmp = t_1;
} else if (c <= -3.2e-147) {
tmp = t_0;
} else if (c <= 1e-126) {
tmp = (b / d) + (a * ((c / d) / d));
} else if (c <= 5e+44) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
function code(a, b, c, d)
return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d)))
end
↓
function code(a, b, c, d)
t_0 = Float64(Float64(1.0 / hypot(c, d)) * Float64(fma(a, c, Float64(b * d)) / hypot(c, d)))
t_1 = Float64(Float64(a / c) + Float64(Float64(b / c) * Float64(d / c)))
tmp = 0.0
if (c <= -5.7e+181)
tmp = t_1;
elseif (c <= -3.2e-147)
tmp = t_0;
elseif (c <= 1e-126)
tmp = Float64(Float64(b / d) + Float64(a * Float64(Float64(c / d) / d)));
elseif (c <= 5e+44)
tmp = t_0;
else
tmp = t_1;
end
return tmp
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]
↓
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(1.0 / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision] * N[(N[(a * c + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[Sqrt[c ^ 2 + d ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a / c), $MachinePrecision] + N[(N[(b / c), $MachinePrecision] * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -5.7e+181], t$95$1, If[LessEqual[c, -3.2e-147], t$95$0, If[LessEqual[c, 1e-126], N[(N[(b / d), $MachinePrecision] + N[(a * N[(N[(c / d), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 5e+44], t$95$0, t$95$1]]]]]]
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
↓
\begin{array}{l}
t_0 := \frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}\\
t_1 := \frac{a}{c} + \frac{b}{c} \cdot \frac{d}{c}\\
\mathbf{if}\;c \leq -5.7 \cdot 10^{+181}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \leq -3.2 \cdot 10^{-147}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 10^{-126}:\\
\;\;\;\;\frac{b}{d} + a \cdot \frac{\frac{c}{d}}{d}\\
\mathbf{elif}\;c \leq 5 \cdot 10^{+44}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
Alternatives Alternative 1 Accuracy 80.4% Cost 1488
\[\begin{array}{l}
t_0 := \frac{b \cdot d + c \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{if}\;c \leq -1.25 \cdot 10^{+145}:\\
\;\;\;\;\frac{a}{c} + \frac{\frac{d}{\frac{c}{b}}}{c}\\
\mathbf{elif}\;c \leq -1 \cdot 10^{-137}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;c \leq 5.3 \cdot 10^{-49}:\\
\;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
\mathbf{elif}\;c \leq 4.4 \cdot 10^{+44}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c} + \frac{b}{c} \cdot \frac{d}{c}\\
\end{array}
\]
Alternative 2 Accuracy 75.9% Cost 1232
\[\begin{array}{l}
t_0 := \frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
\mathbf{if}\;d \leq -41000000000000:\\
\;\;\;\;t_0\\
\mathbf{elif}\;d \leq 3.6 \cdot 10^{-37}:\\
\;\;\;\;\frac{a}{c} + \frac{\frac{d}{\frac{c}{b}}}{c}\\
\mathbf{elif}\;d \leq 7.2 \cdot 10^{+56}:\\
\;\;\;\;\frac{b \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 3.3 \cdot 10^{+80}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\]
Alternative 3 Accuracy 66.2% Cost 1100
\[\begin{array}{l}
\mathbf{if}\;c \leq -37000:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 7.5 \cdot 10^{-114}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;c \leq 1.9 \cdot 10^{+120}:\\
\;\;\;\;a \cdot \frac{c}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\]
Alternative 4 Accuracy 71.5% Cost 969
\[\begin{array}{l}
\mathbf{if}\;c \leq -4.8 \lor \neg \left(c \leq 6.3 \cdot 10^{-49}\right):\\
\;\;\;\;\frac{a}{c} + \frac{b}{c} \cdot \frac{d}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\]
Alternative 5 Accuracy 71.9% Cost 969
\[\begin{array}{l}
\mathbf{if}\;c \leq -0.122 \lor \neg \left(c \leq 7.2 \cdot 10^{-49}\right):\\
\;\;\;\;\frac{a}{c} + \frac{\frac{d}{\frac{c}{b}}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\]
Alternative 6 Accuracy 76.3% Cost 969
\[\begin{array}{l}
\mathbf{if}\;c \leq -7.2 \cdot 10^{+18} \lor \neg \left(c \leq 6.6 \cdot 10^{-49}\right):\\
\;\;\;\;\frac{a}{c} + \frac{\frac{d}{\frac{c}{b}}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d} + \frac{c}{d} \cdot \frac{a}{d}\\
\end{array}
\]
Alternative 7 Accuracy 65.3% Cost 456
\[\begin{array}{l}
\mathbf{if}\;c \leq -200:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 6.2 \cdot 10^{-49}:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\]
Alternative 8 Accuracy 41.9% Cost 192
\[\frac{a}{c}
\]