I’m making a floating_point class and am trying to access the last bit in an unsignedlong by masking it by (1 << 64), but when I compile and run it stops me saying that my value is too big, even though it’s exactly within the constraints! I checked the size of my unsigned long and it said 8 too so I don’t get it, mind helping me?
1. unsigned long is a 32-bit integer even on some 64-bit platforms.
2. 2^64 cannot be held by a 64-bit integer. Did you mean to 2^63?
3. 1 is still of type int. You need to convert it to a suitably large type first in order to nor overflow with the shift.
If you insist on using unsignedlong as your type you should know that there is a literal suffix ul that you can use to turn integer literals into that type.
char has 7 non-sign bits
unsigned char has 8 non-sign bits
short has 15 non-sign bits
unsigned short has 16 non-sign bits
int has 31 non-sign bits
unsigned int has 32 non-sign bits
long has 63 non-sign bits
unsigned long has 64 non-sign bits