Express highest floating point quantity that is less than 1

Posted by edA-qa mort-ora-y on Stack Overflow See other posts from Stack Overflow or by edA-qa mort-ora-y
Published on 2010-12-29T08:23:19Z Indexed on 2010/12/29 8:53 UTC
Read the original article Hit count: 234

Filed under:
|
|

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.)

© Stack Overflow or respective owner

Related posts about c++

Related posts about c