📄 t-ostream.cc
字号:
MPZ_CHECK_FORMAT (mpq_numref (q)); MPZ_CHECK_FORMAT (mpq_denref (q)); if (option_check_standard && mpz_fits_slong_p (mpq_numref(q)) && mpq_integer_p (q)) { ostrstream got; long n = mpz_get_si (mpq_numref(q)); CALL (got << n << '\0'); if (strcmp (got.str(), data[i].want) != 0) { printf ("check_mpq data[%d] doesn't match standard ostream output\n", i); printf (" q: %s\n", data[i].q); printf (" n: %ld\n", n); DUMP (); } } { ostrstream got; CALL (operator<< (got, q) << '\0'); if (strcmp (got.str(), data[i].want) != 0) { printf ("mpq operator<< wrong, data[%d]\n", i); printf (" q: %s\n", data[i].q); mpq_trace (" q", q); ABORT (); } } } mpq_clear (q);}voidcheck_mpf (void){ static const struct { const char *f; const char *want; ios::fmtflags flags; int width; int precision; char fill; } data[] = { { "0", "0", ios::dec }, { "0", "+0", ios::dec | ios::showpos }, { "0", "0.00000", ios::dec | ios::showpoint }, { "0", "0", ios::dec | ios::fixed }, { "0", "0.", ios::dec | ios::fixed | ios::showpoint }, { "0", "0.000000e+00", ios::dec | ios::scientific }, { "0", "0.000000e+00", ios::dec | ios::scientific | ios::showpoint }, { "0", "0", ios::dec, 0, 4 }, { "0", "0.000", ios::dec | ios::showpoint, 0, 4 }, { "0", "0.0000", ios::dec | ios::fixed, 0, 4 }, { "0", "0.0000", ios::dec | ios::fixed | ios::showpoint, 0, 4 }, { "0", "0.0000e+00", ios::dec | ios::scientific, 0, 4 }, { "0", "0.0000e+00", ios::dec | ios::scientific | ios::showpoint, 0, 4 }, { "1", "1", ios::dec }, { "1", "+1", ios::dec | ios::showpos }, { "1", "1.00000", ios::dec | ios::showpoint }, { "1", "1", ios::dec | ios::fixed }, { "1", "1.", ios::dec | ios::fixed | ios::showpoint }, { "1", "1.000000e+00", ios::dec | ios::scientific }, { "1", "1.000000e+00", ios::dec | ios::scientific | ios::showpoint }, { "1", "1", ios::dec, 0, 4 }, { "1", "1.000", ios::dec | ios::showpoint, 0, 4 }, { "1", "1.0000", ios::dec | ios::fixed, 0, 4 }, { "1", "1.0000", ios::dec | ios::fixed | ios::showpoint, 0, 4 }, { "1", "1.0000e+00", ios::dec | ios::scientific, 0, 4 }, { "1", "1.0000e+00", ios::dec | ios::scientific | ios::showpoint, 0, 4 }, { "-1", "-1", ios::dec | ios::showpos }, { "-1", " -1", ios::dec, 4 }, { "-1", "- 1", ios::dec | ios::internal, 4 }, { "-1", "-1 ", ios::dec | ios::left, 4 }, { "-1", " -0x1", ios::hex | ios::showbase, 6 }, { "-1", "-0x 1", ios::hex | ios::showbase | ios::internal, 6 }, { "-1", "-0x1 ", ios::hex | ios::showbase | ios::left, 6 }, { "1", "*********1", ios::dec, 10, 4, '*' }, { "1234", "******1234", ios::dec, 10, 4, '*' }, { "1234", "*****1234.", ios::dec | ios::showpoint, 10, 4, '*' }, { "12345", "1.23e+04", ios::dec, 0, 3 }, { "12345", "12345.", ios::dec | ios::fixed | ios::showpoint }, { "1.9999999", "2", ios::dec, 0, 1 }, { "1.0009999999", "1.001", ios::dec, 0, 4 }, { "1.0001", "1", ios::dec, 0, 4 }, { "1.0004", "1", ios::dec, 0, 4 }, { "1.000555", "1.001", ios::dec, 0, 4 }, { "1.0002", "1.000", ios::dec | ios::fixed, 0, 3 }, { "1.0008", "1.001", ios::dec | ios::fixed, 0, 3 }, { "0", "0", ios::hex }, { "0", "0x0", ios::hex | ios::showbase }, { "0", "0X0", ios::hex | ios::showbase | ios::uppercase }, { "123", "7b", ios::hex }, { "123", "0x7b", ios::hex | ios::showbase }, { "123", "0X7B", ios::hex | ios::showbase | ios::uppercase }, { "0", "0.000@+00", ios::hex | ios::scientific, 0, 3 }, { "256", "1.000@+02", ios::hex | ios::scientific, 0, 3 }, { "123", "7.b@+01", ios::hex | ios::scientific, 0, 1 }, { "123", "7.B@+01", ios::hex | ios::scientific | ios::uppercase, 0, 1 }, { "123", "0x7.b@+01", ios::hex | ios::scientific | ios::showbase, 0, 1 }, { "123", "0X7.B@+01", ios::hex | ios::scientific | ios::showbase | ios::uppercase, 0, 1 }, { "1099511627776", "1.0@+10", ios::hex | ios::scientific, 0, 1 }, { "1099511627776", "1.0@+10", ios::hex | ios::scientific | ios::uppercase, 0, 1 }, { "0.0625", "1.00@-01", ios::hex | ios::scientific, 0, 2 }, { "0", "0", ios::oct }, { "123", "173", ios::oct }, { "123", "0173", ios::oct | ios::showbase }, /* octal showbase suppressed for 0 */ { "0", "0", ios::oct | ios::showbase }, { ".125", "00.1", ios::oct | ios::showbase, 0, 1 }, { ".015625", "00.01", ios::oct | ios::showbase, 0, 2 }, { ".125", "00.1", ios::fixed | ios::oct | ios::showbase, 0, 1 }, { ".015625", "0.0", ios::fixed | ios::oct | ios::showbase, 0, 1 }, { ".015625", "00.01", ios::fixed | ios::oct | ios::showbase, 0, 2 }, { "0.125", "1.000000e-01", ios::oct | ios::scientific }, { "0.125", "+1.000000e-01", ios::oct | ios::scientific | ios::showpos }, { "-0.125", "-1.000000e-01", ios::oct | ios::scientific }, { "-0.125", "-1.000000e-01", ios::oct | ios::scientific | ios::showpos }, { "0", "0.000e+00", ios::oct | ios::scientific, 0, 3 }, { "256", "4.000e+02", ios::oct | ios::scientific, 0, 3 }, { "256", "04.000e+02", ios::oct | ios::scientific | ios::showbase, 0, 3 }, { "256", "4.000E+02", ios::oct | ios::scientific | ios::uppercase, 0, 3 }, { "256", "04.000E+02", ios::oct | ios::scientific | ios::showbase | ios::uppercase, 0, 3 }, { "16777216", "1.000000e+08", ios::oct | ios::scientific }, { "16777216", "1.000000E+08", ios::oct | ios::scientific | ios::uppercase }, { "16777216", "01.000000e+08", ios::oct | ios::scientific | ios::showbase }, { "16777216", "01.000000E+08", ios::oct | ios::scientific | ios::showbase | ios::uppercase }, { "16777216", "+01.000000e+08", ios::oct | ios::scientific | ios::showbase | ios::showpos }, { "16777216", "+01.000000E+08", ios::oct | ios::scientific | ios::showbase | ios::showpos | ios::uppercase }, { "-16777216", "-01.000000e+08", ios::oct | ios::scientific | ios::showbase | ios::showpos }, { "-16777216", "-01.000000E+08", ios::oct | ios::scientific | ios::showbase | ios::showpos | ios::uppercase }, }; size_t i; mpf_t f, f2; double d; mpf_init (f); mpf_init (f2); for (i = 0; i < numberof (data); i++) { mpf_set_str_or_abort (f, data[i].f, 0); d = mpf_get_d (f); mpf_set_d (f2, d); if (option_check_standard && mpf_cmp (f, f2) == 0 && ! (data[i].flags & (ios::hex | ios::oct | ios::showbase))) { ostrstream got; CALL (got << d << '\0'); if (strcmp (got.str(), data[i].want) != 0) { printf ("check_mpf data[%d] doesn't match standard ostream output\n", i); printf (" f: %s\n", data[i].f); printf (" d: %g\n", d); DUMP (); } } { ostrstream got; CALL (operator<< (got, f) << '\0'); if (strcmp (got.str(), data[i].want) != 0) { printf ("mpf operator<< wrong, data[%d]\n", i); printf (" f: %s\n", data[i].f); mpf_trace (" f", f); ABORT (); } } } mpf_clear (f); mpf_clear (f2);}intmain (int argc, char *argv[]){ if (argc > 1 && strcmp (argv[1], "-s") == 0) option_check_standard = 1; tests_start (); check_mpz (); check_mpq (); check_mpf (); tests_end (); exit (0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -