libc/math: Update testcases for pow() and log()
Update testcase for pow() to input specific value which leads to
system hang.
Add testcases for log() to cover corner cases.
@@ -2026,6 +2026,32 @@ static void tc_libc_math_ldexpl(void)
TC_SUCCESS_RESULT();
}
+/**
+ * @fn :tc_libc_math_log
+ * @brief :Returns the natural (base-e) logarithm of x
+ * @Scenario :Returns the natural (base-e) logarithm of x
+ * API's covered :log
+ * Preconditions :None
+ * Postconditions :None
+ * @return :void
+ */
+static void tc_libc_math_log(void)
+{
+ const double in_val[] = { 1024, 5.5, -10.0, 0.936584472656250 };
+ const double sol_val[] = { 6.931471805599453, 1.704748092238425, NAN, -0.065515560785398 };
+ double ret_val[SIZE(sol_val, double)];
+ int log_idx;
+
+ /* Returns the natural (base-e) logarithm of x */
+
+ for (log_idx = 0; log_idx < SIZE(sol_val, double); log_idx++) {
+ ret_val[log_idx] = log(in_val[log_idx]);
+ TC_ASSERT_LEQ("log", fabs(sol_val[log_idx] - ret_val[log_idx]), FLT_EPSILON);
+ }
+
+ TC_SUCCESS_RESULT();
+}
+
/**
* @fn :tc_libc_math_log2
* @brief :Returns the binary (base-2) logarithm of x
@@ -2357,8 +2383,8 @@ static void tc_libc_math_nexttowardl(void)
*/
static void tc_libc_math_pow(void)
{
- const double in_val[][2] = { { 2, 2 }, { 2, 0.5 }, { 2, -2 }, { 2, -0.5 }, { 1, NAN }, { ZERO, 0.5 }, { ZERO, -2 }, { -ZERO, -1 }, { -ZERO, -2 }, { -2, -1 }, { -2, -2 }, { 0.5, INFINITY }, { 2, INFINITY } };
- const double sol_val[] = { 4.0, M_SQRT2, 0.25, M_SQRT1_2, 1, ZERO, INFINITY, -INFINITY, INFINITY, -0.5, 0.25, ZERO, INFINITY };
+ const double in_val[][2] = { { 2, 2 }, { 2, 0.5 }, { 2, -2 }, { 2, -0.5 }, { 1, NAN }, { ZERO, 0.5 }, { ZERO, -2 }, { -ZERO, -1 }, { -ZERO, -2 }, { -2, -1 }, { -2, -2 }, { 0.5, INFINITY }, { 2, INFINITY }, {-0.936584472656250,2} };
+ const double sol_val[] = { 4.0, M_SQRT2, 0.25, M_SQRT1_2, 1, ZERO, INFINITY, -INFINITY, INFINITY, -0.5, 0.25, ZERO, INFINITY, 0.877190474420786 };
double ret_val[SIZE(sol_val, double)];
int pow_idx;
@@ -3533,6 +3559,7 @@ int libc_math_main(void)
tc_libc_math_ldexpf();
tc_libc_math_ldexpl();
tc_libc_math_lgamma();
+ tc_libc_math_log();
tc_libc_math_log2();
tc_libc_math_log2f();
tc_libc_math_log2l();
