Tried on gcc and MSVC, both on Linux and Windows, remarkably the same result:
modf(+INFINITY) returns exact zero (0x0000000000000000 in binary representation of resulting double, 0x00000000 for float)
but modf(-INFINITY) returns 6.3e-322 (1.793662034335766e-43 for float version) (0x0000000000000080 in binary representation of resulting double, 0x00000080 for float)
Questions:
Why is there a tiny non-zero value in second case?
Is there any standard expected behavior for computing fractional part of infinities?
Code example:
#include <stdio.h>
#include <math.h>
int main(int argc, char* argv[])
{
float f1;
float f1a;
double f2;
double f2a;
f1 = modff(-INFINITY,&f1a);
f2 = modf(-INFINITY,&f2a);
//Dump into file to easily see the bits
FILE * f = fopen("a","wb");
fwrite(&f1,4,1,f);
fwrite(&f2,8,1,f);
fclose(f);
return 0;
}