fork download
  1. #include <iostream>
  2. #include <random>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. double a = 0, b = 0, c = 0;
  8.  
  9. for( unsigned long long x = 1; x < 100000000000000ULL; x *= 10 )
  10. {
  11. std::mt19937 generator;
  12. std::uniform_real_distribution<double> distribution( 0, 10000.0 / x );
  13. unsigned found = 0;
  14. for ( unsigned i = 0; i < 10000; ++i )
  15. {
  16. a = distribution(generator);
  17. b = distribution(generator);
  18. c = distribution(generator);
  19. if ( ( (a + b ) + c ) != ( a + ( b + c ) ) )
  20. {
  21. ++found;
  22. }
  23. }
  24.  
  25. cout << 0 << " : " << ( 10000.0 / x ) << "\t" << found << endl;
  26. }
  27.  
  28. return 0;
  29. }
Success #stdin #stdout 0.02s 3340KB
stdin
Standard input is empty
stdout
0 : 10000	256
0 : 1000	285
0 : 100	233
0 : 10	160
0 : 1	1
0 : 0.1	280
0 : 0.01	261
0 : 0.001	242
0 : 0.0001	303
0 : 1e-05	252
0 : 1e-06	264
0 : 1e-07	261
0 : 1e-08	271
0 : 1e-09	267