Parvej's blog

By Parvej, history, 3 years ago, In English

While solving this problem 1359C - Смешиваем воду . I observed a strange thing.

The same code is giving different outputs on different compilers. WA- 146913145 AC- 146915566

I found the test case for which the compilers gave different outputs.

Test Case

for this test case, c++17(64bit) is giving 499979 as output. but c++17 is giving 499981 as output which is as same as correct output.

I want to say that my outputs are compared to the outputs of the authors' solution which was run on c++17. But my solutions should be compared to the outputs which were run on c++17(64bit).

  • Vote: I like it
  • +3
  • Vote: I do not like it

»
3 years ago, # |
  Vote: I like it +2 Vote: I do not like it

Same happened with me in a different question though, and actually compiling with c++14 and c++20(64 bit) gave answers that differed by 2!

»
3 years ago, # |
  Vote: I like it +6 Vote: I do not like it

I've played a bit with your code, and if you make #define double long double , it outputs correct answer on both compiliers. So, probably, there're some differences in the floating point treatment.

»
3 years ago, # |
  Vote: I like it +20 Vote: I do not like it
  • »
    »
    3 years ago, # ^ |
      Vote: I like it +2 Vote: I do not like it

    Yes.

    In short 32 bit g++ does a weird thing making doubles sometimes behave like long doubles. You can turn on the same behaviour in 64 bit g++ (shown here: 146961849). But what you really should do is to just use long double everywhere instead of double (if you need high precision).