clang++ | clang++/fast-math | g++ | g++/fast-math | |
---|---|---|---|---|
Naive | 36028796884746240 | 36028796884746240 | ||
Naive OpenMP | 36028796884746240 | 36028796884746240 | 36028796884746240 | 36028796884746240 |
Vectorization | 36028796884746240 | 36028796884746240 | - | - |
Correct answer -- 36028796884746240
-
clang++ --
clang++ -march=native -O3 -std=c++11 -fopenmp -L/usr/local/opt/llvm/lib -o main ./main.cpp
-
clang++/fast-math --
clang++ -march=native -O3 -std=c++11 -fopenmp -ffast-math -L/usr/local/opt/llvm/lib -o main ./main.cpp
-
g++ --
g++-5 -march=native -O3 -std=c++11 -fopenmp -o main ./main.cpp
-
g++/fast-math --
g++-5 -march=native -O3 -std=c++11 -fopenmp -ffast-math -o main ./main.cpp
-
clang version 3.8.1 (tags/RELEASE_381/final)
-
g++-5 (Homebrew gcc 5.3.0) 5.3.0
-
OS X 10.11, Intel i7
OpenMP not required, just comment it out. I played with vectorization, compared results to naive solution (assumed they would be correct) – debugged vectorization instead of naive...
I am aware of float/double inaccuracy, however I've never thought it could be that large (underflow by 67108864). Is there any other explanation for this? Furthermore, fast-math generates no errors, which is even more strange... I assumed it was clang bug, but tried the code on g++, O1, O2, same behaviour, therefore I must be missing something.
Can anyone somehow illuminate me? Is it just floating point underflow, why fast-math gives correct result?