C get percentage of ULLONG_MAX reliably

39 views Asked by At

In C, the following gives me an implicit conversion warning. I know why this warning happens. What I want to know is if there's a reliable one liner way of getting the percentage of really large unsigned numbers. I know that the end result will fit into unsigned long long, the same can't be said of the intermediate operations.

#define LOAD_FACTOR 0.75
#define MAX_CAPACITY (unsigned long long)((unsigned long long)-1 / sizeof(Entry) * LOAD_FACTOR)

Entry just being a normal struct, any struct will do.

I'm thinking about:

#define MAX_CAPACITY ((unsigned long long)-1 / sizeof(Entry) / 2 + (unsigned long long)-1 / sizeof(Entry) / 4)

But this way the LOAD_FACTOR becomes, well, not "dynamic".

EDIT: I'm compiling with Wall, Werror, Wextra and Wpedantic

0

There are 0 answers