
(FPCore (x y z) :precision binary64 (/ (- x y) (- z y)))
double code(double x, double y, double z) {
return (x - y) / (z - y);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x - y) / (z - y)
end function
public static double code(double x, double y, double z) {
return (x - y) / (z - y);
}
def code(x, y, z): return (x - y) / (z - y)
function code(x, y, z) return Float64(Float64(x - y) / Float64(z - y)) end
function tmp = code(x, y, z) tmp = (x - y) / (z - y); end
code[x_, y_, z_] := N[(N[(x - y), $MachinePrecision] / N[(z - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{z - y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (- x y) (- z y)))
double code(double x, double y, double z) {
return (x - y) / (z - y);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x - y) / (z - y)
end function
public static double code(double x, double y, double z) {
return (x - y) / (z - y);
}
def code(x, y, z): return (x - y) / (z - y)
function code(x, y, z) return Float64(Float64(x - y) / Float64(z - y)) end
function tmp = code(x, y, z) tmp = (x - y) / (z - y); end
code[x_, y_, z_] := N[(N[(x - y), $MachinePrecision] / N[(z - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{z - y}
\end{array}
(FPCore (x y z) :precision binary64 (- (/ y (- y z)) (/ x (- y z))))
double code(double x, double y, double z) {
return (y / (y - z)) - (x / (y - z));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (y / (y - z)) - (x / (y - z))
end function
public static double code(double x, double y, double z) {
return (y / (y - z)) - (x / (y - z));
}
def code(x, y, z): return (y / (y - z)) - (x / (y - z))
function code(x, y, z) return Float64(Float64(y / Float64(y - z)) - Float64(x / Float64(y - z))) end
function tmp = code(x, y, z) tmp = (y / (y - z)) - (x / (y - z)); end
code[x_, y_, z_] := N[(N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision] - N[(x / N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{y}{y - z} - \frac{x}{y - z}
\end{array}
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ y (- y z))))
(if (<= y -2.35e-57)
t_0
(if (<= y 6e-71)
(/ x z)
(if (or (<= y 1.32e+76) (not (<= y 1.35e+239))) (- 1.0 (/ x y)) t_0)))))
double code(double x, double y, double z) {
double t_0 = y / (y - z);
double tmp;
if (y <= -2.35e-57) {
tmp = t_0;
} else if (y <= 6e-71) {
tmp = x / z;
} else if ((y <= 1.32e+76) || !(y <= 1.35e+239)) {
tmp = 1.0 - (x / y);
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = y / (y - z)
if (y <= (-2.35d-57)) then
tmp = t_0
else if (y <= 6d-71) then
tmp = x / z
else if ((y <= 1.32d+76) .or. (.not. (y <= 1.35d+239))) then
tmp = 1.0d0 - (x / y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y / (y - z);
double tmp;
if (y <= -2.35e-57) {
tmp = t_0;
} else if (y <= 6e-71) {
tmp = x / z;
} else if ((y <= 1.32e+76) || !(y <= 1.35e+239)) {
tmp = 1.0 - (x / y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y / (y - z) tmp = 0 if y <= -2.35e-57: tmp = t_0 elif y <= 6e-71: tmp = x / z elif (y <= 1.32e+76) or not (y <= 1.35e+239): tmp = 1.0 - (x / y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y / Float64(y - z)) tmp = 0.0 if (y <= -2.35e-57) tmp = t_0; elseif (y <= 6e-71) tmp = Float64(x / z); elseif ((y <= 1.32e+76) || !(y <= 1.35e+239)) tmp = Float64(1.0 - Float64(x / y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y / (y - z); tmp = 0.0; if (y <= -2.35e-57) tmp = t_0; elseif (y <= 6e-71) tmp = x / z; elseif ((y <= 1.32e+76) || ~((y <= 1.35e+239))) tmp = 1.0 - (x / y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2.35e-57], t$95$0, If[LessEqual[y, 6e-71], N[(x / z), $MachinePrecision], If[Or[LessEqual[y, 1.32e+76], N[Not[LessEqual[y, 1.35e+239]], $MachinePrecision]], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{y}{y - z}\\
\mathbf{if}\;y \leq -2.35 \cdot 10^{-57}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 6 \cdot 10^{-71}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{elif}\;y \leq 1.32 \cdot 10^{+76} \lor \neg \left(y \leq 1.35 \cdot 10^{+239}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ y (- y z))))
(if (<= y -8.8e+23)
t_0
(if (<= y 2.4e-44)
(/ (- x y) z)
(if (or (<= y 1.3e+81) (not (<= y 1.2e+239))) (- 1.0 (/ x y)) t_0)))))
double code(double x, double y, double z) {
double t_0 = y / (y - z);
double tmp;
if (y <= -8.8e+23) {
tmp = t_0;
} else if (y <= 2.4e-44) {
tmp = (x - y) / z;
} else if ((y <= 1.3e+81) || !(y <= 1.2e+239)) {
tmp = 1.0 - (x / y);
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = y / (y - z)
if (y <= (-8.8d+23)) then
tmp = t_0
else if (y <= 2.4d-44) then
tmp = (x - y) / z
else if ((y <= 1.3d+81) .or. (.not. (y <= 1.2d+239))) then
tmp = 1.0d0 - (x / y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y / (y - z);
double tmp;
if (y <= -8.8e+23) {
tmp = t_0;
} else if (y <= 2.4e-44) {
tmp = (x - y) / z;
} else if ((y <= 1.3e+81) || !(y <= 1.2e+239)) {
tmp = 1.0 - (x / y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y / (y - z) tmp = 0 if y <= -8.8e+23: tmp = t_0 elif y <= 2.4e-44: tmp = (x - y) / z elif (y <= 1.3e+81) or not (y <= 1.2e+239): tmp = 1.0 - (x / y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y / Float64(y - z)) tmp = 0.0 if (y <= -8.8e+23) tmp = t_0; elseif (y <= 2.4e-44) tmp = Float64(Float64(x - y) / z); elseif ((y <= 1.3e+81) || !(y <= 1.2e+239)) tmp = Float64(1.0 - Float64(x / y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y / (y - z); tmp = 0.0; if (y <= -8.8e+23) tmp = t_0; elseif (y <= 2.4e-44) tmp = (x - y) / z; elseif ((y <= 1.3e+81) || ~((y <= 1.2e+239))) tmp = 1.0 - (x / y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -8.8e+23], t$95$0, If[LessEqual[y, 2.4e-44], N[(N[(x - y), $MachinePrecision] / z), $MachinePrecision], If[Or[LessEqual[y, 1.3e+81], N[Not[LessEqual[y, 1.2e+239]], $MachinePrecision]], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{y}{y - z}\\
\mathbf{if}\;y \leq -8.8 \cdot 10^{+23}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 2.4 \cdot 10^{-44}:\\
\;\;\;\;\frac{x - y}{z}\\
\mathbf{elif}\;y \leq 1.3 \cdot 10^{+81} \lor \neg \left(y \leq 1.2 \cdot 10^{+239}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (<= y -9.4e+23) 1.0 (if (<= y 1.8e-71) (/ x z) (if (<= y 1.02e+45) (/ (- x) y) 1.0))))
double code(double x, double y, double z) {
double tmp;
if (y <= -9.4e+23) {
tmp = 1.0;
} else if (y <= 1.8e-71) {
tmp = x / z;
} else if (y <= 1.02e+45) {
tmp = -x / y;
} else {
tmp = 1.0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (y <= (-9.4d+23)) then
tmp = 1.0d0
else if (y <= 1.8d-71) then
tmp = x / z
else if (y <= 1.02d+45) then
tmp = -x / y
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -9.4e+23) {
tmp = 1.0;
} else if (y <= 1.8e-71) {
tmp = x / z;
} else if (y <= 1.02e+45) {
tmp = -x / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -9.4e+23: tmp = 1.0 elif y <= 1.8e-71: tmp = x / z elif y <= 1.02e+45: tmp = -x / y else: tmp = 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -9.4e+23) tmp = 1.0; elseif (y <= 1.8e-71) tmp = Float64(x / z); elseif (y <= 1.02e+45) tmp = Float64(Float64(-x) / y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -9.4e+23) tmp = 1.0; elseif (y <= 1.8e-71) tmp = x / z; elseif (y <= 1.02e+45) tmp = -x / y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -9.4e+23], 1.0, If[LessEqual[y, 1.8e-71], N[(x / z), $MachinePrecision], If[LessEqual[y, 1.02e+45], N[((-x) / y), $MachinePrecision], 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.4 \cdot 10^{+23}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.8 \cdot 10^{-71}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{elif}\;y \leq 1.02 \cdot 10^{+45}:\\
\;\;\;\;\frac{-x}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= y -1.4e-14) (not (<= y 3e+36))) (/ y (- y z)) (/ (- x) (- y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.4e-14) || !(y <= 3e+36)) {
tmp = y / (y - z);
} else {
tmp = -x / (y - z);
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((y <= (-1.4d-14)) .or. (.not. (y <= 3d+36))) then
tmp = y / (y - z)
else
tmp = -x / (y - z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1.4e-14) || !(y <= 3e+36)) {
tmp = y / (y - z);
} else {
tmp = -x / (y - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.4e-14) or not (y <= 3e+36): tmp = y / (y - z) else: tmp = -x / (y - z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.4e-14) || !(y <= 3e+36)) tmp = Float64(y / Float64(y - z)); else tmp = Float64(Float64(-x) / Float64(y - z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.4e-14) || ~((y <= 3e+36))) tmp = y / (y - z); else tmp = -x / (y - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.4e-14], N[Not[LessEqual[y, 3e+36]], $MachinePrecision]], N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision], N[((-x) / N[(y - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.4 \cdot 10^{-14} \lor \neg \left(y \leq 3 \cdot 10^{+36}\right):\\
\;\;\;\;\frac{y}{y - z}\\
\mathbf{else}:\\
\;\;\;\;\frac{-x}{y - z}\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= y -2.8e-77) (not (<= y 1.2e-70))) (- 1.0 (/ x y)) (/ x z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.8e-77) || !(y <= 1.2e-70)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / z;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((y <= (-2.8d-77)) .or. (.not. (y <= 1.2d-70))) then
tmp = 1.0d0 - (x / y)
else
tmp = x / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -2.8e-77) || !(y <= 1.2e-70)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.8e-77) or not (y <= 1.2e-70): tmp = 1.0 - (x / y) else: tmp = x / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.8e-77) || !(y <= 1.2e-70)) tmp = Float64(1.0 - Float64(x / y)); else tmp = Float64(x / z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2.8e-77) || ~((y <= 1.2e-70))) tmp = 1.0 - (x / y); else tmp = x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.8e-77], N[Not[LessEqual[y, 1.2e-70]], $MachinePrecision]], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.8 \cdot 10^{-77} \lor \neg \left(y \leq 1.2 \cdot 10^{-70}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z}\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (<= y -1.04e+24) 1.0 (if (<= y 8.5e-31) (/ x z) 1.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -1.04e+24) {
tmp = 1.0;
} else if (y <= 8.5e-31) {
tmp = x / z;
} else {
tmp = 1.0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (y <= (-1.04d+24)) then
tmp = 1.0d0
else if (y <= 8.5d-31) then
tmp = x / z
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -1.04e+24) {
tmp = 1.0;
} else if (y <= 8.5e-31) {
tmp = x / z;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -1.04e+24: tmp = 1.0 elif y <= 8.5e-31: tmp = x / z else: tmp = 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -1.04e+24) tmp = 1.0; elseif (y <= 8.5e-31) tmp = Float64(x / z); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -1.04e+24) tmp = 1.0; elseif (y <= 8.5e-31) tmp = x / z; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -1.04e+24], 1.0, If[LessEqual[y, 8.5e-31], N[(x / z), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.04 \cdot 10^{+24}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 8.5 \cdot 10^{-31}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (/ (- x y) (- z y)))
double code(double x, double y, double z) {
return (x - y) / (z - y);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x - y) / (z - y)
end function
public static double code(double x, double y, double z) {
return (x - y) / (z - y);
}
def code(x, y, z): return (x - y) / (z - y)
function code(x, y, z) return Float64(Float64(x - y) / Float64(z - y)) end
function tmp = code(x, y, z) tmp = (x - y) / (z - y); end
code[x_, y_, z_] := N[(N[(x - y), $MachinePrecision] / N[(z - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{z - y}
\end{array}
(FPCore (x y z) :precision binary64 1.0)
double code(double x, double y, double z) {
return 1.0;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 1.0d0
end function
public static double code(double x, double y, double z) {
return 1.0;
}
def code(x, y, z): return 1.0
function code(x, y, z) return 1.0 end
function tmp = code(x, y, z) tmp = 1.0; end
code[x_, y_, z_] := 1.0
\begin{array}{l}
\\
1
\end{array}
(FPCore (x y z) :precision binary64 (- (/ x (- z y)) (/ y (- z y))))
double code(double x, double y, double z) {
return (x / (z - y)) - (y / (z - y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x / (z - y)) - (y / (z - y))
end function
public static double code(double x, double y, double z) {
return (x / (z - y)) - (y / (z - y));
}
def code(x, y, z): return (x / (z - y)) - (y / (z - y))
function code(x, y, z) return Float64(Float64(x / Float64(z - y)) - Float64(y / Float64(z - y))) end
function tmp = code(x, y, z) tmp = (x / (z - y)) - (y / (z - y)); end
code[x_, y_, z_] := N[(N[(x / N[(z - y), $MachinePrecision]), $MachinePrecision] - N[(y / N[(z - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{z - y} - \frac{y}{z - y}
\end{array}
herbie shell --seed 2023350
(FPCore (x y z)
:name "Graphics.Rasterific.Shading:$sgradientColorAt from Rasterific-0.6.1"
:precision binary64
:herbie-target
(- (/ x (- z y)) (/ y (- z y)))
(/ (- x y) (- z y)))