TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Weird compiler bug – Same code, different results

73 pointsby zaitanzover 4 years ago

5 comments

brucehoultover 4 years ago
If you read the article you find that this is a bug in MinGW64 libraries.<p>It&#x27;s not a compiler bug, it&#x27;s not a problem in C&#x2F;C++, or even in IEEE-754 floating point math. The MinGW64 thread library simply forgot to initialize the FPU correctly.<p>He&#x27;d have had the same problem if he wrote his code in assembly language and then ran it in a MinGW64 thread.
评论 #25964105 未加载
gus_massaover 4 years ago
&gt; <i>This means that floating point arithmetic is non-associative. In that A + B != B + A.</i><p>The equation is the commutative property, not associative. IIRC addition in IEEE-754 is commutative.<p>The property that fails is (A+B)+C = A+(B+C).
评论 #25964071 未加载
lysiumover 4 years ago
I would have never thought that the output of some floating point operations depend on the „reset of the floating point package“. What gives?
评论 #25963271 未加载
评论 #25963330 未加载
评论 #25963144 未加载
评论 #25963257 未加载
评论 #25964159 未加载
评论 #25963163 未加载
peter_d_shermanover 4 years ago
&gt;&quot;Compiler bug? But how… Looking at the code, the only things that could create the bug were the operators and pow() call. These are part of the C++ standard offering so it’s highly unlikely that either of these would have an error. What next? Off to GodBolt to try some other compilers to see if I get wonky results on them. MSVC++… nope, Clang… nope, GCC-Trunk on Linux… nope. I am only getting this weird behaviour in TDM-GCC. Time to try some other MingW64 compilers. Nuwen… Yes, Mingw64.. yes, TDM-GCC… yes.<p>Confirmed: It’s a bug in MinGW64.<p>When I create a new thread and run floating point operations in that thread, I get slightly different answers.&quot;<p>Interesting!
titzerover 4 years ago
Do <i>not</i> use C&#x2F;C++ for numerical code where accuracy is needed. These languages are not specified to conform to IEEE 754 and you are absolutely asking for trouble.
评论 #25963206 未加载
评论 #25964154 未加载
评论 #25963676 未加载
评论 #25964094 未加载
评论 #25963300 未加载