I have provided Pastebin for my code: https://pastebin.com/thTapSgn
The issue that I am having is that I am getting different results based on whether or not my calculation is happening within a thread or not. This does not happen with GCC on Linux, or MinGW in MSYS, or Visual Studio.
I've confirmed this with:
x86_64-8.1.0-release-posix-seh-rt_v6-rev0
TDM-GCC 9.1.0
g++ -std=c++17 -O0 -g3 -Wall -c -fmessage-length=0 -o "src\\ThreadDoublePrecision.o" "..\\src\\ThreadDoublePrecision.cpp"
g++ -o ThreadDoublePrecision.exe "src\\ThreadDoublePrecision.o" -lpthread
Produces this output:
Local = 0.0010370292068795884059
Local = 0.0010370292068795884059
Thread = 0.0010370292068795879722
Thread = 0.0010370292068795879722
When I run this on GodBolt.org, Visual Studop, WSL2 and Linux natively with GCC/G++ I get this output:
zaita@Anubis:~$ ./a.out
Local = 0.0010370292068795884059
Local = 0.0010370292068795884059
Thread = 0.0010370292068795884059
Thread = 0.0010370292068795884059
I believe this issue has been fixed by https://sourceforge.net/p/mingw-w64/mingw-w64/ci/295fafcf584ce105426045b03d17aa90d105808d/ (which should be part of the mingw-w64 v8.0.0 release).
That commit fixes it for pthreads (and std::threads with libstdc++), but won't fix it if manually creating threads or using libc++ yet though.
Where can I download a version with this fix? I've tried MinGW-W64 GCC-8.1.0 - x86_64-posix-seh from https://sourceforge.net/projects/mingw-w64/files/ with no luck. Also Tried the TDM-GCC 9.2.0 and Nuwen MinGW64 9.2.0 both built from Mingw64.
Also. I updated my code to #undef STRICT_ANSI and manually call _fpreset(); ( https://pastebin.com/NE8D0DVb ) and this seems to work perfectly. Super hacky though, but will be sufficient enough to allow me to get correct results until a fix is available.
Note: This is for scientific modeling software. So having reproducible results across compilers and platforms is a key requirement :)