
On Mon, Dec 8, 2008 at 6:22 PM, Stjepan Rajko <stjepan.rajko@gmail.com> wrote:
On Mon, Dec 8, 2008 at 4:39 PM, Robert Kawulak <robert.kawulak@gmail.com> wrote:
Maybe the requirement could be loosened if I find a generic way to implement the bounds inclusion test which always returns false for NaN. Currently, to test x for inclusion in a closed range [lower, upper], we have:
!(x < lower) && !(upper < x)
But as the NaN case illustrates, !(x < lower) && !(upper < x) is not the same as (lower <= x) && (x <= upper). If I'm using a bounded type, I would want the latter. In non-numerical settings, and with custom comparisons, the two might have nothing to do with each other. I think bounded_value should *always* use the test (and invariant)
compare(lower, x) && compare(x, upper).
If you want boundaries excluded, use < for compare. If you want them included, use <=. If the type doesn't offer <=, use "<(a, b) || ==(a, b)".
OK, now I am getting both hasty and brain-dead. "!<(b,a)", as you have it, is a perfectly fine comparison for many cases. <(a,b) || ==(a,b) might work better for the NaN problem, but not for others. Stjepan