Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

Блог пользователя apnakaamkar

Автор apnakaamkar, история, 3 года назад, По-английски

Can anyone tell me why I am getting different values of lhs and rhs? I expected them to produce similar results.

double lhs=y*log10(x);
double rhs=x*log10(y);

**

double lhs=log10(x);
double rhs=log10(y);
lhs*=y;
rhs*=x;

I am getting wrong answers for x=6,y=6 while submitting on codeforces but I am getting correct on VSCode.

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

»
3 года назад, # |
  Проголосовать: нравится +12 Проголосовать: не нравится

How are you doing comparison directly like this? Never do comparisons without some tolerance in precision. There might be a precision error as small as $$$10^{-15}$$$ or even smaller which makes both not equal to each other. You can do something like:

Code

You are lucky that the other code passed with direct comparisons.