fork(1) download
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. #include <math.h>
  4.  
  5. int main(void) {
  6. for (uint32_t y = 1; y != 0; y++) {
  7. // *Just* smaller than a perfect square
  8. uint64_t x = ((uint64_t)y * (uint64_t)y) - 1;
  9.  
  10. // We expect the floor of the result
  11. uint32_t expected = y - 1;
  12.  
  13. uint32_t result = (uint32_t)sqrt((double)x);
  14.  
  15. if (result != expected) {
  16. printf("Incorrect: x = %llu, result = %u\n", x, result);
  17. break;
  18. }
  19. }
  20. return 0;
  21. }
  22.  
Success #stdin #stdout 0.4s 4476KB
stdin
Standard input is empty
stdout
Incorrect: x = 4503599761588224, result = 67108865