Given two (here and below: single-precision, IEEE 32-bit floats) normalized floating-point numbers $x, y$ (perhaps of reasonable range: my counterexamples don't have unusual magnitudes), and another floating-point number $0\leq t\leq 1$, I would like to evaluate the linear interpolant$$ z_t = x(1-t) + yt $$in such a way that:$$ \begin{gathered}x \leq z_t \leq y,\\z_0 = x, \qquad z_1 = y,\end{gathered} $$as well as$$ z_t \leq z_s \quad\text{whenever}\quad 0\leq t \leq s \leq 1. $$The direct formula, $z_t = x(1-t)+yt$ fails. For example, with $x=2.0000076$, $y=2.9007149$, we have in single-precision arithmetic$$ \mathrm{fl}(z_t) < x, \qquad \text{for}\quad2.9802326\times 10^{-8}\leq t<4.109652\times 10^{-8}. $$The obvious other formula $z_t = x + (y-x)t$ satisfies $z_t \geq x$, but sometimes $z_1 > y$ for$$ x=1.0000609, \quad y=3.9999998, \quad z_1 = 4.0. $$I considered$$ z_t = \mathrm{fma}(x, 1-t, y t), $$and it has counterexamples x=y=1.9210567f0, t=0.10707888f0, z_t = 1.9210566f0 < x and x=-1.4928777f-36, y=-1.4825014f-36, t=2.9802322f-8, z_t=-1.4928778f-36 < x.If I allow using if-statements, then simply evaluating one of$$ x+(y-x)t\quad(t\leq\tfrac12), \qquad y - (y-x)(1-t)\quad(t\geq\tfrac12) $$works as defined above, but this is quite inefficient because of the branching on $t$. There is also sometimes an unexpected discontinuity at $t=\frac12$:$$ \begin{gathered}x = 0.9921611, \quad y = 4.0\\x+\tfrac12(y-x) = 2.4960806, \qquad y-\tfrac12 (y-x) = 2.4960804.\end{gathered} $$Does there exist an efficient simple formula that gives the linear interpolant with the standard mathematical properties?
How can I interpolate $z_t = x(1-t)+y t$ with single-precision floats so that it satisfies $x\leq z\leq y$, $z_0=x$, $z_1=y$?
numerical analysis;floating point