int main(void) { int n = 1E7; item_t *a = (item_t *)malloc(n * sizeof *a); for_each(a, a + n, init); /*for_each(a, a + n, print); putchar('\n'); putchar('\n');*/ clock_t begin = clock(); #if defined (USER) int count = quick_sort(a, 0, n-1); printf("Hi\n"); #else qsort(a, n, sizeof *a, comp); int count = count_diff(a, n); #endif clock_t end = clock(); /*for_each(a, a + n, print); putchar('\n');*/ printf("\n%d distinct number; time elapse: %f\n", count, (double)(end - begin)/CLOCKS_PER_SEC); return 0; }
int main(void) { union data_32bit a, n, result, correct; uint32_t i; long unsigned int total_mistakes = 0; //誤答数をカウント /* long unsigned int count_no_diff = 0; long unsigned int count_1ulp_diff = 0; //1bitずれをカウント long unsigned int count_2ulp_diff = 0; long unsigned int count_3ulp_diff = 0; */ long unsigned int count_total_diff[PERMIT+1]; int count, j; for (i = 0; i < PERMIT+1; i++) { count_total_diff[i] = 0; } for (i = 0; i < 4294967295; i++) { if ((i % 100000000) == 0) { printf("> checked (%2u/42)\n", i / 100000000); } a.uint32 = i; n.uint32 = normalize(i); result.uint32 = finv(a.uint32); correct.fl32 = 1.0 / n.fl32; //非正規仮数を0に潰す count = count_diff(result.uint32, correct.uint32); if (count < PERMIT+1) { count_total_diff[count]++; } else { if (total_mistakes <= 5) { show_testcase(a, result, correct); } total_mistakes++; } /* switch (count_diff(result.uint32, correct.uint32)) { case 0: count_no_diff++; break; case 1: count_1ulp_diff++; break; case 2: count_2ulp_diff++; break; case 3: count_3ulp_diff++; break; default: total_mistakes++; if (total_mistakes <= 5) { show_testcase(a, result, correct); } if (total_mistakes == 5) { printf("more than 5 mistakes.\n"); } break; } */ } /* printf("total no diff : %lu\n", count_no_diff); printf("total 1ulp diff : %lu\n", count_1ulp_diff); printf("total 2ulp diff : %lu\n", count_2ulp_diff); printf("total 3ulp diff : %lu\n", count_3ulp_diff); printf("total mistakes : %lu (more than 3ulp)\n", total_mistakes); */ for (j = 0; j < PERMIT+1; j++) { printf("total %dulp diff : %lu\n", j, count_total_diff[j]); } printf("total mistakes : %lu\n", total_mistakes); return 0; }