-
Notifications
You must be signed in to change notification settings - Fork 18
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
Conversation
e351fda
to
afcc1c1
Compare
f2098c4
to
e1fc824
Compare
e1fc824
to
4474cb6
Compare
There was a problem hiding this 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
/* 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); |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
ea80603
to
5a9f4ff
Compare
…rewritten libc: add math.h tests JIRA CI-277
5a9f4ff
to
fc784bd
Compare
#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; | ||
} |
There was a problem hiding this comment.
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.
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)); | ||
} | ||
} |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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())); |
There was a problem hiding this comment.
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.
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))); | ||
} | ||
} |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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 .
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)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as cosh().
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)); | ||
} |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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())); |
There was a problem hiding this comment.
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.
JIRA CI-277
The pull request will be closed and replaced with: #237
Description
Motivation and Context
Types of changes
How Has This Been Tested?
Checklist:
Special treatment