div.c 693 B

1234567891011121314151617181920212223242526272829
  1. #include "test/jemalloc_test.h"
  2. #include "jemalloc/internal/div.h"
  3. TEST_BEGIN(test_div_exhaustive) {
  4. for (size_t divisor = 2; divisor < 1000 * 1000; ++divisor) {
  5. div_info_t div_info;
  6. div_init(&div_info, divisor);
  7. size_t max = 1000 * divisor;
  8. if (max < 1000 * 1000) {
  9. max = 1000 * 1000;
  10. }
  11. for (size_t dividend = 0; dividend < 1000 * divisor;
  12. dividend += divisor) {
  13. size_t quotient = div_compute(
  14. &div_info, dividend);
  15. assert_zu_eq(dividend, quotient * divisor,
  16. "With divisor = %zu, dividend = %zu, "
  17. "got quotient %zu", divisor, dividend, quotient);
  18. }
  19. }
  20. }
  21. TEST_END
  22. int
  23. main(void) {
  24. return test_no_reentrancy(
  25. test_div_exhaustive);
  26. }