#include <stdio.h> #include <float.h> #include <math.h> double sqrt(double); main() { double x, y, r; *((int*)&x+1) = 0x3d2ffffe; *(int*)&x = 0x7fffffff; printf("x %08X%08X %.16e \n\n", *(((int*)&x) + 1), *((int*)&x ); y = sqrt(x); printf("result %08X%08X %.16e \n", *(((int*)&y) + 1), *((int*)&y), *((int*)&r+1) = 0x3e8fffff; *(int*)&r = 0x3ffffdbf; printf("result should be %08X%08X %.16e \n", *(((int*)&r) + 1), *((int*)&r), } It reports the following x 3D2FFFFE7FFFFFFF 5.6843378203226540e-14 result 3E8FFFFF3FFFFDC0 2.3841849383641896e-07 result should be 3E8FFFFF3FFFFDBF 2.3841849383641894e-07 The machine is running: Red Hat Release 6.0 (hedwig) Kernel 2.2.5-15smp on an i686
The representation is outside of the bounds of representation. 15 precision digits is the most you can do on a double (well, that's what is guaranteed)