stdlib: add tests for strtod, strtof and atof

This commit is contained in:
Lephenixnoir 2021-05-21 23:52:08 +02:00
parent f7be1f758f
commit 65979454ba
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
1 changed files with 30 additions and 4 deletions

View File

@ -77,11 +77,12 @@ static void _ft_stdlib_fpconv(ft_test *t)
assert_end("73.e2f", 5);
assert_end(" 73E+2+1", 7);
assert_end(" -1e5", 6);
assert_end("nan(120)+3", 8);
assert_end("", 0);
ft_log(t, "\nInfinity and NaN:\n");
assert_conv("inf", __builtin_infl());
assert_conv("-inFiNiTY", -__builtin_infl());
assert_conv("inf", HUGE_VALL);
assert_conv("-inFiNiTY", -HUGE_VALL);
ft_assert(t, isnan(strtold("+NAN", NULL)));
ft_assert(t, isnan(strtold("-nan", NULL)));
ft_assert(t, isnan(strtold("NaN(57)", NULL)));
@ -119,9 +120,34 @@ static void _ft_stdlib_fpconv(ft_test *t)
ft_log(t, "\nHexadecimal notation:\n");
assert_conv("0xa47b.3f85p12", 0xa47b.3f85p12);
// ft_log(t, "\nConversion to double:\n");
#undef func
#undef format
#define func strtod
#define format "l"
// ft_log(t, "\nConversion to float:\n");
ft_log(t, "\n--- strtod ---\n");
ft_log(t, "\nConversion to double:\n");
assert_conv(" -0.73e2", -73.0);
assert_conv("-inf", -HUGE_VAL);
ft_assert(t, atof("+37.5") == 37.5);
assert_errno("1e308", 0);
assert_errno("1e309", ERANGE);
ft_assert(t, isnan(strtod("nan", NULL)));
#undef func
#undef format
#define func strtof
#define format ""
ft_log(t, "\n--- strtof ---\n");
ft_log(t, "\nConversion to float:\n");
assert_conv(" -0.73e2", -73.0f);
assert_conv("+inf", HUGE_VALF);
assert_errno("1e38", 0);
assert_errno("1e39", ERANGE);
ft_assert(t, isnan(strtof("nan", NULL)));
}
ft_test ft_stdlib_fpconv = {