
(FPCore (x y) :precision binary64 (+ x (/ (fabs (- y x)) 2.0)))
double code(double x, double y) {
return x + (fabs((y - x)) / 2.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x + (abs((y - x)) / 2.0d0)
end function
public static double code(double x, double y) {
return x + (Math.abs((y - x)) / 2.0);
}
def code(x, y): return x + (math.fabs((y - x)) / 2.0)
function code(x, y) return Float64(x + Float64(abs(Float64(y - x)) / 2.0)) end
function tmp = code(x, y) tmp = x + (abs((y - x)) / 2.0); end
code[x_, y_] := N[(x + N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{\left|y - x\right|}{2}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (+ x (/ (fabs (- y x)) 2.0)))
double code(double x, double y) {
return x + (fabs((y - x)) / 2.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x + (abs((y - x)) / 2.0d0)
end function
public static double code(double x, double y) {
return x + (Math.abs((y - x)) / 2.0);
}
def code(x, y): return x + (math.fabs((y - x)) / 2.0)
function code(x, y) return Float64(x + Float64(abs(Float64(y - x)) / 2.0)) end
function tmp = code(x, y) tmp = x + (abs((y - x)) / 2.0); end
code[x_, y_] := N[(x + N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{\left|y - x\right|}{2}
\end{array}
(FPCore (x y) :precision binary64 (+ x (/ (fabs (- y x)) 2.0)))
double code(double x, double y) {
return x + (fabs((y - x)) / 2.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x + (abs((y - x)) / 2.0d0)
end function
public static double code(double x, double y) {
return x + (Math.abs((y - x)) / 2.0);
}
def code(x, y): return x + (math.fabs((y - x)) / 2.0)
function code(x, y) return Float64(x + Float64(abs(Float64(y - x)) / 2.0)) end
function tmp = code(x, y) tmp = x + (abs((y - x)) / 2.0); end
code[x_, y_] := N[(x + N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{\left|y - x\right|}{2}
\end{array}
(FPCore (x y)
:precision binary64
(let* ((t_0 (* 0.5 (+ x y))))
(if (<= x -8e-43)
t_0
(if (<= x 1.08e+17) (* (fabs (- y x)) 0.5) (+ x t_0)))))
double code(double x, double y) {
double t_0 = 0.5 * (x + y);
double tmp;
if (x <= -8e-43) {
tmp = t_0;
} else if (x <= 1.08e+17) {
tmp = fabs((y - x)) * 0.5;
} else {
tmp = x + t_0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = 0.5d0 * (x + y)
if (x <= (-8d-43)) then
tmp = t_0
else if (x <= 1.08d+17) then
tmp = abs((y - x)) * 0.5d0
else
tmp = x + t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = 0.5 * (x + y);
double tmp;
if (x <= -8e-43) {
tmp = t_0;
} else if (x <= 1.08e+17) {
tmp = Math.abs((y - x)) * 0.5;
} else {
tmp = x + t_0;
}
return tmp;
}
def code(x, y): t_0 = 0.5 * (x + y) tmp = 0 if x <= -8e-43: tmp = t_0 elif x <= 1.08e+17: tmp = math.fabs((y - x)) * 0.5 else: tmp = x + t_0 return tmp
function code(x, y) t_0 = Float64(0.5 * Float64(x + y)) tmp = 0.0 if (x <= -8e-43) tmp = t_0; elseif (x <= 1.08e+17) tmp = Float64(abs(Float64(y - x)) * 0.5); else tmp = Float64(x + t_0); end return tmp end
function tmp_2 = code(x, y) t_0 = 0.5 * (x + y); tmp = 0.0; if (x <= -8e-43) tmp = t_0; elseif (x <= 1.08e+17) tmp = abs((y - x)) * 0.5; else tmp = x + t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -8e-43], t$95$0, If[LessEqual[x, 1.08e+17], N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[(x + t$95$0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \left(x + y\right)\\
\mathbf{if}\;x \leq -8 \cdot 10^{-43}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq 1.08 \cdot 10^{+17}:\\
\;\;\;\;\left|y - x\right| \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x + t_0\\
\end{array}
\end{array}
(FPCore (x y) :precision binary64 (let* ((t_0 (* 0.5 (+ x y)))) (if (<= x 2e-290) t_0 (+ x t_0))))
double code(double x, double y) {
double t_0 = 0.5 * (x + y);
double tmp;
if (x <= 2e-290) {
tmp = t_0;
} else {
tmp = x + t_0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = 0.5d0 * (x + y)
if (x <= 2d-290) then
tmp = t_0
else
tmp = x + t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = 0.5 * (x + y);
double tmp;
if (x <= 2e-290) {
tmp = t_0;
} else {
tmp = x + t_0;
}
return tmp;
}
def code(x, y): t_0 = 0.5 * (x + y) tmp = 0 if x <= 2e-290: tmp = t_0 else: tmp = x + t_0 return tmp
function code(x, y) t_0 = Float64(0.5 * Float64(x + y)) tmp = 0.0 if (x <= 2e-290) tmp = t_0; else tmp = Float64(x + t_0); end return tmp end
function tmp_2 = code(x, y) t_0 = 0.5 * (x + y); tmp = 0.0; if (x <= 2e-290) tmp = t_0; else tmp = x + t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 2e-290], t$95$0, N[(x + t$95$0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \left(x + y\right)\\
\mathbf{if}\;x \leq 2 \cdot 10^{-290}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;x + t_0\\
\end{array}
\end{array}
(FPCore (x y) :precision binary64 (if (<= x -7.8e-39) (* x 0.5) (if (<= x 3e-205) (* y 0.5) (* x 1.5))))
double code(double x, double y) {
double tmp;
if (x <= -7.8e-39) {
tmp = x * 0.5;
} else if (x <= 3e-205) {
tmp = y * 0.5;
} else {
tmp = x * 1.5;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-7.8d-39)) then
tmp = x * 0.5d0
else if (x <= 3d-205) then
tmp = y * 0.5d0
else
tmp = x * 1.5d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -7.8e-39) {
tmp = x * 0.5;
} else if (x <= 3e-205) {
tmp = y * 0.5;
} else {
tmp = x * 1.5;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -7.8e-39: tmp = x * 0.5 elif x <= 3e-205: tmp = y * 0.5 else: tmp = x * 1.5 return tmp
function code(x, y) tmp = 0.0 if (x <= -7.8e-39) tmp = Float64(x * 0.5); elseif (x <= 3e-205) tmp = Float64(y * 0.5); else tmp = Float64(x * 1.5); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -7.8e-39) tmp = x * 0.5; elseif (x <= 3e-205) tmp = y * 0.5; else tmp = x * 1.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -7.8e-39], N[(x * 0.5), $MachinePrecision], If[LessEqual[x, 3e-205], N[(y * 0.5), $MachinePrecision], N[(x * 1.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.8 \cdot 10^{-39}:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{elif}\;x \leq 3 \cdot 10^{-205}:\\
\;\;\;\;y \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1.5\\
\end{array}
\end{array}
(FPCore (x y) :precision binary64 (if (<= x 1.55e-166) (* 0.5 (+ x y)) (* x 1.5)))
double code(double x, double y) {
double tmp;
if (x <= 1.55e-166) {
tmp = 0.5 * (x + y);
} else {
tmp = x * 1.5;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= 1.55d-166) then
tmp = 0.5d0 * (x + y)
else
tmp = x * 1.5d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 1.55e-166) {
tmp = 0.5 * (x + y);
} else {
tmp = x * 1.5;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 1.55e-166: tmp = 0.5 * (x + y) else: tmp = x * 1.5 return tmp
function code(x, y) tmp = 0.0 if (x <= 1.55e-166) tmp = Float64(0.5 * Float64(x + y)); else tmp = Float64(x * 1.5); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 1.55e-166) tmp = 0.5 * (x + y); else tmp = x * 1.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 1.55e-166], N[(0.5 * N[(x + y), $MachinePrecision]), $MachinePrecision], N[(x * 1.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.55 \cdot 10^{-166}:\\
\;\;\;\;0.5 \cdot \left(x + y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot 1.5\\
\end{array}
\end{array}
(FPCore (x y) :precision binary64 (if (<= y 2.35e-245) x (* y 0.5)))
double code(double x, double y) {
double tmp;
if (y <= 2.35e-245) {
tmp = x;
} else {
tmp = y * 0.5;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 2.35d-245) then
tmp = x
else
tmp = y * 0.5d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 2.35e-245) {
tmp = x;
} else {
tmp = y * 0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 2.35e-245: tmp = x else: tmp = y * 0.5 return tmp
function code(x, y) tmp = 0.0 if (y <= 2.35e-245) tmp = x; else tmp = Float64(y * 0.5); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 2.35e-245) tmp = x; else tmp = y * 0.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 2.35e-245], x, N[(y * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.35 \cdot 10^{-245}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot 0.5\\
\end{array}
\end{array}
(FPCore (x y) :precision binary64 (if (<= y 70000.0) (* x 0.5) (* y 0.5)))
double code(double x, double y) {
double tmp;
if (y <= 70000.0) {
tmp = x * 0.5;
} else {
tmp = y * 0.5;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 70000.0d0) then
tmp = x * 0.5d0
else
tmp = y * 0.5d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 70000.0) {
tmp = x * 0.5;
} else {
tmp = y * 0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 70000.0: tmp = x * 0.5 else: tmp = y * 0.5 return tmp
function code(x, y) tmp = 0.0 if (y <= 70000.0) tmp = Float64(x * 0.5); else tmp = Float64(y * 0.5); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 70000.0) tmp = x * 0.5; else tmp = y * 0.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 70000.0], N[(x * 0.5), $MachinePrecision], N[(y * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 70000:\\
\;\;\;\;x \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;y \cdot 0.5\\
\end{array}
\end{array}
(FPCore (x y) :precision binary64 x)
double code(double x, double y) {
return x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x
end function
public static double code(double x, double y) {
return x;
}
def code(x, y): return x
function code(x, y) return x end
function tmp = code(x, y) tmp = x; end
code[x_, y_] := x
\begin{array}{l}
\\
x
\end{array}
herbie shell --seed 2024008
(FPCore (x y)
:name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
:precision binary64
(+ x (/ (fabs (- y x)) 2.0)))