Changeset View
Changeset View
Standalone View
Standalone View
lib/libc/tests/stdio/printfloat_test.c
Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | |||||
#include <atf-c.h> | #include <atf-c.h> | ||||
static void | static void | ||||
smash_stack(void) | smash_stack(void) | ||||
{ | { | ||||
static uint32_t junk = 0xdeadbeef; | static uint32_t junk = 0xdeadbeef; | ||||
uint32_t buf[512]; | uint32_t buf[512]; | ||||
int i; | size_t i; | ||||
for (i = 0; i < sizeof(buf) / sizeof(buf[0]); i++) | for (i = 0; i < sizeof(buf) / sizeof(buf[0]); i++) | ||||
buf[i] = junk; | buf[i] = junk; | ||||
} | } | ||||
#define testfmt(result, fmt, ...) \ | #define testfmt(result, fmt, ...) \ | ||||
_testfmt((result), #__VA_ARGS__, fmt, __VA_ARGS__) | _testfmt((result), #__VA_ARGS__, fmt, __VA_ARGS__) | ||||
static void | static void | ||||
▲ Show 20 Lines • Show All 303 Lines • ▼ Show 20 Lines | ATF_TC_BODY(hexadecimal_rounding, tc) | ||||
testfmt("0x1.23456p+0", "%.5a", 0x1.23456789abcdep0); | testfmt("0x1.23456p+0", "%.5a", 0x1.23456789abcdep0); | ||||
testfmt("0x1.234568p+0", "%.6a", 0x1.23456789abcdep0); | testfmt("0x1.234568p+0", "%.6a", 0x1.23456789abcdep0); | ||||
testfmt("-0x1.234567p+0", "%.6a", -0x1.23456689abcdep0); | testfmt("-0x1.234567p+0", "%.6a", -0x1.23456689abcdep0); | ||||
testfmt("0x1.00p-1029", "%.2a", 0x1.fffp-1030); | testfmt("0x1.00p-1029", "%.2a", 0x1.fffp-1030); | ||||
testfmt("0x1.00p-1026", "%.2a", 0xf.fffp-1030); | testfmt("0x1.00p-1026", "%.2a", 0xf.fffp-1030); | ||||
testfmt("0x1.83p+0", "%.2a", 1.51); | testfmt("0x1.83p+0", "%.2a", 1.51); | ||||
} | } | ||||
ATF_TC_WITHOUT_HEAD(subnormal_double); | |||||
ATF_TC_BODY(subnormal_double, tc) | |||||
{ | |||||
/* Regression test for https://bugs.freebsd.org/253847 */ | |||||
double positive = __DBL_DENORM_MIN__; | |||||
testfmt("4.9406564584124654418e-324", "%20.20g", positive); | |||||
testfmt("4.9406564584124654418E-324", "%20.20G", positive); | |||||
testfmt("0x1p-1074", "%a", positive); | |||||
testfmt("0X1P-1074", "%A", positive); | |||||
double negative = -__DBL_DENORM_MIN__; | |||||
testfmt("-4.9406564584124654418e-324", "%20.20g", negative); | |||||
testfmt("-4.9406564584124654418E-324", "%20.20G", negative); | |||||
testfmt("-0x1p-1074", "%a", negative); | |||||
testfmt("-0X1P-1074", "%A", negative); | |||||
} | |||||
ATF_TC_WITHOUT_HEAD(subnormal_float); | |||||
ATF_TC_BODY(subnormal_float, tc) | |||||
{ | |||||
float positive = __FLT_DENORM_MIN__; | |||||
testfmt("1.4012984643248170709e-45", "%20.20g", positive); | |||||
testfmt("1.4012984643248170709E-45", "%20.20G", positive); | |||||
testfmt("0x1p-149", "%a", positive); | |||||
testfmt("0X1P-149", "%A", positive); | |||||
float negative = -__FLT_DENORM_MIN__; | |||||
testfmt("-1.4012984643248170709e-45", "%20.20g", negative); | |||||
testfmt("-1.4012984643248170709E-45", "%20.20G", negative); | |||||
testfmt("-0x1p-149", "%a", negative); | |||||
testfmt("-0X1P-149", "%A", negative); | |||||
} | |||||
ATF_TP_ADD_TCS(tp) | ATF_TP_ADD_TCS(tp) | ||||
{ | { | ||||
ATF_TP_ADD_TC(tp, float_within_limits); | ATF_TP_ADD_TC(tp, float_within_limits); | ||||
ATF_TP_ADD_TC(tp, infinities_and_nans); | ATF_TP_ADD_TC(tp, infinities_and_nans); | ||||
ATF_TP_ADD_TC(tp, padding); | ATF_TP_ADD_TC(tp, padding); | ||||
ATF_TP_ADD_TC(tp, precision_specifiers); | ATF_TP_ADD_TC(tp, precision_specifiers); | ||||
ATF_TP_ADD_TC(tp, thousands_separator_and_other_locale_tests); | ATF_TP_ADD_TC(tp, thousands_separator_and_other_locale_tests); | ||||
ATF_TP_ADD_TC(tp, signed_conversions); | ATF_TP_ADD_TC(tp, signed_conversions); | ||||
ATF_TP_ADD_TC(tp, alternate_form); | ATF_TP_ADD_TC(tp, alternate_form); | ||||
ATF_TP_ADD_TC(tp, padding_and_decimal_point_placement); | ATF_TP_ADD_TC(tp, padding_and_decimal_point_placement); | ||||
ATF_TP_ADD_TC(tp, decimal_rounding); | ATF_TP_ADD_TC(tp, decimal_rounding); | ||||
ATF_TP_ADD_TC(tp, hexadecimal_floating_point); | ATF_TP_ADD_TC(tp, hexadecimal_floating_point); | ||||
ATF_TP_ADD_TC(tp, hexadecimal_rounding); | ATF_TP_ADD_TC(tp, hexadecimal_rounding); | ||||
ATF_TP_ADD_TC(tp, subnormal_double); | |||||
ATF_TP_ADD_TC(tp, subnormal_float); | |||||
return (atf_no_error()); | return (atf_no_error()); | ||||
} | } |