
(FPCore (x) :precision binary64 (- (* x 116.0) 16.0))
double code(double x) {
return (x * 116.0) - 16.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x * 116.0d0) - 16.0d0
end function
public static double code(double x) {
return (x * 116.0) - 16.0;
}
def code(x): return (x * 116.0) - 16.0
function code(x) return Float64(Float64(x * 116.0) - 16.0) end
function tmp = code(x) tmp = (x * 116.0) - 16.0; end
code[x_] := N[(N[(x * 116.0), $MachinePrecision] - 16.0), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 116 - 16
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (- (* x 116.0) 16.0))
double code(double x) {
return (x * 116.0) - 16.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x * 116.0d0) - 16.0d0
end function
public static double code(double x) {
return (x * 116.0) - 16.0;
}
def code(x): return (x * 116.0) - 16.0
function code(x) return Float64(Float64(x * 116.0) - 16.0) end
function tmp = code(x) tmp = (x * 116.0) - 16.0; end
code[x_] := N[(N[(x * 116.0), $MachinePrecision] - 16.0), $MachinePrecision]
\begin{array}{l}
\\
x \cdot 116 - 16
\end{array}
(FPCore (x) :precision binary64 (fma x 116.0 -16.0))
double code(double x) {
return fma(x, 116.0, -16.0);
}
function code(x) return fma(x, 116.0, -16.0) end
code[x_] := N[(x * 116.0 + -16.0), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, 116, -16\right)
\end{array}
Initial program 100.0%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
lower-fma.f64N/A
metadata-eval100.0
Applied rewrites100.0%
(FPCore (x) :precision binary64 (if (<= (* x 116.0) -2000000.0) (* x 116.0) (if (<= (* x 116.0) 2.0) -16.0 (* x 116.0))))
double code(double x) {
double tmp;
if ((x * 116.0) <= -2000000.0) {
tmp = x * 116.0;
} else if ((x * 116.0) <= 2.0) {
tmp = -16.0;
} else {
tmp = x * 116.0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x * 116.0d0) <= (-2000000.0d0)) then
tmp = x * 116.0d0
else if ((x * 116.0d0) <= 2.0d0) then
tmp = -16.0d0
else
tmp = x * 116.0d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x * 116.0) <= -2000000.0) {
tmp = x * 116.0;
} else if ((x * 116.0) <= 2.0) {
tmp = -16.0;
} else {
tmp = x * 116.0;
}
return tmp;
}
def code(x): tmp = 0 if (x * 116.0) <= -2000000.0: tmp = x * 116.0 elif (x * 116.0) <= 2.0: tmp = -16.0 else: tmp = x * 116.0 return tmp
function code(x) tmp = 0.0 if (Float64(x * 116.0) <= -2000000.0) tmp = Float64(x * 116.0); elseif (Float64(x * 116.0) <= 2.0) tmp = -16.0; else tmp = Float64(x * 116.0); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x * 116.0) <= -2000000.0) tmp = x * 116.0; elseif ((x * 116.0) <= 2.0) tmp = -16.0; else tmp = x * 116.0; end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(x * 116.0), $MachinePrecision], -2000000.0], N[(x * 116.0), $MachinePrecision], If[LessEqual[N[(x * 116.0), $MachinePrecision], 2.0], -16.0, N[(x * 116.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot 116 \leq -2000000:\\
\;\;\;\;x \cdot 116\\
\mathbf{elif}\;x \cdot 116 \leq 2:\\
\;\;\;\;-16\\
\mathbf{else}:\\
\;\;\;\;x \cdot 116\\
\end{array}
\end{array}
if (*.f64 x #s(literal 116 binary64)) < -2e6 or 2 < (*.f64 x #s(literal 116 binary64)) Initial program 100.0%
Taylor expanded in x around inf
lower-*.f6498.5
Applied rewrites98.5%
if -2e6 < (*.f64 x #s(literal 116 binary64)) < 2Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites97.4%
Final simplification97.9%
herbie shell --seed 2024227
(FPCore (x)
:name "Data.Colour.CIE:lightness from colour-2.3.3"
:precision binary64
(- (* x 116.0) 16.0))