📄 x-cvsweb-markup(60)
字号:
size_t len = strlen(f)+1; char *dup = memcpy(alloca(len), f, len); char *low = dup + len - _FP_W_TYPE_SIZE/4 - 1; u.bits.frac0 = strtoul(low, 0, 16); *low = 0; u.bits.frac1 = strtoul(dup, 0, 16); }#else u.bits.frac = strtoul(f, 0, 16);#endif return u.flt;} /*======================================================================*/fpu_control_t fcw0, fcw1;void test_float_arith(float (*tf)(float, float), float (*rf)(float, float), float x, float y){ float tr, rr; rr = (*rf)(x, y); tr = (*tf)(x, y); if (memcmp(&tr, &rr, sizeof(float)) != 0) { fputs("error:\n\tx = ", stdout); print_float(x); fputs("\n\ty = ", stdout); print_float(y); fputs("\n\ttrue = ", stdout); print_float(rr); fputs("\n\tfalse = ", stdout); print_float(tr); putchar('\n'); }}void test_double_arith(double (*tf)(double, double), double (*rf)(double, double), double x, double y){ double tr, rr;#ifdef __i386__ /* Don't worry. Even this does not make it error free on ia32. If the result is denormal, it will not honour the double precision and generate bad results anyway. On the other side, who wants to use ia32 for IEEE math? I don't. */ _FPU_GETCW(fcw0); fcw1 = ((fcw0 & ~_FPU_EXTENDED) | _FPU_DOUBLE); _FPU_SETCW(fcw1);#endif rr = (*rf)(x, y);#ifdef __i386__ _FPU_SETCW(fcw0);#endif tr = (*tf)(x, y); if (memcmp(&tr, &rr, sizeof(double)) != 0) { fputs("error:\n\tx = ", stdout); print_double(x); fputs("\n\ty = ", stdout); print_double(y); fputs("\n\ttrue = ", stdout); print_double(rr); fputs("\n\tfalse = ", stdout); print_double(tr); putchar('\n'); }}void test_float_double_conv(float x){ double tr, rr; rr = r_extendsfdf2(x); tr = __extendsfdf2(x); if (memcmp(&tr, &rr, sizeof(double)) != 0) { fputs("error:\n\tx = ", stdout); print_float(x); fputs("\n\ttrue = ", stdout); print_double(rr); fputs("\n\tfalse = ", stdout); print_double(tr); putchar('\n'); }}void test_double_float_conv(double x){ float tr, rr; rr = r_truncdfsf2(x); tr = __truncdfsf2(x); if (memcmp(&tr, &rr, sizeof(float)) != 0) { fputs("error:\n\tx = ", stdout); print_double(x); fputs("\n\ttrue = ", stdout); print_float(rr); fputs("\n\tfalse = ", stdout); print_float(tr); putchar('\n'); }}void test_int_float_conv(int x){ float tr, rr; rr = r_floatsisf(x); tr = __floatsisf(x); if (memcmp(&tr, &rr, sizeof(float)) != 0) { printf("error\n\tx = %d", x); fputs("\n\ttrue = ", stdout); print_float(rr); fputs("\n\tfalse = ", stdout); print_float(tr); putchar('\n'); }}void test_int_double_conv(int x){ double tr, rr; rr = r_floatsidf(x); tr = __floatsidf(x); if (memcmp(&tr, &rr, sizeof(double)) != 0) { printf("error\n\tx = %d", x); fputs("\n\ttrue = ", stdout); print_double(rr); fputs("\n\tfalse = ", stdout); print_double(tr); putchar('\n'); }}void test_float_int_conv(float x){ int tr, rr; rr = r_fixsfsi(x); tr = __fixsfsi(x); if (rr != tr) { fputs("error:\n\tx = ", stdout); print_float(x); printf("\n\ttrue = %d\n\tfalse = %d\n", rr, tr); }} void test_double_int_conv(double x){ int tr, rr; rr = r_fixsfsi(x); tr = __fixsfsi(x); if (rr != tr) { fputs("error:\n\tx = ", stdout); print_double(x); printf("\n\ttrue = %d\n\tfalse = %d\n", rr, tr); }}int eq0(int x) { return x == 0; }int ne0(int x) { return x != 0; }int le0(int x) { return x <= 0; }int lt0(int x) { return x < 0; }int ge0(int x) { return x >= 0; }int gt0(int x) { return x > 0; }void test_float_cmp(int (*tf)(float, float), int (*rf)(float, float), int (*cmp0)(int), float x, float y){ int tr, rr; rr = (*rf)(x, y); tr = (*tf)(x, y); if (cmp0(rr) != cmp0(tr)) { fputs("error:\n\tx = ", stdout); print_float(x); fputs("\n\ty = ", stdout); print_float(y); printf("\n\ttrue = %d\n\tfalse = %d\n", rr, tr); }}void test_double_cmp(int (*tf)(double, double), int (*rf)(double, double), int (*cmp0)(int), double x, double y){ int tr, rr; rr = (*rf)(x, y); tr = (*tf)(x, y); if (cmp0(rr) != cmp0(tr)) { fputs("error:\n\tx = ", stdout); print_double(x); fputs("\n\ty = ", stdout); print_double(y); printf("\n\ttrue = %d\n\tfalse = %d\n", rr, tr); }}/*======================================================================*/int main(int ac, char **av){#ifdef __alpha__ __ieee_set_fp_control(0);#endif av++, ac--; switch (*(*av)++) { { float (*r)(float, float); float (*t)(float, float); do { case 'a': r = r_addsf3; t = __addsf3; break; case 's': r = r_subsf3; t = __subsf3; break; case 'm': r = r_mulsf3; t = __mulsf3; break; case 'd': r = r_divsf3; t = __divsf3; break; case 'r': r = r_sqrtsf3; t = __sqrtsf3; break; case 'j': r = r_negsf3; t = __negsf3; break; } while (0); switch (*(*av)++) { case 'n': { int count = (ac > 1 ? atoi(av[1]) : 100); while (count--) test_float_arith(t, r, rand_float(), rand_float()); } break; case 's': { int i, j; for (i = 0; i < NSPECIALS; i++) for (j = 0; j < NSPECIALS; j++) test_float_arith(t, r, gen_special_float(i), gen_special_float(j)); } break; case 0: if (ac < 7) abort(); test_float_arith(t, r, build_float(av[1], av[2], av[3]), build_float(av[4], av[5], av[6])); break; } } break; { double (*r)(double, double); double (*t)(double, double); do { case 'A': r = r_adddf3; t = __adddf3; break; case 'S': r = r_subdf3; t = __subdf3; break; case 'M': r = r_muldf3; t = __muldf3; break; case 'D': r = r_divdf3; t = __divdf3; break; case 'R': r = r_sqrtdf3; t = __sqrtdf3; break; case 'J': r = r_negdf3; t = __negdf3; break; } while (0); switch (*(*av)++) { case 'n': { int count = (ac > 1 ? atoi(av[1]) : 100); while (count--) test_double_arith(t, r, rand_double(), rand_double()); } break; case 's': { int i, j; for (i = 0; i < NSPECIALS; i++) for (j = 0; j < NSPECIALS; j++) test_double_arith(t, r, gen_special_double(i),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -