| Alternative 1 | |
|---|---|
| Error | 0.9 |
| Cost | 6788 |
\[\begin{array}{l}
\mathbf{if}\;x \leq -8.071019112801398 \cdot 10^{-297}:\\
\;\;\;\;\sqrt{2} \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \sqrt{2}\\
\end{array}
\]
(FPCore (x) :precision binary64 (sqrt (* 2.0 (* x x))))
(FPCore (x) :precision binary64 (if (<= x -8.071019112801398e-297) (* (sqrt 2.0) (- x)) (* (sqrt (* x 2.0)) (sqrt x))))
double code(double x) {
return sqrt((2.0 * (x * x)));
}
double code(double x) {
double tmp;
if (x <= -8.071019112801398e-297) {
tmp = sqrt(2.0) * -x;
} else {
tmp = sqrt((x * 2.0)) * sqrt(x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt((2.0d0 * (x * x)))
end function
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-8.071019112801398d-297)) then
tmp = sqrt(2.0d0) * -x
else
tmp = sqrt((x * 2.0d0)) * sqrt(x)
end if
code = tmp
end function
public static double code(double x) {
return Math.sqrt((2.0 * (x * x)));
}
public static double code(double x) {
double tmp;
if (x <= -8.071019112801398e-297) {
tmp = Math.sqrt(2.0) * -x;
} else {
tmp = Math.sqrt((x * 2.0)) * Math.sqrt(x);
}
return tmp;
}
def code(x): return math.sqrt((2.0 * (x * x)))
def code(x): tmp = 0 if x <= -8.071019112801398e-297: tmp = math.sqrt(2.0) * -x else: tmp = math.sqrt((x * 2.0)) * math.sqrt(x) return tmp
function code(x) return sqrt(Float64(2.0 * Float64(x * x))) end
function code(x) tmp = 0.0 if (x <= -8.071019112801398e-297) tmp = Float64(sqrt(2.0) * Float64(-x)); else tmp = Float64(sqrt(Float64(x * 2.0)) * sqrt(x)); end return tmp end
function tmp = code(x) tmp = sqrt((2.0 * (x * x))); end
function tmp_2 = code(x) tmp = 0.0; if (x <= -8.071019112801398e-297) tmp = sqrt(2.0) * -x; else tmp = sqrt((x * 2.0)) * sqrt(x); end tmp_2 = tmp; end
code[x_] := N[Sqrt[N[(2.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
code[x_] := If[LessEqual[x, -8.071019112801398e-297], N[(N[Sqrt[2.0], $MachinePrecision] * (-x)), $MachinePrecision], N[(N[Sqrt[N[(x * 2.0), $MachinePrecision]], $MachinePrecision] * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]]
\sqrt{2 \cdot \left(x \cdot x\right)}
\begin{array}{l}
\mathbf{if}\;x \leq -8.071019112801398 \cdot 10^{-297}:\\
\;\;\;\;\sqrt{2} \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{x \cdot 2} \cdot \sqrt{x}\\
\end{array}
Results
if x < -8.07101911280139796e-297Initial program 29.6
Taylor expanded in x around -inf 0.4
Simplified0.4
if -8.07101911280139796e-297 < x Initial program 31.1
Applied egg-rr1.4
Final simplification0.9
| Alternative 1 | |
|---|---|
| Error | 0.9 |
| Cost | 6788 |
| Alternative 2 | |
|---|---|
| Error | 30.8 |
| Cost | 6592 |

herbie shell --seed 2022308
(FPCore (x)
:name "sqrt C"
:precision binary64
(sqrt (* 2.0 (* x x))))