Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libc: add tests for functions from math.h #210

Closed
wants to merge 2 commits into from

Conversation

mateusz-bloch
Copy link
Member

@mateusz-bloch mateusz-bloch commented May 24, 2023

JIRA CI-277
The pull request will be closed and replaced with: #237

Description

Motivation and Context

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

How Has This Been Tested?

  • Already covered by automatic testing.
  • New test added: (add PR link here).
  • Tested by hand on: (list targets here).

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing linter checks and tests passed.
  • My changes generate no new compilation warnings for any of the targets.

Special treatment

  • This PR needs additional PRs to work (list the PRs, preferably in merge-order).
  • I will merge this PR by myself when appropriate.

@mateusz-bloch mateusz-bloch changed the title libc: add functions from math.h tests libc: add tests for functions from math.h May 24, 2023
@mateusz-bloch mateusz-bloch force-pushed the mateusz-bloch/libc_math.h_tests branch 10 times, most recently from e351fda to afcc1c1 Compare July 7, 2023 10:21
@mateusz-bloch mateusz-bloch force-pushed the mateusz-bloch/libc_math.h_tests branch 4 times, most recently from f2098c4 to e1fc824 Compare July 10, 2023 16:18
@mateusz-bloch mateusz-bloch marked this pull request as ready for review July 10, 2023 16:27
@mateusz-bloch mateusz-bloch marked this pull request as draft July 10, 2023 16:27
@mateusz-bloch mateusz-bloch force-pushed the mateusz-bloch/libc_math.h_tests branch from e1fc824 to 4474cb6 Compare July 14, 2023 15:24
Copy link
Contributor

@adamdebek adamdebek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All basic tests should be replaced with test that will span over whole double range.

libc/math/math.c Outdated Show resolved Hide resolved
libc/Makefile Outdated Show resolved Hide resolved
libc/math/math.c Outdated Show resolved Hide resolved
libc/math/math.c Outdated Show resolved Hide resolved
libc/math/math.c Outdated
Comment on lines 188 to 194
/* to discuss */
// errno = 0;
TEST_ASSERT_DOUBLE_IS_NAN(fmod(1, 0.0));
// TEST_ASSERT_EQUAL_INT(EDOM, errno);

// errno = 0;
TEST_ASSERT_DOUBLE_IS_NAN(fmod(INFINITY, 1));
// TEST_ASSERT_EQUAL_INT(EDOM, errno);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be discussed during the meeting , I think if toolchains support IEC 60559 floating point arithmetic then it should be tested.

libc/math/math.c Outdated
}


TEST(math_mod, fmod_special_cond)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also add testcase when y is so smallest than epsilon for x.

libc/math/math.c Outdated Show resolved Hide resolved
libc/math/math.c Outdated Show resolved Hide resolved
@mateusz-bloch mateusz-bloch force-pushed the mateusz-bloch/libc_math.h_tests branch 5 times, most recently from ea80603 to 5a9f4ff Compare July 26, 2023 09:51
…rewritten

libc: add math.h tests

JIRA CI-277
@mateusz-bloch mateusz-bloch force-pushed the mateusz-bloch/libc_math.h_tests branch from 5a9f4ff to fc784bd Compare July 26, 2023 10:03
Comment on lines +29 to +41
#define M_SQRT3 1.73205080756887719318
#define DELTA 1e-05


static double dblSubnormal(void)
{
union {
double doubleValue;
uint64_t integerValue;
} representation;
representation.integerValue = 0x000fffffffffffffULL;
return representation.doubleValue;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be redundant since it was only used in basic tests.

Comment on lines +58 to +72
TEST(math_trig, tan_basic)
{
int i;
int iterates = 2000;
double start = -DBL_MAX;
double end = DBL_MAX;
double step = (end - start) / (iterates - 1);
double x, y;

for (i = 0; i <= iterates; i++) {
x = start + i * step;
y = tan(x / 2.0);
TEST_ASSERT_EQUAL_DOUBLE(tan(x), (2.0 * y) / (1.0 + y * y));
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will take care of basic testcases.


TEST(math_trig, tan_special_cond)
{
TEST_ASSERT_DOUBLE_IS_NAN(tan(NAN));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tan() with NAN shouldn' t be tested since we don't support IEC 60559

TEST_ASSERT_EQUAL_DOUBLE(0, tan(0.0));
TEST_ASSERT_EQUAL_DOUBLE(0, tan(-0.0));

TEST_ASSERT_EQUAL_DOUBLE(dblSubnormal(), tan(dblSubnormal()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Subnormal values will be tested in basic tests.

Comment on lines +106 to +119
TEST(math_trig, atan_basic)
{
int i;
int iterates = 2000;
double start = -1.0;
double end = 1.0;
double step = (end - start) / (iterates - 1);
double x;

for (i = 0; i <= iterates; i++) {
x = start + i * step;
TEST_ASSERT_EQUAL_DOUBLE(x, tan(atan(x)));
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above.

TEST_ASSERT_EQUAL_DOUBLE(1, cosh(1.0e-6));
TEST_ASSERT_EQUAL_DOUBLE(1, cosh(-1.0e-6));

TEST_ASSERT_EQUAL_DOUBLE(1, cosh(DBL_MIN));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DBL_MIN shouldn't be tested, it is not standardized that it should return 1.0 .

Comment on lines +443 to +454
TEST(math_hyper, sinh_huge_x)
{
TEST_ASSERT_EQUAL_DOUBLE(HUGE_VAL, sinh(1.0e+6));
TEST_ASSERT_EQUAL_DOUBLE(-HUGE_VAL, sinh(-1.0e+6));

TEST_ASSERT_DOUBLE_WITHIN(DELTA, 1e-06, sinh(1.0e-6));
TEST_ASSERT_DOUBLE_WITHIN(DELTA, -1e-06, sinh(-1.0e-6));


// TEST_ASSERT_EQUAL_DOUBLE(DBL_MIN, sinh(DBL_MIN));
TEST_ASSERT_EQUAL_DOUBLE(HUGE_VAL, sinh(DBL_MAX));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as cosh().

Comment on lines +396 to +409
TEST(math_hyper, tanh_huge_x)
{
// TEST_ASSERT_EQUAL_DOUBLE(1, tanh(1.0e+6));
// TEST_ASSERT_EQUAL_DOUBLE(-1, tanh(-1.0e+6));

// TEST_ASSERT_EQUAL_DOUBLE(1e-10, tanh(1.0e-10)); // Sprawdź do którego bitu ma być uwzględnione
// TEST_ASSERT_EQUAL_DOUBLE(-1e-10, tanh(-1.0e-10)); // Sprawdź do którego bitu ma być uwzględnione

// TEST_ASSERT_EQUAL_DOUBLE(1, tanh(INT_MAX));
// TEST_ASSERT_EQUAL_DOUBLE(-1, tanh(INT_MIN));

// TEST_ASSERT_EQUAL_DOUBLE(1, tanh(DBL_MAX));
// TEST_ASSERT_EQUAL_DOUBLE(DBL_MIN, tanh(DBL_MIN));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as other hyper functions.


TEST(math_hyper, tanh_special_cond)
{
// TEST_ASSERT_EQUAL_DOUBLE(NAN, tanh(NAN)); IMX, ZYNQ-QEMU
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't check NAN since we don't support IEC 60559.

// TEST_ASSERT_EQUAL_DOUBLE(1, tanh(INFINITY));
// TEST_ASSERT_EQUAL_DOUBLE(-1, tanh(-INFINITY));

// TEST_ASSERT_EQUAL_DOUBLE(dblSubnormal(), tanh(dblSubnormal()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Subnormal will be tested in basic tests.

@mateusz-bloch mateusz-bloch deleted the mateusz-bloch/libc_math.h_tests branch January 31, 2024 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants