I have a int32_t number and i need to check if will it fit in int8 and in16 but when i try:
if (number ==(int32_t)((int8_t) number)) {
printf("%s %d\n","8", number);
} else if (number ==(int32_t)((int16_t) number)){
printf("%s %d\n","16", number);
Compiler says that first if statement is always true, but i don't know how to do it in other way, using only "==" and bits operations like << >>. and <stdint.h>.
As of C++ 20 you can do this:
std::in_range<std::int8_t>(-1)
see here
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