I have an array of floating point numbers $X_i$ of type T
, where T
could be either float or double.
These numbers are strictly positive and sorted, i.e.
$$0 < X_0 < X_1 < X_2 < ... < X_n$$
I want to find the smallest floating point number $H$ of type T
such that the following inequality is strictly satisfied:
$$\lfloor X_{i+1}H \rfloor > \lfloor X_iH \rfloor \quad i=0\dots n-1$$
Let's assume that the numbers $X_i$ are such that there are no underflow or overflow issues to worry about.
I am approaching the problem as described below, which I think is not robust and, when it works, produces a sub optimal result.
Is there a robust and accurate way? I could accept a sub optimal solution, but at least I need it to be robust.
My current method
I use the notation $m(x)$ to indicate a floating point number which approximates $x$ and may be affected by roundoff error. In the following passages, I modify the inequality below taking as appropriate upper and lower bounds.
Let $a(x)$ be the floating point number closest to the floating point number $x$ toward $-\infty$
Let $b(x)$ be the floating point number closest to the floating point number $x$ toward $+\infty$
I mark with $m()$ the operation affected by rounding error, the original inequality is: $$\lfloor m(X_{i+1}\,H) \rfloor > \lfloor m(X_i\,H )\rfloor ,\quad i=0\dots n-1$$
I remove the $floor$ operator subtracting and adding 0.5. Since this is a conceptual operation, not actually executed on the machine, I do not mark it with an $m()$ $$m(X_{i+1}\,H) - 0.5 > m(X_i\,H) + 0.5 ,\quad i=0\dots n-1$$
I reorganize terms $$m(X_{i+1}\, H) - m(X_i\, H) > + 1 ,\quad i=0\dots n-1$$
I resolve the $m()$ operator with strict LHS minorant and RHS majorant. Note I cannot use $a(x)$ and $b(x)$ here because I do notbexplicitly compute the product $X_i\,H$. I use multiplication by $(1+2\epsilon)$ or $(1-2\epsilon)$ as I believe this will result in a number strictly greater (or lower) than the original one. Does this work? This may be the weak point in my formula! If $X_i$ is very small, multiplying it by $(1+2\epsilon)$ won't change it. Perhaps I should simply take $b(X_i)$ and $a(X_i)$.
$$X_{i+1}\,H\,(1-2\epsilon) - X_{i}\,H\,(1+2\epsilon) > b(1) ,\quad i=0\dots n-1$$
I solve the inequality for $H$, marking the operations affected by rounding error with $m()$
$$H > m\left( \frac{b(1)}{ m( X_{i+1}\,(1-2\epsilon) - X_{i}\,(1+2\epsilon) )} \right) ,\quad i=0\dots n-1$$
Take majorant or minorant as appropriate for rounded terms $$ H > b\left( \frac{b(1)} { a( X_{i+1}(1-2\epsilon) - X_{i}(1+2\epsilon) )} \right) ,\quad i=0\dots n-1$$
and eventually take a majorant which gives me the final formula for $H$ $$H = b\left( b\left( \frac{b(1)}{ \underset{0\leq i < n-1}{min}\{ a( X_{i+1}\,(1-2\epsilon) - X_{i}\,(1+2\epsilon) ) \} } \right) \right)$$