Average Error: 0.1 → 0.1
Time: 1.0s
Precision: binary64
\[x + \frac{\left|y - x\right|}{2} \]
\[\mathsf{fma}\left(\left|y - x\right|, 0.5, x\right) \]
(FPCore (x y) :precision binary64 (+ x (/ (fabs (- y x)) 2.0)))
(FPCore (x y) :precision binary64 (fma (fabs (- y x)) 0.5 x))
double code(double x, double y) {
	return x + (fabs((y - x)) / 2.0);
}
double code(double x, double y) {
	return fma(fabs((y - x)), 0.5, x);
}
function code(x, y)
	return Float64(x + Float64(abs(Float64(y - x)) / 2.0))
end
function code(x, y)
	return fma(abs(Float64(y - x)), 0.5, x)
end
code[x_, y_] := N[(x + N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := N[(N[Abs[N[(y - x), $MachinePrecision]], $MachinePrecision] * 0.5 + x), $MachinePrecision]
x + \frac{\left|y - x\right|}{2}
\mathsf{fma}\left(\left|y - x\right|, 0.5, x\right)

Error

Bits error versus x

Bits error versus y

Derivation

  1. Initial program 0.1

    \[x + \frac{\left|y - x\right|}{2} \]
  2. Simplified0.1

    \[\leadsto \color{blue}{\mathsf{fma}\left(\left|y - x\right|, 0.5, x\right)} \]
  3. Final simplification0.1

    \[\leadsto \mathsf{fma}\left(\left|y - x\right|, 0.5, x\right) \]

Reproduce

herbie shell --seed 2022150 
(FPCore (x y)
  :name "Graphics.Rendering.Chart.Plot.AreaSpots:renderSpotLegend from Chart-1.5.3"
  :precision binary64
  (+ x (/ (fabs (- y x)) 2.0)))