HHY_zZhu's blog

By HHY_zZhu, history, 7 months ago, In English

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?

Full text and comments »

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

By HHY_zZhu, history, 8 months ago, In English

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.net/profile/HHY_zZhu

Full text and comments »

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