
(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 8 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 (/ (- 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
(let* ((t_0 (/ (- x) (- y z))))
(if (<= x -4.4e+106)
t_0
(if (<= x -4.8e+51)
(- 1.0 (/ x y))
(if (or (<= x -2e+25) (not (<= x 4.9e-33))) t_0 (/ y (- y z)))))))
double code(double x, double y, double z) {
double t_0 = -x / (y - z);
double tmp;
if (x <= -4.4e+106) {
tmp = t_0;
} else if (x <= -4.8e+51) {
tmp = 1.0 - (x / y);
} else if ((x <= -2e+25) || !(x <= 4.9e-33)) {
tmp = t_0;
} else {
tmp = y / (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) :: t_0
real(8) :: tmp
t_0 = -x / (y - z)
if (x <= (-4.4d+106)) then
tmp = t_0
else if (x <= (-4.8d+51)) then
tmp = 1.0d0 - (x / y)
else if ((x <= (-2d+25)) .or. (.not. (x <= 4.9d-33))) then
tmp = t_0
else
tmp = y / (y - z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = -x / (y - z);
double tmp;
if (x <= -4.4e+106) {
tmp = t_0;
} else if (x <= -4.8e+51) {
tmp = 1.0 - (x / y);
} else if ((x <= -2e+25) || !(x <= 4.9e-33)) {
tmp = t_0;
} else {
tmp = y / (y - z);
}
return tmp;
}
def code(x, y, z): t_0 = -x / (y - z) tmp = 0 if x <= -4.4e+106: tmp = t_0 elif x <= -4.8e+51: tmp = 1.0 - (x / y) elif (x <= -2e+25) or not (x <= 4.9e-33): tmp = t_0 else: tmp = y / (y - z) return tmp
function code(x, y, z) t_0 = Float64(Float64(-x) / Float64(y - z)) tmp = 0.0 if (x <= -4.4e+106) tmp = t_0; elseif (x <= -4.8e+51) tmp = Float64(1.0 - Float64(x / y)); elseif ((x <= -2e+25) || !(x <= 4.9e-33)) tmp = t_0; else tmp = Float64(y / Float64(y - z)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = -x / (y - z); tmp = 0.0; if (x <= -4.4e+106) tmp = t_0; elseif (x <= -4.8e+51) tmp = 1.0 - (x / y); elseif ((x <= -2e+25) || ~((x <= 4.9e-33))) tmp = t_0; else tmp = y / (y - z); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[((-x) / N[(y - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -4.4e+106], t$95$0, If[LessEqual[x, -4.8e+51], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[x, -2e+25], N[Not[LessEqual[x, 4.9e-33]], $MachinePrecision]], t$95$0, N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x}{y - z}\\
\mathbf{if}\;x \leq -4.4 \cdot 10^{+106}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -4.8 \cdot 10^{+51}:\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{elif}\;x \leq -2 \cdot 10^{+25} \lor \neg \left(x \leq 4.9 \cdot 10^{-33}\right):\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{y - z}\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (<= y -2.6e+95) 1.0 (if (<= y -9.6e-27) (/ (- y) z) (if (<= y 1.25e+78) (/ x z) 1.0))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.6e+95) {
tmp = 1.0;
} else if (y <= -9.6e-27) {
tmp = -y / z;
} else if (y <= 1.25e+78) {
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 <= (-2.6d+95)) then
tmp = 1.0d0
else if (y <= (-9.6d-27)) then
tmp = -y / z
else if (y <= 1.25d+78) 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 <= -2.6e+95) {
tmp = 1.0;
} else if (y <= -9.6e-27) {
tmp = -y / z;
} else if (y <= 1.25e+78) {
tmp = x / z;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.6e+95: tmp = 1.0 elif y <= -9.6e-27: tmp = -y / z elif y <= 1.25e+78: tmp = x / z else: tmp = 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.6e+95) tmp = 1.0; elseif (y <= -9.6e-27) tmp = Float64(Float64(-y) / z); elseif (y <= 1.25e+78) tmp = Float64(x / z); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.6e+95) tmp = 1.0; elseif (y <= -9.6e-27) tmp = -y / z; elseif (y <= 1.25e+78) tmp = x / z; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.6e+95], 1.0, If[LessEqual[y, -9.6e-27], N[((-y) / z), $MachinePrecision], If[LessEqual[y, 1.25e+78], N[(x / z), $MachinePrecision], 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.6 \cdot 10^{+95}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -9.6 \cdot 10^{-27}:\\
\;\;\;\;\frac{-y}{z}\\
\mathbf{elif}\;y \leq 1.25 \cdot 10^{+78}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= y -1.15e-112) (not (<= y 1.16e+49))) (- 1.0 (/ x y)) (/ x z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.15e-112) || !(y <= 1.16e+49)) {
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 <= (-1.15d-112)) .or. (.not. (y <= 1.16d+49))) 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 <= -1.15e-112) || !(y <= 1.16e+49)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.15e-112) or not (y <= 1.16e+49): tmp = 1.0 - (x / y) else: tmp = x / z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.15e-112) || !(y <= 1.16e+49)) 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 <= -1.15e-112) || ~((y <= 1.16e+49))) tmp = 1.0 - (x / y); else tmp = x / z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.15e-112], N[Not[LessEqual[y, 1.16e+49]], $MachinePrecision]], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x / z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.15 \cdot 10^{-112} \lor \neg \left(y \leq 1.16 \cdot 10^{+49}\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{z}\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= z -0.000116) (not (<= z 31500000000000.0))) (/ (- x y) z) (- 1.0 (/ x y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -0.000116) || !(z <= 31500000000000.0)) {
tmp = (x - y) / z;
} else {
tmp = 1.0 - (x / y);
}
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 ((z <= (-0.000116d0)) .or. (.not. (z <= 31500000000000.0d0))) then
tmp = (x - y) / z
else
tmp = 1.0d0 - (x / y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -0.000116) || !(z <= 31500000000000.0)) {
tmp = (x - y) / z;
} else {
tmp = 1.0 - (x / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -0.000116) or not (z <= 31500000000000.0): tmp = (x - y) / z else: tmp = 1.0 - (x / y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -0.000116) || !(z <= 31500000000000.0)) tmp = Float64(Float64(x - y) / z); else tmp = Float64(1.0 - Float64(x / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -0.000116) || ~((z <= 31500000000000.0))) tmp = (x - y) / z; else tmp = 1.0 - (x / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -0.000116], N[Not[LessEqual[z, 31500000000000.0]], $MachinePrecision]], N[(N[(x - y), $MachinePrecision] / z), $MachinePrecision], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.000116 \lor \neg \left(z \leq 31500000000000\right):\\
\;\;\;\;\frac{x - y}{z}\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{x}{y}\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (<= y -3.7e-121) (/ y (- y z)) (if (<= y 1.16e+49) (/ x z) (- 1.0 (/ x y)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3.7e-121) {
tmp = y / (y - z);
} else if (y <= 1.16e+49) {
tmp = x / z;
} else {
tmp = 1.0 - (x / y);
}
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 <= (-3.7d-121)) then
tmp = y / (y - z)
else if (y <= 1.16d+49) then
tmp = x / z
else
tmp = 1.0d0 - (x / y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -3.7e-121) {
tmp = y / (y - z);
} else if (y <= 1.16e+49) {
tmp = x / z;
} else {
tmp = 1.0 - (x / y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3.7e-121: tmp = y / (y - z) elif y <= 1.16e+49: tmp = x / z else: tmp = 1.0 - (x / y) return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3.7e-121) tmp = Float64(y / Float64(y - z)); elseif (y <= 1.16e+49) tmp = Float64(x / z); else tmp = Float64(1.0 - Float64(x / y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3.7e-121) tmp = y / (y - z); elseif (y <= 1.16e+49) tmp = x / z; else tmp = 1.0 - (x / y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3.7e-121], N[(y / N[(y - z), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.16e+49], N[(x / z), $MachinePrecision], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.7 \cdot 10^{-121}:\\
\;\;\;\;\frac{y}{y - z}\\
\mathbf{elif}\;y \leq 1.16 \cdot 10^{+49}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{x}{y}\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (<= y -94000.0) 1.0 (if (<= y 6e+79) (/ x z) 1.0)))
double code(double x, double y, double z) {
double tmp;
if (y <= -94000.0) {
tmp = 1.0;
} else if (y <= 6e+79) {
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 <= (-94000.0d0)) then
tmp = 1.0d0
else if (y <= 6d+79) 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 <= -94000.0) {
tmp = 1.0;
} else if (y <= 6e+79) {
tmp = x / z;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -94000.0: tmp = 1.0 elif y <= 6e+79: tmp = x / z else: tmp = 1.0 return tmp
function code(x, y, z) tmp = 0.0 if (y <= -94000.0) tmp = 1.0; elseif (y <= 6e+79) tmp = Float64(x / z); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -94000.0) tmp = 1.0; elseif (y <= 6e+79) tmp = x / z; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -94000.0], 1.0, If[LessEqual[y, 6e+79], N[(x / z), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -94000:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 6 \cdot 10^{+79}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\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 2023343
(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)))