I found this code in an algorithm I need to update:
if (value > (unsigned long long) LONG_MAX)
EDIT: value
is the result of a division of two uint64_t
numbers.
I understand that (unsigned long long) LONG_MAX
is a VERY big number:
#include "stdio.h"
#include "limits.h"
int main() {
unsigned long long ull = (unsigned long long) LONG_MAX;
printf("%lu",ull);
return 0;
}
prints 9223372036854775807
So what I am comparing here? In what case this if
statement will evaluate to true
?
A float
or double
can be larger than that. Appendix Ep5 of the C standard states that either type must be able to hold a value at least as large as 1E37
which is a larger value than LONG_MAX
which must be at least 2147483647:
The values given in the following list shall be replaced by implementation-defined constant expressions with values that are greater than or equal to those shown:
#define DBL_MAX 1E+37 #define FLT_MAX 1E+37 #define LDBL_MAX 1E+37
So if value
is either of those types, it could evaluate to true.
EDIT:
Since value
is a uint64_t
, whose max value is 18446744073709551615, this can also be larger than LONG_MAX
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With