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

Автор HHY_zZhu, история, 7 месяцев назад, По-английски

You will see something strange in this code

which is : a > b && a == b && !(a > b && a == b) (a, b are double)


#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; double qpow(double a, ll b) { double res = 1; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a; a = a * a; } return res; } double n, m; double p; double check(int x) { double p1 = 1 - p; p1 = 1 - qpow(p1, x); p1 = 1 / p1 * (n * x + m); return p1; } void solve() { n = 10, m = 27, p = 2855; // scanf("%lf%lf%lf", &n, &m, &p); p /= 10000; int l = 1, r = 10; while (l < r) { int k = (r - l) / 3; int mid1 = l + k; int mid2 = l + k * 2; double a = check(mid1), b = check(mid2); if(mid1 == mid2) { cout << (a > b) << endl; cout << (a == b) << endl; cout << (a > b && a == b) << endl; cout << (a < b) << endl; cout << *((ull*)(&a)) << endl; cout << *((ull*)(&b)) << endl; cout << a << endl; cout << b << endl; } if (a > b) { if(mid1 == mid2) cout << (a == b) << endl; l = mid1 + 1; } else { r = mid2; } } } int main() { solve(); }

Put this code in custom test with C++17

Could someone explain this?

Полный текст и комментарии »

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

Автор HHY_zZhu, история, 8 месяцев назад, По-английски

A very strange little bug has appeared, my rating timeline starts from 1970. For now, I haven't found anyone else who has encountered this bug (of course, I haven't really tried hard to find).

If you click on this link soon enough, you should still be able to see this interesting little bug :

https://codeforces.me/profile/HHY_zZhu

Полный текст и комментарии »

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