The root problem is that d3 gets rounded to a double at some point,
becoming 72057594037927936. With MSVC this happens already at d2
definition because in MSVC long double is the same as double. But with
gcc it should work in principle as long double has more precision there.
Anyway, it seems there are two problems:
1. <cmath> defines fmod() overloads in std:: namespace, so you need to
use std::fmod, not fmod. The latter (at least with gcc) only finds the C
version fmod(double, double). The std::fmod() works correctly with g++
4.6.2 on Linux, for example.
2. Even if you use std::fmod(), it seems that Cygwin g++ has not
implemented the long double version (it is lacking fmodl() as well), so
it is still falling back to the double version.