コード例 #1
0
ATF_TC_BODY(alternate_form, tc)
{

	ATF_REQUIRE(setlocale(LC_NUMERIC, "C"));

	testfmt("1.250e+00", "%#.3e", 1.25);
	testfmt("123.000000", "%#f", 123.0);
	testfmt(" 12345.", "%#7.5g", 12345.0);
	testfmt(" 1.00000", "%#8g", 1.0);
	testfmt("0.0", "%#.2g", 0.0);
}
コード例 #2
0
ATF_TC_BODY(padding, tc)
{

	ATF_REQUIRE(setlocale(LC_NUMERIC, "C"));

	testfmt("0.000000e+00", "%e", 0.0);
	testfmt("0.000000", "%F", (double)0.0);
	testfmt("0", "%G", 0.0);
	testfmt("  0", "%3.0Lg", 0.0L);
	testfmt("    0", "%5.0f", 0.001);
}
コード例 #3
0
ファイル: printbasic_test.c プロジェクト: hbsciw/freebsd
ATF_TC_BODY(int_limits, tc)
{

	ATF_REQUIRE(setlocale(LC_NUMERIC, "C"));

	/*
	 * Check that printing the largest negative number does not cause
	 * overflow when it is negated.
	 */
	testfmt(S_INT32MIN, "%d", INT_MIN);
	testfmt(S_INT64MIN, "%jd", INTMAX_MIN);
}
コード例 #4
0
ATF_TC_BODY(signed_conversions, tc)
{

	ATF_REQUIRE(setlocale(LC_NUMERIC, "C"));

	testfmt("+2.500000e-01", "%+e", 0.25);
	testfmt("+0.000000", "%+F", 0.0);
	testfmt("-1", "%+g", -1.0);

	testfmt("-1.000000e+00", "% e", -1.0);
	testfmt("+1.000000", "% +f", 1.0);
	testfmt(" 1", "% g", 1.0);
	testfmt(" 0", "% g", 0.0);
}
コード例 #5
0
ATF_TC_BODY(precision_specifiers, tc)
{

	ATF_REQUIRE(setlocale(LC_NUMERIC, "C"));

	testfmt("1.0123e+00", "%.4e", 1.0123456789);
	testfmt("1.0123", "%.4f", 1.0123456789);
	testfmt("1.012", "%.4g", 1.0123456789);
	testfmt("1.2346e-02", "%.4e", 0.0123456789);
	testfmt("0.0123", "%.4f", 0.0123456789);
	testfmt("0.01235", "%.4g", 0.0123456789);
}
コード例 #6
0
ATF_TC_BODY(hexadecimal_floating_point, tc)
{

	ATF_REQUIRE(setlocale(LC_NUMERIC, "C"));

	/*
	 * Hexadecimal floating point (%a, %A) tests.  Some of these
	 * are only valid if the implementation converts to hex digits
	 * on nibble boundaries.
	 */
	testfmt("0x0p+0", "%a", 0x0.0p0);
	testfmt("0X0.P+0", "%#LA", 0x0.0p0L);
	testfmt("inf", "%La", (long double)INFINITY);
	testfmt("+INF", "%+A", INFINITY);
	testfmt("nan", "%La", (long double)NAN);
	testfmt("NAN", "%A", NAN);

	testfmt(" 0x1.23p+0", "%10a", 0x1.23p0);
	testfmt(" 0x1.23p-500", "%12a", 0x1.23p-500);
	testfmt(" 0x1.2p+40", "%10.1a", 0x1.23p40);
	testfmt(" 0X1.230000000000000000000000P-4", "%32.24A", 0x1.23p-4);
	testfmt("0x1p-1074", "%a", 0x1p-1074);
	testfmt("0x1.2345p-1024", "%a", 0x1.2345p-1024);

#if (LDBL_MANT_DIG == 64)
	testfmt("0x1.921fb54442d18468p+1", "%La", 0x3.243f6a8885a308dp0L);
	testfmt("0x1p-16445", "%La", 0x1p-16445L);
	testfmt("0x1.30ecap-16381", "%La", 0x9.8765p-16384L);
#elif (LDBL_MANT_DIG == 113)
	testfmt("0x1.921fb54442d18469898cc51701b8p+1", "%La",
	    0x3.243f6a8885a308d313198a2e037p0L);
	testfmt("0x1p-16494", "%La", 0x1p-16494L);
	testfmt("0x1.2345p-16384", "%La", 0x1.2345p-16384L);
#else
	testfmt("0x1.921fb54442d18p+1", "%La", 0x3.243f6a8885a31p0L);
	testfmt("0x1p-1074", "%La", 0x1p-1074L);
	testfmt("0x1.30ecap-1021", "%La", 0x9.8765p-1024L);
#endif
}
コード例 #7
0
ATF_TC_BODY(decimal_rounding, tc)
{

	ATF_REQUIRE(setlocale(LC_NUMERIC, "C"));

	fesetround(FE_DOWNWARD);
	testfmt("4.437", "%.3f", 4.4375);
	testfmt("-4.438", "%.3f", -4.4375);
	testfmt("4.437", "%.3Lf", 4.4375L);
	testfmt("-4.438", "%.3Lf", -4.4375L);

	fesetround(FE_UPWARD);
	testfmt("4.438", "%.3f", 4.4375);
	testfmt("-4.437", "%.3f", -4.4375);
	testfmt("4.438", "%.3Lf", 4.4375L);
	testfmt("-4.437", "%.3Lf", -4.4375L);

	fesetround(FE_TOWARDZERO);
	testfmt("4.437", "%.3f", 4.4375);
	testfmt("-4.437", "%.3f", -4.4375);
	testfmt("4.437", "%.3Lf", 4.4375L);
	testfmt("-4.437", "%.3Lf", -4.4375L);

	fesetround(FE_TONEAREST);
	testfmt("4.438", "%.3f", 4.4375);
	testfmt("-4.438", "%.3f", -4.4375);
	testfmt("4.438", "%.3Lf", 4.4375L);
	testfmt("-4.438", "%.3Lf", -4.4375L);
}
コード例 #8
0
ATF_TC_BODY(padding_and_decimal_point_placement, tc)
{

	ATF_REQUIRE(setlocale(LC_NUMERIC, "C"));

	testfmt("03.2E+00", "%08.1E", 3.25);
	testfmt("003.25", "%06.2F", 3.25);
	testfmt("0003.25", "%07.4G", 3.25);

	testfmt("3.14159e-05", "%g", 3.14159e-5);
	testfmt("0.000314159", "%g", 3.14159e-4);
	testfmt("3.14159e+06", "%g", 3.14159e6);
	testfmt("314159", "%g", 3.14159e5);
	testfmt("314159.", "%#g", 3.14159e5);

	testfmt(" 9.000000e+03", "%13e", 9000.0);
	testfmt(" 9000.000000", "%12f", 9000.0);
	testfmt(" 9000", "%5g", 9000.0);
	testfmt(" 900000.", "%#8g", 900000.0);
	testfmt(" 9e+06", "%6g", 9000000.0);
	testfmt(" 9.000000e-04", "%13e", 0.0009);
	testfmt(" 0.000900", "%9f", 0.0009);
	testfmt(" 0.0009", "%7g", 0.0009);
	testfmt(" 9e-05", "%6g", 0.00009);
	testfmt(" 9.00000e-05", "%#12g", 0.00009);
	testfmt(" 9.e-05", "%#7.1g", 0.00009);

	testfmt(" 0.0", "%4.1f", 0.0);
	testfmt("90.0", "%4.1f", 90.0);
	testfmt(" 100", "%4.0f", 100.0);
	testfmt("9.0e+01", "%4.1e", 90.0);
	testfmt("1e+02", "%4.0e", 100.0);
}
コード例 #9
0
ファイル: test-printbasic.c プロジェクト: JabirTech/Source
int
main(int argc, char *argv[])
{

	printf("1..2\n");
	assert(setlocale(LC_NUMERIC, "C"));

	/* The test requires these to be true. */
	assert(UINTMAX_MAX == UINT64_MAX);
	assert(UINT_MAX == UINT32_MAX);
	assert(USHRT_MAX == 0xffff);
	assert(UCHAR_MAX == 0xff);

	/*
	 * Make sure we handle signed vs. unsigned args correctly.
	 */
	testfmt("-1", "%jd", (intmax_t)-1);
	testfmt(S_UINT64MAX, "%ju", UINT64_MAX);

	testfmt("-1", "%td", (ptrdiff_t)-1);
	testfmt(S_SIZEMAX, "%tu", (size_t)-1);

	testfmt("-1", "%zd", (ssize_t)-1);
	testfmt(S_SIZEMAX, "%zu", (ssize_t)-1);

	testfmt("-1", "%ld", (long)-1);
	testfmt(S_ULONGMAX, "%lu", ULONG_MAX);

	testfmt("-1", "%lld", (long long)-1);
	testfmt(S_ULONGMAX, "%lu", ULLONG_MAX);

	testfmt("-1", "%d", -1);
	testfmt(S_UINT32MAX, "%lu", UINT32_MAX);

	testfmt("-1", "%hd", -1);
	testfmt("65535", "%hu", USHRT_MAX);

	testfmt("-1", "%hhd", -1);
	testfmt("255", "%hhu", UCHAR_MAX);

	printf("ok 1 - printbasic signed/unsigned\n");

	/*
	 * Check that printing the largest negative number does not cause
	 * overflow when it is negated.
	 */
	testfmt(S_INT32MIN, "%d", INT_MIN);
	testfmt(S_INT64MIN, "%jd", INTMAX_MIN);

	printf("ok 2 - printbasic INT_MIN\n");


	return (0);
}
コード例 #10
0
int
main(int argc, char *argv[])
{
    setvbuf(stdout, NULL, _IONBF, 0);

	printf("1..11\n");
	assert(setlocale(LC_NUMERIC, "C"));

#if __ANDROID__ && __x86_64__ && __clang__
    /* Print of long double values broken on Android/x86_64 when being built by clang.
     * See https://tracker.crystax.net/issues/830 for details.
     */
#define LONG_DOUBLE_PRINT_BROKEN 1
#else
#define LONG_DOUBLE_PRINT_BROKEN 0
#endif

	/*
	 * Basic tests of decimal output functionality.
	 */
	testfmt(" 1.000000E+00", "%13E", 1.0);
	testfmt("     1.000000", "%13f", 1.0);
	testfmt("            1", "%13G", 1.0);
#if !LONG_DOUBLE_PRINT_BROKEN
	testfmt(" 1.000000E+00", "%13LE", 1.0L);
	testfmt("     1.000000", "%13Lf", 1.0L);
	testfmt("            1", "%13LG", 1.0L);
#endif /* !LONG_DOUBLE_PRINT_BROKEN */

	testfmt("2.718282", "%.*f", -2, 2.7182818);

	testfmt("1.234568e+06", "%e", 1234567.8);
	testfmt("1234567.800000", "%f", 1234567.8);
	testfmt("1.23457E+06", "%G", 1234567.8);
#if !LONG_DOUBLE_PRINT_BROKEN
	testfmt("1.234568e+06", "%Le", 1234567.8L);
	testfmt("1234567.800000", "%Lf", 1234567.8L);
	testfmt("1.23457E+06", "%LG", 1234567.8L);
#endif /* !LONG_DOUBLE_PRINT_BROKEN */

#if (LDBL_MANT_DIG > DBL_MANT_DIG) && !defined(__i386__)
#if !LONG_DOUBLE_PRINT_BROKEN
	testfmt("123456789.864210", "%Lf", 123456789.8642097531L);
	testfmt("-1.23457E+08", "%LG", -123456789.8642097531L);
	testfmt("123456789.8642097531", "%.10Lf", 123456789.8642097531L);
#if !__gnu_linux__
	testfmt(" 3.141592653589793238e-4000", "%L27.18Le",
	    3.14159265358979323846e-4000L);
#endif
#endif /* !LONG_DOUBLE_PRINT_BROKEN */
#endif

	printf("ok 1 - printfloat\n");

	/*
	 * Infinities and NaNs
	 */
	testfmt("nan", "%e", NAN);
	testfmt("NAN", "%F", NAN);
	testfmt("nan", "%g", NAN);
#if !__ANDROID__
    /* Temporarily disable this test since it's broken.
     * See https://tracker.crystax.net/issues/817.
     */
	testfmt("NAN", "%LE", (long double)NAN);
#endif
#if !__APPLE__ || defined(__MAC_10_7)
	testfmt("  nan", "%05e", NAN);
#endif

	testfmt("INF", "%E", HUGE_VAL);
	testfmt("-inf", "%f", -HUGE_VAL);
	testfmt("+inf", "%+g", HUGE_VAL);
#if !__ANDROID__
    /* Temporarily disable these tests since they are broken.
     * See https://tracker.crystax.net/issues/818.
     */
	testfmt(" inf", "%4.2Le", HUGE_VALL);
	testfmt("-inf", "%Lf", -HUGE_VALL);
#endif
#if !__APPLE__ || defined(__MAC_10_7)
	testfmt("  inf", "%05e", HUGE_VAL);
	testfmt(" -inf", "%05e", -HUGE_VAL);
#endif

	printf("ok 2 - printfloat\n");

	/*
	 * Padding
	 */
	testfmt("0.000000e+00", "%e", 0.0);
	testfmt("0.000000", "%F", (double)0.0);
	testfmt("0", "%G", 0.0);
	testfmt("  0", "%3.0Lg", 0.0L);
	testfmt("    0", "%5.0f", 0.001);
	printf("ok 3 - printfloat\n");

	/*
	 * Precision specifiers
	 */
	testfmt("1.0123e+00", "%.4e", 1.0123456789);
	testfmt("1.0123", "%.4f", 1.0123456789);
	testfmt("1.012", "%.4g", 1.0123456789);
	testfmt("1.2346e-02", "%.4e", 0.0123456789);
	testfmt("0.0123", "%.4f", 0.0123456789);
	testfmt("0.01235", "%.4g", 0.0123456789);
	printf("ok 4 - printfloat\n");

	/*
	 * Thousands' separators and other locale fun
	 */
	testfmt("12345678.0625", "%'.04f", 12345678.0625);
	testfmt("0012345678.0625", "%'015.4F", 12345678.0625);

#if !__gnu_linux__
	assert(setlocale(LC_NUMERIC, "hi_IN.ISCII-DEV")); /* grouping == 2;3 */
	testfmt("123,456,78.0625", "%'.4f", 12345678.0625);
	testfmt("00123,456,78.0625", "%'017.4F", 12345678.0625);
	testfmt(" 90,00", "%'6.0f", 9000.0);
	testfmt("90,00.0", "%'.1f", 9000.0);

	assert(setlocale(LC_NUMERIC, "ru_RU.ISO8859-5")); /* decimalpoint==, */
	testfmt("3,1415", "%g", 3.1415);

	/* thousands=. decimalpoint=, grouping=3;3 */
	assert(setlocale(LC_NUMERIC, "el_GR.ISO8859-7")); /* decimalpoint==, */
	testfmt("1.234,00", "%'.2f", 1234.00);
	testfmt("123.456,789", "%'.3f", 123456.789);
#endif /* !__gnu_linux__ */

	assert(setlocale(LC_NUMERIC, "C"));
	testfmt("12345678.062500", "%'f", 12345678.0625);
	testfmt("9000.000000", "%'f", 9000.0);

	printf("ok 5 - printfloat\n");

	/*
	 * Signed conversions
	 */
	testfmt("+2.500000e-01", "%+e", 0.25);
	testfmt("+0.000000", "%+F", 0.0);
	testfmt("-1", "%+g", -1.0);

	testfmt("-1.000000e+00", "% e", -1.0);
	testfmt("+1.000000", "% +f", 1.0);
	testfmt(" 1", "% g", 1.0);
	testfmt(" 0", "% g", 0.0);

	printf("ok 6 - printfloat\n");

	/*
	 * ``Alternate form''
	 */
	testfmt("1.250e+00", "%#.3e", 1.25);
	testfmt("123.000000", "%#f", 123.0);
	testfmt(" 12345.", "%#7.5g", 12345.0);
	testfmt(" 1.00000", "%#8g", 1.0);
	testfmt("0.0", "%#.2g", 0.0);
	printf("ok 7 - printfloat\n");

	/*
	 * Padding and decimal point placement
	 */
	testfmt("03.2E+00", "%08.1E", 3.25);
	testfmt("003.25", "%06.2F", 3.25);
	testfmt("0003.25", "%07.4G", 3.25);

	testfmt("3.14159e-05", "%g", 3.14159e-5);
	testfmt("0.000314159", "%g", 3.14159e-4);
	testfmt("3.14159e+06", "%g", 3.14159e6);
	testfmt("314159", "%g", 3.14159e5);
	testfmt("314159.", "%#g", 3.14159e5);

	testfmt(" 9.000000e+03", "%13e", 9000.0);
	testfmt(" 9000.000000", "%12f", 9000.0);
	testfmt(" 9000", "%5g", 9000.0);
	testfmt(" 900000.", "%#8g", 900000.0);
	testfmt(" 9e+06", "%6g", 9000000.0);
	testfmt(" 9.000000e-04", "%13e", 0.0009);
	testfmt(" 0.000900", "%9f", 0.0009);
	testfmt(" 0.0009", "%7g", 0.0009);
	testfmt(" 9e-05", "%6g", 0.00009);
	testfmt(" 9.00000e-05", "%#12g", 0.00009);
	testfmt(" 9.e-05", "%#7.1g", 0.00009);

	testfmt(" 0.0", "%4.1f", 0.0);
	testfmt("90.0", "%4.1f", 90.0);
	testfmt(" 100", "%4.0f", 100.0);
	testfmt("9.0e+01", "%4.1e", 90.0);
	testfmt("1e+02", "%4.0e", 100.0);

	printf("ok 8 - printfloat\n");

#if __ANDROID__
/* Temporarily disable some tests since they are broken.
 * See https://tracker.crystax.net/issues/819 for details.
 */
#define FLOAT_DECIMAL_ROUNDING_DOWNWARD_BROKEN 1
#define FLOAT_DECIMAL_ROUNDING_UPWARD_BROKEN 1
#define FLOAT_DECIMAL_ROUNDING_TOWARDZERO_BROKEN 1
#define FLOAT_DECIMAL_ROUNDING_TONEAREST_BROKEN 0
#elif defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ <= 15
#define FLOAT_DECIMAL_ROUNDING_DOWNWARD_BROKEN 1
#define FLOAT_DECIMAL_ROUNDING_UPWARD_BROKEN 1
#define FLOAT_DECIMAL_ROUNDING_TOWARDZERO_BROKEN 1
#define FLOAT_DECIMAL_ROUNDING_TONEAREST_BROKEN 0
#else
#define FLOAT_DECIMAL_ROUNDING_DOWNWARD_BROKEN 0
#define FLOAT_DECIMAL_ROUNDING_UPWARD_BROKEN 0
#define FLOAT_DECIMAL_ROUNDING_TOWARDZERO_BROKEN 0
#define FLOAT_DECIMAL_ROUNDING_TONEAREST_BROKEN 0
#endif

#if !FLOAT_DECIMAL_ROUNDING_DOWNWARD_BROKEN
	/*
	 * Decimal rounding
	 */
	fesetround(FE_DOWNWARD);
	testfmt("4.437", "%.3f", 4.4375);
	testfmt("-4.438", "%.3f", -4.4375);
	testfmt("4.437", "%.3Lf", 4.4375L);
#if !__APPLE__ || defined(__MAC_10_7)
	testfmt("-4.438", "%.3Lf", -4.4375L);
#endif
#endif /* !FLOAT_DECIMAL_ROUNDING_DOWNWARD_BROKEN */

#if !FLOAT_DECIMAL_ROUNDING_UPWARD_BROKEN
	fesetround(FE_UPWARD);
	testfmt("4.438", "%.3f", 4.4375);
	testfmt("-4.437", "%.3f", -4.4375);
	testfmt("4.438", "%.3Lf", 4.4375L);
#if !__APPLE__ || defined(__MAC_10_7)
	testfmt("-4.437", "%.3Lf", -4.4375L);
#endif
#endif /* !FLOAT_DECIMAL_ROUNDING_UPWARD_BROKEN */

#if !FLOAT_DECIMAL_ROUNDING_TOWARDZERO_BROKEN
	fesetround(FE_TOWARDZERO);
	testfmt("4.437", "%.3f", 4.4375);
	testfmt("-4.437", "%.3f", -4.4375);
	testfmt("4.437", "%.3Lf", 4.4375L);
	testfmt("-4.437", "%.3Lf", -4.4375L);
#endif /* !FLOAT_DECIMAL_ROUNDING_TOWARDZERO_BROKEN */

#if !FLOAT_DECIMAL_ROUNDING_TONEAREST_BROKEN
	fesetround(FE_TONEAREST);
	testfmt("4.438", "%.3f", 4.4375);
	testfmt("-4.438", "%.3f", -4.4375);
#if !LONG_DOUBLE_PRINT_BROKEN
	testfmt("4.438", "%.3Lf", 4.4375L);
	testfmt("-4.438", "%.3Lf", -4.4375L);
#endif /* !LONG_DOUBLE_PRINT_BROKEN */
#endif /* !FLOAT_DECIMAL_ROUNDING_TONEAREST_BROKEN */

	printf("ok 9 - printfloat\n");

	/*
	 * Hexadecimal floating point (%a, %A) tests.  Some of these
	 * are only valid if the implementation converts to hex digits
	 * on nibble boundaries.
	 */
	testfmt("0x0p+0", "%a", 0x0.0p0);
	testfmt("0X0.P+0", "%#LA", 0x0.0p0L);
#if !LONG_DOUBLE_PRINT_BROKEN
	testfmt("inf", "%La", (long double)INFINITY);
#endif
	testfmt("+INF", "%+A", INFINITY);
#if !LONG_DOUBLE_PRINT_BROKEN
	testfmt("nan", "%La", (long double)NAN);
#endif
	testfmt("NAN", "%A", NAN);

	testfmt(" 0x1.23p+0", "%10a", 0x1.23p0);
	testfmt(" 0x1.23p-500", "%12a", 0x1.23p-500);
	testfmt(" 0x1.2p+40", "%10.1a", 0x1.23p40);
	testfmt(" 0X1.230000000000000000000000P-4", "%32.24A", 0x1.23p-4);
#if !__gnu_linux__
	testfmt("0x1p-1074", "%a", 0x1p-1074);
	testfmt("0x1.2345p-1024", "%a", 0x1.2345p-1024);
#endif /* !__gnu_linux__ */

#if !__APPLE__ && !__gnu_linux__
#if (LDBL_MANT_DIG == 64) && !defined(__i386__)
	testfmt("0x1.921fb54442d18468p+1", "%La", 0x3.243f6a8885a308dp0L);
	testfmt("0x1p-16445", "%La", 0x1p-16445L);
	testfmt("0x1.30ecap-16381", "%La", 0x9.8765p-16384L);
#elif (LDBL_MANT_DIG == 113)
	testfmt("0x1.921fb54442d18469898cc51701b8p+1", "%La",
	    0x3.243f6a8885a308d313198a2e037p0L);
	testfmt("0x1p-16494", "%La", 0x1p-16494L);
	testfmt("0x1.2345p-16384", "%La", 0x1.2345p-16384L);
#else
	testfmt("0x1.921fb54442d18p+1", "%La", 0x3.243f6a8885a31p0L);
	testfmt("0x1p-1074", "%La", 0x1p-1074L);
	testfmt("0x1.30ecap-1021", "%La", 0x9.8765p-1024L);
#endif
#endif /* !__APPLE__ && !__gnu_linux__ */

	printf("ok 10 - printfloat\n");

#if __ANDROID__ && __arm__ && __SOFTFP__
/* Temporarily disable this test for ARM soft float since it's broken.
 * See https://tracker.crystax.net/issues/820 for details.
 */
#define FLOAT_HEX_ROUNDING_BROKEN 1
#elif defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ <= 15
#define FLOAT_HEX_ROUNDING_BROKEN 1
#else
#define FLOAT_HEX_ROUNDING_BROKEN 0
#endif

#if __CRYSTAX__ && __i386__
    /* This test fails on x86 emulator so temporarily disable it for such case.
     * See https://tracker.crystax.net/issues/820 for details.
     */
    if (crystax_device_type() != CRYSTAX_DEVICE_TYPE_EMULATOR)
    {
#endif

#if !FLOAT_HEX_ROUNDING_BROKEN
	/*
	 * Hexadecimal rounding
	 */
	fesetround(FE_TOWARDZERO);
	testfmt("0X1.23456789ABCP+0", "%.11A", 0x1.23456789abcdep0);
	testfmt("-0x1.23456p+0", "%.5a", -0x1.23456789abcdep0);
	testfmt("0x1.23456p+0", "%.5a", 0x1.23456789abcdep0);
	testfmt("0x1.234567p+0", "%.6a", 0x1.23456789abcdep0);
	testfmt("-0x1.234566p+0", "%.6a", -0x1.23456689abcdep0);

	fesetround(FE_DOWNWARD);
	testfmt("0X1.23456789ABCP+0", "%.11A", 0x1.23456789abcdep0);
	testfmt("-0x1.23457p+0", "%.5a", -0x1.23456789abcdep0);
	testfmt("0x1.23456p+0", "%.5a", 0x1.23456789abcdep0);
	testfmt("0x1.234567p+0", "%.6a", 0x1.23456789abcdep0);
	testfmt("-0x1.234567p+0", "%.6a", -0x1.23456689abcdep0);

	fesetround(FE_UPWARD);
	testfmt("0X1.23456789ABDP+0", "%.11A", 0x1.23456789abcdep0);
	testfmt("-0x1.23456p+0", "%.5a", -0x1.23456789abcdep0);
	testfmt("0x1.23457p+0", "%.5a", 0x1.23456789abcdep0);
	testfmt("0x1.234568p+0", "%.6a", 0x1.23456789abcdep0);
	testfmt("-0x1.234566p+0", "%.6a", -0x1.23456689abcdep0);
#endif /* !FLOAT_HEX_ROUNDING_BROKEN */

#if __CRYSTAX__ && __i386__
    }
#endif

	fesetround(FE_TONEAREST);
	testfmt("0x1.23456789abcdep+4", "%a", 0x1.23456789abcdep4);
	testfmt("0X1.23456789ABDP+0", "%.11A", 0x1.23456789abcdep0);
	testfmt("-0x1.23456p+0", "%.5a", -0x1.23456789abcdep0);
	testfmt("0x1.23456p+0", "%.5a", 0x1.23456789abcdep0);
	testfmt("0x1.234568p+0", "%.6a", 0x1.23456789abcdep0);
#if !__APPLE__ || defined(__MAC_10_7)
	testfmt("-0x1.234567p+0", "%.6a", -0x1.23456689abcdep0);
#endif
#if !__APPLE__ && !__gnu_linux__
	testfmt("0x1.00p-1029", "%.2a", 0x1.fffp-1030);
	testfmt("0x1.00p-1026", "%.2a", 0xf.fffp-1030);
#endif /* !__APPLE__ && !__gnu_linux__ */
#if !__APPLE__ || defined(__MAC_10_7)
	testfmt("0x1.83p+0", "%.2a", 1.51);
#endif

	printf("ok 11 - printfloat\n");

	return (0);
}
コード例 #11
0
ATF_TC_BODY(infinities_and_nans, tc)
{

	ATF_REQUIRE(setlocale(LC_NUMERIC, "C"));

	testfmt("nan", "%e", NAN);
	testfmt("NAN", "%F", NAN);
	testfmt("nan", "%g", NAN);
	testfmt("NAN", "%LE", (long double)NAN);
	testfmt("  nan", "%05e", NAN);

	testfmt("INF", "%E", HUGE_VAL);
	testfmt("-inf", "%f", -HUGE_VAL);
	testfmt("+inf", "%+g", HUGE_VAL);
	testfmt(" inf", "%4.2Le", HUGE_VALL);
	testfmt("-inf", "%Lf", -HUGE_VALL);
	testfmt("  inf", "%05e", HUGE_VAL);
	testfmt(" -inf", "%05e", -HUGE_VAL);
}
コード例 #12
0
ファイル: printbasic_test.c プロジェクト: hbsciw/freebsd
ATF_TC_BODY(int_within_limits, tc)
{

	ATF_REQUIRE(setlocale(LC_NUMERIC, "C"));

	/* The test requires these to be true. */
	ATF_REQUIRE(UINTMAX_MAX == UINT64_MAX);
	ATF_REQUIRE(UINT_MAX == UINT32_MAX);
	ATF_REQUIRE(USHRT_MAX == 0xffff);
	ATF_REQUIRE(UCHAR_MAX == 0xff);

	/* Make sure we handle signed vs. unsigned args correctly. */
	testfmt("-1", "%jd", (intmax_t)-1);
	testfmt(S_UINT64MAX, "%ju", UINT64_MAX);

	testfmt("-1", "%td", (ptrdiff_t)-1);
	testfmt(S_SIZEMAX, "%tu", (size_t)-1);

	testfmt("-1", "%zd", (ssize_t)-1);
	testfmt(S_SIZEMAX, "%zu", (ssize_t)-1);

	testfmt("-1", "%ld", (long)-1);
	testfmt(S_ULONGMAX, "%lu", ULONG_MAX);

	testfmt("-1", "%lld", (long long)-1);
	testfmt(S_ULONGMAX, "%lu", ULLONG_MAX);

	testfmt("-1", "%d", -1);
	testfmt(S_UINT32MAX, "%lu", UINT32_MAX);

	testfmt("-1", "%hd", -1);
	testfmt("65535", "%hu", USHRT_MAX);

	testfmt("-1", "%hhd", -1);
	testfmt("255", "%hhu", UCHAR_MAX);
}
コード例 #13
0
ATF_TC_BODY(int_within_limits, tc)
{

	ATF_REQUIRE(setlocale(LC_NUMERIC, "C"));

	/* The test requires these to be true. */
	ATF_REQUIRE(UINTMAX_MAX == UINT64_MAX);
	ATF_REQUIRE(UINT_MAX == UINT32_MAX);
	ATF_REQUIRE(USHRT_MAX == 0xffff);
	ATF_REQUIRE(UCHAR_MAX == 0xff);

	/* Make sure we handle signed vs. unsigned args correctly. */
	testfmt("-1", "%jd", (intmax_t)-1);
	testfmt(S_UINT64MAX, "%ju", UINT64_MAX);

	if (sizeof(ptrdiff_t) != sizeof(uintmax_t))
		atf_tc_expect_fail("the %%t qualifier is broken on 32-bit "
		    "platforms where there's a mismatch between ptrdiff_t and "
		    "uintmax_t's type width; bug # 191674");

	testfmt("-1", "%td", (ptrdiff_t)-1);
	testfmt(S_SIZEMAX, "%tu", (size_t)-1);

	testfmt("-1", "%zd", (ssize_t)-1);
	testfmt(S_SIZEMAX, "%zu", (ssize_t)-1);

	testfmt("-1", "%ld", (long)-1);
	testfmt(S_ULONGMAX, "%lu", ULONG_MAX);

	testfmt("-1", "%lld", (long long)-1);
	testfmt(S_ULLONGMAX, "%llu", ULLONG_MAX);

	testfmt("-1", "%d", -1);
	testfmt(S_UINT32MAX, "%u", UINT32_MAX);

	testfmt("-1", "%hd", -1);
	testfmt("65535", "%hu", USHRT_MAX);

	testfmt("-1", "%hhd", -1);
	testfmt("255", "%hhu", UCHAR_MAX);
}
コード例 #14
0
ファイル: itrbnfp.cpp プロジェクト: LittoCats/OT_4010D
void 
IntlTestRBNFParse::TestParse() {
  // Try various rule parsing errors.  Shouldn't crash.

  logln("RBNF Parse test starting");

  // these rules make no sense but behave rationally
  const char* okrules[] = {
    "",
    "random text",
    "%foo:bar",
    "%foo: bar",
    "0:",
    "0::",
    ";",
    ";;",
    "%%foo:;",
    ":",
    "::",
    ":1",
    ":;",
    ":;:;",
    "-",
    "-1",
    "-:",
    ".",
    ".1",
    "[",
    "]",
    "[]",
    "[foo]",
    "[[]",
    "[]]",
    "[[]]",
    "[][]",
    "<",
    "<<",
    "<<<",
    "10:;9:;",
    ">",
    ">>",
    ">>>",
    "=",
    "==",
    "===",
    "=foo=",

    NULL,
  };

  // these rules would throw exceptions when formatting, if we could throw exceptions
  const char* exceptrules[] = {
    "10:", // formatting any value with a one's digit will fail
    "11: << x", // formating a multiple of 10 causes rollback rule to fail
    "%%foo: 0 foo; 10: =%%bar=; %%bar: 0: bar; 10: =%%foo=;",

    NULL,
  };

  // none of these rules should crash the formatter
  const char** allrules[] = {
    okrules,
    exceptrules,
    NULL,
  };

  for (int j = 0; allrules[j]; ++j) {
      const char** rules = allrules[j];
      for (int i = 0; rules[i]; ++i) {
          const char* rule = rules[i];
          logln("rule[%d] \"%s\"", i, rule);
          UErrorCode status = U_ZERO_ERROR;
          UParseError perr;
          RuleBasedNumberFormat* formatter = new RuleBasedNumberFormat(rule, Locale::getUS(), perr, status);
          
          if (U_SUCCESS(status)) {
              // format some values
              
              testfmt(formatter, 20, status);
              testfmt(formatter, 1.23, status);
              testfmt(formatter, -123, status);
              testfmt(formatter, .123, status);
              testfmt(formatter, 123, status);
              
          } else if (status == U_PARSE_ERROR) {
              logln("perror line: %x offset: %x context: %s|%s", perr.line, perr.offset, perr.preContext, perr.postContext);
          }

          delete formatter;
      }
  }
}
コード例 #15
0
ATF_TC_BODY(hexadecimal_rounding, tc)
{

	ATF_REQUIRE(setlocale(LC_NUMERIC, "C"));

	fesetround(FE_TOWARDZERO);
	testfmt("0X1.23456789ABCP+0", "%.11A", 0x1.23456789abcdep0);
	testfmt("-0x1.23456p+0", "%.5a", -0x1.23456789abcdep0);
	testfmt("0x1.23456p+0", "%.5a", 0x1.23456789abcdep0);
	testfmt("0x1.234567p+0", "%.6a", 0x1.23456789abcdep0);
	testfmt("-0x1.234566p+0", "%.6a", -0x1.23456689abcdep0);

	fesetround(FE_DOWNWARD);
	testfmt("0X1.23456789ABCP+0", "%.11A", 0x1.23456789abcdep0);
	testfmt("-0x1.23457p+0", "%.5a", -0x1.23456789abcdep0);
	testfmt("0x1.23456p+0", "%.5a", 0x1.23456789abcdep0);
	testfmt("0x1.234567p+0", "%.6a", 0x1.23456789abcdep0);
	testfmt("-0x1.234567p+0", "%.6a", -0x1.23456689abcdep0);

	fesetround(FE_UPWARD);
	testfmt("0X1.23456789ABDP+0", "%.11A", 0x1.23456789abcdep0);
	testfmt("-0x1.23456p+0", "%.5a", -0x1.23456789abcdep0);
	testfmt("0x1.23457p+0", "%.5a", 0x1.23456789abcdep0);
	testfmt("0x1.234568p+0", "%.6a", 0x1.23456789abcdep0);
	testfmt("-0x1.234566p+0", "%.6a", -0x1.23456689abcdep0);

	fesetround(FE_TONEAREST);
	testfmt("0x1.23456789abcdep+4", "%a", 0x1.23456789abcdep4);
	testfmt("0X1.23456789ABDP+0", "%.11A", 0x1.23456789abcdep0);
	testfmt("-0x1.23456p+0", "%.5a", -0x1.23456789abcdep0);
	testfmt("0x1.23456p+0", "%.5a", 0x1.23456789abcdep0);
	testfmt("0x1.234568p+0", "%.6a", 0x1.23456789abcdep0);
	testfmt("-0x1.234567p+0", "%.6a", -0x1.23456689abcdep0);
	testfmt("0x1.00p-1029", "%.2a", 0x1.fffp-1030);
	testfmt("0x1.00p-1026", "%.2a", 0xf.fffp-1030);
	testfmt("0x1.83p+0", "%.2a", 1.51);
}
コード例 #16
0
ATF_TC_BODY(float_within_limits, tc)
{

	ATF_REQUIRE(setlocale(LC_NUMERIC, "C"));

	/* Basic tests of decimal output functionality. */
	testfmt(" 1.000000E+00", "%13E", 1.0);
	testfmt("     1.000000", "%13f", 1.0);
	testfmt("            1", "%13G", 1.0);
	testfmt(" 1.000000E+00", "%13LE", 1.0L);
	testfmt("     1.000000", "%13Lf", 1.0L);
	testfmt("            1", "%13LG", 1.0L);

	testfmt("2.718282", "%.*f", -2, 2.7182818);

	testfmt("1.234568e+06", "%e", 1234567.8);
	testfmt("1234567.800000", "%f", 1234567.8);
	testfmt("1.23457E+06", "%G", 1234567.8);
	testfmt("1.234568e+06", "%Le", 1234567.8L);
	testfmt("1234567.800000", "%Lf", 1234567.8L);
	testfmt("1.23457E+06", "%LG", 1234567.8L);

#if (LDBL_MANT_DIG > DBL_MANT_DIG) && !defined(__i386__)
	testfmt("123456789.864210", "%Lf", 123456789.8642097531L);
	testfmt("-1.23457E+08", "%LG", -123456789.8642097531L);
	testfmt("123456789.8642097531", "%.10Lf", 123456789.8642097531L);
	testfmt(" 3.141592653589793238e-4000", "%L27.18Le",
	    3.14159265358979323846e-4000L);
#endif
}
コード例 #17
0
ATF_TC_BODY(thousands_separator_and_other_locale_tests, tc)
{

	ATF_REQUIRE(setlocale(LC_NUMERIC, "C"));

	testfmt("12345678.0625", "%'.04f", 12345678.0625);
	testfmt("0012345678.0625", "%'015.4F", 12345678.0625);

	ATF_REQUIRE(setlocale(LC_NUMERIC, "hi_IN.ISCII-DEV")); /* grouping == 2;3 */
	testfmt("1,23,45,678.0625", "%'.4f", 12345678.0625);
	testfmt("01,23,45,678.0625", "%'017.4F", 12345678.0625);
	testfmt(" 9,000", "%'6.0f", 9000.0);
	testfmt("9,000.0", "%'.1f", 9000.0);

	ATF_REQUIRE(setlocale(LC_NUMERIC, "ru_RU.ISO8859-5")); /* decimalpoint==, */
	testfmt("3,1415", "%g", 3.1415);

	/* thousands=. decimalpoint=, grouping=3;3 */
	ATF_REQUIRE(setlocale(LC_NUMERIC, "el_GR.ISO8859-7")); /* decimalpoint==, */
	testfmt("1.234,00", "%'.2f", 1234.00);
	testfmt("123.456,789", "%'.3f", 123456.789);

	ATF_REQUIRE(setlocale(LC_NUMERIC, "C"));
	testfmt("12345678.062500", "%'f", 12345678.0625);
	testfmt("9000.000000", "%'f", 9000.0);
}
コード例 #18
0
ファイル: test-printfloat.c プロジェクト: AhmadTux/freebsd
int
main(int argc, char *argv[])
{

	printf("1..11\n");
	assert(setlocale(LC_NUMERIC, "C"));

	/*
	 * Basic tests of decimal output functionality.
	 */
	testfmt(" 1.000000E+00", "%13E", 1.0);
	testfmt("     1.000000", "%13f", 1.0);
	testfmt("            1", "%13G", 1.0);
	testfmt(" 1.000000E+00", "%13LE", 1.0L);
	testfmt("     1.000000", "%13Lf", 1.0L);
	testfmt("            1", "%13LG", 1.0L);

	testfmt("2.718282", "%.*f", -2, 2.7182818);

	testfmt("1.234568e+06", "%e", 1234567.8);
	testfmt("1234567.800000", "%f", 1234567.8);
	testfmt("1.23457E+06", "%G", 1234567.8);
	testfmt("1.234568e+06", "%Le", 1234567.8L);
	testfmt("1234567.800000", "%Lf", 1234567.8L);
	testfmt("1.23457E+06", "%LG", 1234567.8L);

#if (LDBL_MANT_DIG > DBL_MANT_DIG) && !defined(__i386__)
	testfmt("123456789.864210", "%Lf", 123456789.8642097531L);
	testfmt("-1.23457E+08", "%LG", -123456789.8642097531L);
	testfmt("123456789.8642097531", "%.10Lf", 123456789.8642097531L);
	testfmt(" 3.141592653589793238e-4000", "%L27.18Le",
	    3.14159265358979323846e-4000L);
#endif

	printf("ok 1 - printfloat\n");

	/*
	 * Infinities and NaNs
	 */
	testfmt("nan", "%e", NAN);
	testfmt("NAN", "%F", NAN);
	testfmt("nan", "%g", NAN);
	testfmt("NAN", "%LE", (long double)NAN);
	testfmt("  nan", "%05e", NAN);

	testfmt("INF", "%E", HUGE_VAL);
	testfmt("-inf", "%f", -HUGE_VAL);
	testfmt("+inf", "%+g", HUGE_VAL);
	testfmt(" inf", "%4.2Le", HUGE_VALL);
	testfmt("-inf", "%Lf", -HUGE_VALL);
	testfmt("  inf", "%05e", HUGE_VAL);
	testfmt(" -inf", "%05e", -HUGE_VAL);

	printf("ok 2 - printfloat\n");

	/*
	 * Padding
	 */
	testfmt("0.000000e+00", "%e", 0.0);
	testfmt("0.000000", "%F", (double)0.0);
	testfmt("0", "%G", 0.0);
	testfmt("  0", "%3.0Lg", 0.0L);
	testfmt("    0", "%5.0f", 0.001);
	printf("ok 3 - printfloat\n");

	/*
	 * Precision specifiers
	 */
	testfmt("1.0123e+00", "%.4e", 1.0123456789);
	testfmt("1.0123", "%.4f", 1.0123456789);
	testfmt("1.012", "%.4g", 1.0123456789);
	testfmt("1.2346e-02", "%.4e", 0.0123456789);
	testfmt("0.0123", "%.4f", 0.0123456789);
	testfmt("0.01235", "%.4g", 0.0123456789);
	printf("ok 4 - printfloat\n");

	/*
	 * Thousands' separators and other locale fun
	 */
	testfmt("12345678.0625", "%'.04f", 12345678.0625);
	testfmt("0012345678.0625", "%'015.4F", 12345678.0625);

	assert(setlocale(LC_NUMERIC, "hi_IN.ISCII-DEV")); /* grouping == 2;3 */
	testfmt("123,456,78.0625", "%'.4f", 12345678.0625);
	testfmt("00123,456,78.0625", "%'017.4F", 12345678.0625);
	testfmt(" 90,00", "%'6.0f", 9000.0);
	testfmt("90,00.0", "%'.1f", 9000.0);

	assert(setlocale(LC_NUMERIC, "ru_RU.ISO8859-5")); /* decimalpoint==, */
	testfmt("3,1415", "%g", 3.1415);

	/* thousands=. decimalpoint=, grouping=3;3 */
	assert(setlocale(LC_NUMERIC, "el_GR.ISO8859-7")); /* decimalpoint==, */
	testfmt("1.234,00", "%'.2f", 1234.00);
	testfmt("123.456,789", "%'.3f", 123456.789);

	assert(setlocale(LC_NUMERIC, "C"));
	testfmt("12345678.062500", "%'f", 12345678.0625);
	testfmt("9000.000000", "%'f", 9000.0);

	printf("ok 5 - printfloat\n");

	/*
	 * Signed conversions
	 */
	testfmt("+2.500000e-01", "%+e", 0.25);
	testfmt("+0.000000", "%+F", 0.0);
	testfmt("-1", "%+g", -1.0);

	testfmt("-1.000000e+00", "% e", -1.0);
	testfmt("+1.000000", "% +f", 1.0);
	testfmt(" 1", "% g", 1.0);
	testfmt(" 0", "% g", 0.0);

	printf("ok 6 - printfloat\n");

	/*
	 * ``Alternate form''
	 */
	testfmt("1.250e+00", "%#.3e", 1.25);
	testfmt("123.000000", "%#f", 123.0);
	testfmt(" 12345.", "%#7.5g", 12345.0);
	testfmt(" 1.00000", "%#8g", 1.0);
	testfmt("0.0", "%#.2g", 0.0);
	printf("ok 7 - printfloat\n");

	/*
	 * Padding and decimal point placement
	 */
	testfmt("03.2E+00", "%08.1E", 3.25);
	testfmt("003.25", "%06.2F", 3.25);
	testfmt("0003.25", "%07.4G", 3.25);

	testfmt("3.14159e-05", "%g", 3.14159e-5);
	testfmt("0.000314159", "%g", 3.14159e-4);
	testfmt("3.14159e+06", "%g", 3.14159e6);
	testfmt("314159", "%g", 3.14159e5);
	testfmt("314159.", "%#g", 3.14159e5);

	testfmt(" 9.000000e+03", "%13e", 9000.0);
	testfmt(" 9000.000000", "%12f", 9000.0);
	testfmt(" 9000", "%5g", 9000.0);
	testfmt(" 900000.", "%#8g", 900000.0);
	testfmt(" 9e+06", "%6g", 9000000.0);
	testfmt(" 9.000000e-04", "%13e", 0.0009);
	testfmt(" 0.000900", "%9f", 0.0009);
	testfmt(" 0.0009", "%7g", 0.0009);
	testfmt(" 9e-05", "%6g", 0.00009);
	testfmt(" 9.00000e-05", "%#12g", 0.00009);
	testfmt(" 9.e-05", "%#7.1g", 0.00009);

	testfmt(" 0.0", "%4.1f", 0.0);
	testfmt("90.0", "%4.1f", 90.0);
	testfmt(" 100", "%4.0f", 100.0);
	testfmt("9.0e+01", "%4.1e", 90.0);
	testfmt("1e+02", "%4.0e", 100.0);

	printf("ok 8 - printfloat\n");

	/*
	 * Decimal rounding
	 */
	fesetround(FE_DOWNWARD);
	testfmt("4.437", "%.3f", 4.4375);
	testfmt("-4.438", "%.3f", -4.4375);
	testfmt("4.437", "%.3Lf", 4.4375L);
	testfmt("-4.438", "%.3Lf", -4.4375L);

	fesetround(FE_UPWARD);
	testfmt("4.438", "%.3f", 4.4375);
	testfmt("-4.437", "%.3f", -4.4375);
	testfmt("4.438", "%.3Lf", 4.4375L);
	testfmt("-4.437", "%.3Lf", -4.4375L);

	fesetround(FE_TOWARDZERO);
	testfmt("4.437", "%.3f", 4.4375);
	testfmt("-4.437", "%.3f", -4.4375);
	testfmt("4.437", "%.3Lf", 4.4375L);
	testfmt("-4.437", "%.3Lf", -4.4375L);

	fesetround(FE_TONEAREST);
	testfmt("4.438", "%.3f", 4.4375);
	testfmt("-4.438", "%.3f", -4.4375);
	testfmt("4.438", "%.3Lf", 4.4375L);
	testfmt("-4.438", "%.3Lf", -4.4375L);

	printf("ok 9 - printfloat\n");

	/*
	 * Hexadecimal floating point (%a, %A) tests.  Some of these
	 * are only valid if the implementation converts to hex digits
	 * on nibble boundaries.
	 */
	testfmt("0x0p+0", "%a", 0x0.0p0);
	testfmt("0X0.P+0", "%#LA", 0x0.0p0L);
	testfmt("inf", "%La", (long double)INFINITY);
	testfmt("+INF", "%+A", INFINITY);
	testfmt("nan", "%La", (long double)NAN);
	testfmt("NAN", "%A", NAN);

	testfmt(" 0x1.23p+0", "%10a", 0x1.23p0);
	testfmt(" 0x1.23p-500", "%12a", 0x1.23p-500);
	testfmt(" 0x1.2p+40", "%10.1a", 0x1.23p40);
	testfmt(" 0X1.230000000000000000000000P-4", "%32.24A", 0x1.23p-4);
	testfmt("0x1p-1074", "%a", 0x1p-1074);
	testfmt("0x1.2345p-1024", "%a", 0x1.2345p-1024);

#if (LDBL_MANT_DIG == 64) && !defined(__i386__)
	testfmt("0x1.921fb54442d18468p+1", "%La", 0x3.243f6a8885a308dp0L);
	testfmt("0x1p-16445", "%La", 0x1p-16445L);
	testfmt("0x1.30ecap-16381", "%La", 0x9.8765p-16384L);
#elif (LDBL_MANT_DIG == 113)
	testfmt("0x1.921fb54442d18469898cc51701b8p+1", "%La",
	    0x3.243f6a8885a308d313198a2e037p0L);
	testfmt("0x1p-16494", "%La", 0x1p-16494L);
	testfmt("0x1.2345p-16384", "%La", 0x1.2345p-16384L);
#else
	testfmt("0x1.921fb54442d18p+1", "%La", 0x3.243f6a8885a31p0L);
	testfmt("0x1p-1074", "%La", 0x1p-1074L);
	testfmt("0x1.30ecap-1021", "%La", 0x9.8765p-1024L);
#endif

	printf("ok 10 - printfloat\n");

	/*
	 * Hexadecimal rounding
	 */
	fesetround(FE_TOWARDZERO);
	testfmt("0X1.23456789ABCP+0", "%.11A", 0x1.23456789abcdep0);
	testfmt("-0x1.23456p+0", "%.5a", -0x1.23456789abcdep0);
	testfmt("0x1.23456p+0", "%.5a", 0x1.23456789abcdep0);
	testfmt("0x1.234567p+0", "%.6a", 0x1.23456789abcdep0);
	testfmt("-0x1.234566p+0", "%.6a", -0x1.23456689abcdep0);

	fesetround(FE_DOWNWARD);
	testfmt("0X1.23456789ABCP+0", "%.11A", 0x1.23456789abcdep0);
	testfmt("-0x1.23457p+0", "%.5a", -0x1.23456789abcdep0);
	testfmt("0x1.23456p+0", "%.5a", 0x1.23456789abcdep0);
	testfmt("0x1.234567p+0", "%.6a", 0x1.23456789abcdep0);
	testfmt("-0x1.234567p+0", "%.6a", -0x1.23456689abcdep0);

	fesetround(FE_UPWARD);
	testfmt("0X1.23456789ABDP+0", "%.11A", 0x1.23456789abcdep0);
	testfmt("-0x1.23456p+0", "%.5a", -0x1.23456789abcdep0);
	testfmt("0x1.23457p+0", "%.5a", 0x1.23456789abcdep0);
	testfmt("0x1.234568p+0", "%.6a", 0x1.23456789abcdep0);
	testfmt("-0x1.234566p+0", "%.6a", -0x1.23456689abcdep0);

	fesetround(FE_TONEAREST);
	testfmt("0x1.23456789abcdep+4", "%a", 0x1.23456789abcdep4);
	testfmt("0X1.23456789ABDP+0", "%.11A", 0x1.23456789abcdep0);
	testfmt("-0x1.23456p+0", "%.5a", -0x1.23456789abcdep0);
	testfmt("0x1.23456p+0", "%.5a", 0x1.23456789abcdep0);
	testfmt("0x1.234568p+0", "%.6a", 0x1.23456789abcdep0);
	testfmt("-0x1.234567p+0", "%.6a", -0x1.23456689abcdep0);
	testfmt("0x1.00p-1029", "%.2a", 0x1.fffp-1030);
	testfmt("0x1.00p-1026", "%.2a", 0xf.fffp-1030);
	testfmt("0x1.83p+0", "%.2a", 1.51);

	printf("ok 11 - printfloat\n");

	return (0);
}
コード例 #19
0
ファイル: fp.c プロジェクト: SylvestreG/bitrig
int
main(int argc, char *argv[])
{
	/*
	 * Basic tests of decimal output functionality.
	 */
	testfmt(" 1.000000E+00", "%13E", 1.0);
	testfmt("     1.000000", "%13f", 1.0);
	testfmt("            1", "%13G", 1.0);
	testfmt(" 1.000000E+00", "%13LE", 1.0L);
	testfmt("     1.000000", "%13Lf", 1.0L);
	testfmt("            1", "%13LG", 1.0L);

	testfmt("2.718282", "%.*f", -2, 2.7182818);

	testfmt("1.234568e+06", "%e", 1234567.8);
	testfmt("1234567.800000", "%f", 1234567.8);
	testfmt("1.23457E+06", "%G", 1234567.8);
	testfmt("1.234568e+06", "%Le", 1234567.8L);
	testfmt("1234567.800000", "%Lf", 1234567.8L);
	testfmt("1.23457E+06", "%LG", 1234567.8L);

#if (LDBL_MANT_DIG > DBL_MANT_DIG) && !defined(__i386__)
	testfmt("123456789.864210", "%Lf", 123456789.8642097531L);
	testfmt("-1.23457E+08", "%LG", -123456789.8642097531L);
	testfmt("123456789.8642097531", "%.10Lf", 123456789.8642097531L);
	testfmt(" 3.141592653589793238e-4000", "%L27.18Le",
	    3.14159265358979323846e-4000L);
#endif /* (LDBL_MANT_DIG > DBL_MANT_DIG) && !defined(__i386__) */

	/*
	 * Infinities and NaNs
	 */
#ifdef NAN
	testfmt("nan", "%e", NAN);
	testfmt("NAN", "%F", NAN);
	testfmt("nan", "%g", NAN);
	testfmt("NAN", "%LE", (long double)NAN);
	testfmt("  nan", "%05e", NAN);
#endif /* NAN */

	testfmt("INF", "%E", HUGE_VAL);
	testfmt("-inf", "%f", -HUGE_VAL);
	testfmt("+inf", "%+g", HUGE_VAL);
	testfmt(" inf", "%4.2Le", HUGE_VALL);
	testfmt("-inf", "%Lf", -HUGE_VALL);
	testfmt("  inf", "%05e", HUGE_VAL);
	testfmt(" -inf", "%05e", -HUGE_VAL);

	/*
	 * Padding
	 */
	testfmt("0.000000e+00", "%e", 0.0);
	testfmt("0.000000", "%F", (double)0.0);
	testfmt("0", "%G", 0.0);
	testfmt("  0", "%3.0Lg", 0.0L);
	testfmt("    0", "%5.0f", 0.001);

	/*
	 * Precision specifiers
	 */
	testfmt("1.0123e+00", "%.4e", 1.0123456789);
	testfmt("1.0123", "%.4f", 1.0123456789);
	testfmt("1.012", "%.4g", 1.0123456789);
	testfmt("1.2346e-02", "%.4e", 0.0123456789);
	testfmt("0.0123", "%.4f", 0.0123456789);
	testfmt("0.01235", "%.4g", 0.0123456789);

	/*
	 * Signed conversions
	 */
	testfmt("+2.500000e-01", "%+e", 0.25);
	testfmt("+0.000000", "%+F", 0.0);
	testfmt("-1", "%+g", -1.0);

	testfmt("-1.000000e+00", "% e", -1.0);
	testfmt("+1.000000", "% +f", 1.0);
	testfmt(" 1", "% g", 1.0);
	testfmt(" 0", "% g", 0.0);

	/*
	 * ``Alternate form''
	 */
	testfmt("1.250e+00", "%#.3e", 1.25);
	testfmt("123.000000", "%#f", 123.0);
	testfmt(" 12345.", "%#7.5g", 12345.0);
	testfmt(" 1.00000", "%#8g", 1.0);
	testfmt("0.0", "%#.2g", 0.0);

	/*
	 * Padding and decimal point placement
	 */
	testfmt("03.2E+00", "%08.1E", 3.25);
	testfmt("003.25", "%06.2F", 3.25);
	testfmt("0003.25", "%07.4G", 3.25);

	testfmt("3.14159e-05", "%g", 3.14159e-5);
	testfmt("0.000314159", "%g", 3.14159e-4);
	testfmt("3.14159e+06", "%g", 3.14159e6);
	testfmt("314159", "%g", 3.14159e5);
	testfmt("314159.", "%#g", 3.14159e5);

	testfmt(" 9.000000e+03", "%13e", 9000.0);
	testfmt(" 9000.000000", "%12f", 9000.0);
	testfmt(" 9000", "%5g", 9000.0);
	testfmt(" 900000.", "%#8g", 900000.0);
	testfmt(" 9e+06", "%6g", 9000000.0);
	testfmt(" 9.000000e-04", "%13e", 0.0009);
	testfmt(" 0.000900", "%9f", 0.0009);
	testfmt(" 0.0009", "%7g", 0.0009);
	testfmt(" 9e-05", "%6g", 0.00009);
	testfmt(" 9.00000e-05", "%#12g", 0.00009);
	testfmt(" 9.e-05", "%#7.1g", 0.00009);

	testfmt(" 0.0", "%4.1f", 0.0);
	testfmt("90.0", "%4.1f", 90.0);
	testfmt(" 100", "%4.0f", 100.0);
	testfmt("9.0e+01", "%4.1e", 90.0);
	testfmt("1e+02", "%4.0e", 100.0);

	/*
	 * Hexadecimal floating point (%a, %A) tests.  Some of these
	 * are only valid if the implementation converts to hex digits
	 * on nibble boundaries.
	 */
	testfmt("0x0p+0", "%a", 0x0.0p0);
	testfmt("0X0.P+0", "%#LA", 0x0.0p0L);
#ifdef NAN
	testfmt("inf", "%La", (long double)INFINITY);
	testfmt("+INF", "%+A", INFINITY);
	testfmt("nan", "%La", (long double)NAN);
	testfmt("NAN", "%A", NAN);
#endif /* NAN */

	testfmt(" 0x1.23p+0", "%10a", 0x1.23p0);
	testfmt(" 0x1.23p-500", "%12a", 0x1.23p-500);
	testfmt(" 0x1.2p+40", "%10.1a", 0x1.23p40);
	testfmt(" 0X1.230000000000000000000000P-4", "%32.24A", 0x1.23p-4);
	testfmt("0x1p-1074", "%a", 0x1p-1074);
	testfmt("0x1.2345p-1024", "%a", 0x1.2345p-1024);

	return (0);
}