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

math:tan: Generate unit testing data on [0, 2pi] #190

Merged
merged 3 commits into from
Jul 8, 2015
Merged

math:tan: Generate unit testing data on [0, 2pi] #190

merged 3 commits into from
Jul 8, 2015

Conversation

mansourmoufid
Copy link
Contributor

Hi,

I noticed the unit testing data (gold) for the tangent function seems to be bound to [-1, 1] but it should be bound to [0, 2pi]. (This was mentioned in #166.) So I generated new data.

Ironically, my tangent implementation had a couple bugs, but produced good results with the bad data...

I generated the new data in Python:

>>> import math
>>> n = 100
>>> x = [2.0 * math.pi / n * i for i in range(n)]
>>> data = [(a, 0.0, 0.0, math.tan(a)) for a in x]
>>> for (a, b, c, d) in data:
...     print("{:.6f},{:.6f},{:.6f},{:.6f}".format(a, b, c, d))

I removed two lines for input close to a multiple of pi/2 since they produce garbage (+/- infinity).

This new data helped me fix two bugs.

The input should be bound to [0, 2pi].

Signed-off-by: Mansour Moufid <[email protected]>
Signed-off-by: Mansour Moufid <[email protected]>
* x = x' + pi/4
* tan x = tan(x' + pi/4) = (tan x' + 1) / (1 - tan x')
*/
static inline float __p_tan_pi_2(const float x)
{
float x_, tanx_;
if (x <= pi_4)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use #defines from pal_math.h, eg. M_PI_4

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On platforms with math.h, M_PI_4 and other constants are defined with type double. When you mix single and double floating-point arithmetic the compiler produces much slower code.

aolofsson added a commit that referenced this pull request Jul 8, 2015
math:tan: Generate unit testing data on [0, 2pi]
@aolofsson aolofsson merged commit 014d34e into parallella:master Jul 8, 2015
@mansourmoufid mansourmoufid deleted the tan-gold branch July 8, 2015 13:12
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.

3 participants