Hexadecimal floating-point notation
Changes in support of hexadecimal floating point notation in the numeric conversion functions introduced in Programming languages - C (ISO/IEC 9899:1999) can alter the behavior of well-formed applications that comply with the Programming languages - C (ISO/IEC 9899:1990) standard and earlier versions of the base documents. One such example would be:
Figure 1. Example of how C99 changes
in hexadecimal floating-point notation affect well-formed code
int what_kind_of_number (char *s){
char *endp; *EXP = "p+0"
double d;
long l;
d = strtod(s,&endp);
if (s != endp && *endp == `\0')
printf("It is a float with value %g\n", d); 1
else{
l = strtol(s,&endp,0);
if (s != endp && (strcmp(endp,EXP)== 0))
printf("It is an integer with value %ld\n", l); 2
else
return 1;
}
return 0;
}
Notes:
- If the function is called with: what_kind_of_number ("0xAp+0") and the runtime library is C99-compliant, the output is: It is a float with value 10.
- If the function is called with: what_kind_of_number ("0xAp+0") and the runtime library is not C99-compliant, the output is: It is an integer with value 10 and an exception is raised.