When I run the following code, I am surprised to see that subtracting DBL_MIN
(the "minimum normalized positive value", around 2.2250738585072014e-308
), which is supposed to be the lowest positive double, has no effect. Doing the same with DBL_TRUE_MIN
has no effect either.
How should I go about getting the highest double lower to (double)upper_bound
?
Code:
#include <stdio.h>
#include <float.h>
int main(void) {
// lower_bound ≤ x < upper_bound
long int lower_bound = 0L;
long int upper_bound = 50L;
// x_lo ≤ x ≤ x_hi
double x_lo = (double)lower_bound;
double x_hi = ((double)upper_bound) - DBL_MIN;
if (x_hi < upper_bound)
printf("x_hi < upper_bound: SUCCESS\n");
else if (x_hi > upper_bound)
printf("x_hi > upper_bound: FAILURE\n");
else
printf("x_hi == upper_bound: FAILURE\n");
}
Output:
x_hi == upper_bound: FAILURE