Monday, December 1, 2014

float, double, long double - max values in hexadecimal

It is trivial, but I could not find an easy reference. Here is one, after having found it:

float (32-bit):
0X1.FFFFFEP+127F

double (64-bit):
0X1.FFFFFFFFFFFFFP+1023

long double (128-bit):
0XF.FFFFFFFFFFFFFFFP+16380L

Don't forget the letter 'L' for 128-bit floating-point value! (Otherwise, the literal value will be truncanted into 64-bit float, and that would be a bug)

Test:

#include<cstdio>
#include<cfloat>
int main(){
printf("0x20-bit %A\n0x40-bit %A\n0x80-bit %LA\n",FLT_MAX,DBL_MAX,LDBL_MAX);
return 0;}

No comments:

Post a Comment