Express highest floating point quantity that is less than 1
- by edA-qa mort-ora-y
I was doing some rounding calculations and happened upon a question. How can I express the highest quantity less than 1 for a given floating point type?
That is, how I write/represent value x such that x < 1, x + y >= 1 for any y > 0.
In fractions this would be x = (q-1)/q where q is the precision of the type. For example, if you are counting in 1/999 increments then x = 998/999.
For a given type (float, double, long double), how could one express the value x in code?
I also wonder if such a value actually exists for all values of y. That is, as y's exponent gets smaller perhaps the relation doesn't hold anymore. So an answer with some range restriction on y is also acceptable. (The value of x I want still does exist, the relationship may just not properly express it.)