Блог пользователя absolute-mess

Автор absolute-mess, 4 года назад, По-английски

Hello Coders!

I was doing this question High School: Become Human. I had to calculate x^y and y^x and take log on both sides...x(logy) and y(logx). When I submitted my solution, it got WA on TC3...where the TC was n=6 and m=6. The answer should be '=,' but the compiler showed '<'...Code in C++17 WA on 3. So why does 6(log6) != 6(log6), according to C++17, when I submitted the code for checking the value of 6log6 in this TC. It surprised me coz now the answer was showing '='... Code in C++17 for checking. But it got failed due to the value of n1 and m1 displayed. When I tried submitting the first code using C++20, it was accepted. AC on C++20.

I tried using Long double also, but it was of no use. https://mirror.codeforces.com/contest/987/submission/140238196

Can you somehow tell me why log, C++17, and C++20 behave in this strange manner and give weird output? I don't know why people are downvoting this, but if someone has the answer, do answer this.

Thanks!

  • Проголосовать: нравится
  • -8
  • Проголосовать: не нравится

»
4 года назад, скрыть # |
 
Проголосовать: нравится -9 Проголосовать: не нравится

Bahut bura hua bro !!!

»
4 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Log always behave strange, because it's double arithmetic

»
4 года назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

Different compilers will work with floating point numbers differently. This is the reason why one should avoid using them if possible. That's all I know.

»
4 года назад, скрыть # |
 
Проголосовать: нравится +9 Проголосовать: не нравится

I have previously written a blog about exactly this weirdness: Explanation of weird/strange floating point behaviour in C++

The difference in floating point behaviour comes from the difference of compiling in 32 bit vs 64 bit.

WA in C++17 (32 bit) 140239565

AC in C++17 (64 bit) 140305850

AC in C++17 (32 bit) if you use a pragma to turn off most of the weird floating point behaviour 140305892