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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/math/p_tan.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,38 +31,38 @@ static inline float __p_tan_pi_4(const float x)
}

/*
* pi/4 <= x <= pi/2
* 0 <= x <= pi/2
* 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.

return __p_tan_pi_4(x);
x_ = x - pi_4;
tanx_ = __p_tan_pi_4(x_);
return (tanx_ + 1.f) / (1.f - tanx_);
}

/*
* pi/2 <= x <= pi
* 0 <= x <= pi
* x = x' + pi/2
* tan x = tan (x' + pi/2) = - tan (pi/2 - x')
* tan x = tan (x' + pi/2) = -1 / tan x'
*/
static inline float __p_tan_pi(const float x)
{
float x_;
if (x <= pi_2)
return __p_tan_pi_2(x);
x_ = x - pi_2;
return -1.f * __p_tan_pi_2(pi_2 - x_);
return -1.f / __p_tan_pi_2(x_);
}

/* 0 <= x <= 2pi */
static inline float _p_tan(const float x)
{
if (x <= pi_4)
return __p_tan_pi_4(x);
else if (x <= pi_2)
return __p_tan_pi_2(x);
else if (x <= pi)
if (x <= pi)
return __p_tan_pi(x);
else
return __p_tan_pi(x - pi);
Expand Down
198 changes: 98 additions & 100 deletions tests/math/gold/p_tan_f32.dat
Original file line number Diff line number Diff line change
@@ -1,100 +1,98 @@
-0.107358,-0.049577,0.000000,-0.107772
0.051781,-0.265425,0.000000,0.051827
0.941475,-0.975603,0.000000,1.373483
-0.770979,-0.360797,0.000000,-0.971570
0.738044,-0.380252,0.000000,0.909509
0.608158,-0.123753,0.000000,0.696181
-0.066886,0.380368,0.000000,-0.066986
0.465099,0.210297,0.000000,0.501816
0.968926,0.910675,0.000000,1.455846
-0.207846,-0.573708,0.000000,-0.210892
-0.971535,-0.123731,0.000000,-1.464015
-0.782373,-0.992383,0.000000,-0.993968
0.682603,0.521601,0.000000,0.812976
-0.536897,0.615399,0.000000,-0.595219
-0.076406,-0.549893,0.000000,-0.076555
-0.683411,0.816236,0.000000,-0.814319
0.400530,0.368370,0.000000,0.423418
-0.449189,0.342005,0.000000,-0.482055
0.392768,-0.220168,0.000000,0.414294
0.981208,0.130812,0.000000,1.494859
0.399579,0.589365,0.000000,0.422297
-0.992941,-0.667307,0.000000,-1.533490
-0.030266,0.472158,0.000000,-0.030275
0.542991,-0.061340,0.000000,0.603503
0.382832,-0.664855,0.000000,0.402700
0.364952,0.411298,0.000000,0.382067
0.211414,0.582579,0.000000,0.214621
0.418914,-0.105983,0.000000,0.445271
0.104180,0.882017,0.000000,0.104559
-0.490584,-0.972226,0.000000,-0.534139
-0.667876,-0.173995,0.000000,-0.788803
0.844010,0.732653,0.000000,1.124674
-0.805625,-0.605179,0.000000,-1.041295
0.074658,0.587143,0.000000,0.074797
0.174653,0.055866,0.000000,0.176451
-0.282045,-0.425768,0.000000,-0.289770
-0.354768,-0.274987,0.000000,-0.370441
-0.093074,0.614965,0.000000,-0.093344
-0.802829,-0.550084,0.000000,-1.035484
-0.446374,0.580004,0.000000,-0.478591
-0.214939,0.918578,0.000000,-0.218311
-0.008699,0.996475,0.000000,-0.008699
0.501157,-0.589785,0.000000,0.547806
-0.109508,-0.394662,0.000000,-0.109948
-0.707768,0.399907,0.000000,-0.855655
-0.366888,-0.375644,0.000000,-0.384287
-0.774088,-0.522878,0.000000,-0.977632
-0.642991,-0.579713,0.000000,-0.749203
-0.128057,0.431668,0.000000,-0.128762
-0.992570,-0.953404,0.000000,-1.532247
-0.512466,-0.274615,0.000000,-0.562601
-0.379171,0.132765,0.000000,-0.398452
0.450398,0.527754,0.000000,0.483546
-0.252269,0.647569,0.000000,-0.257760
0.977671,0.301357,0.000000,1.483478
0.227573,-0.237268,0.000000,0.231585
0.219935,-0.781126,0.000000,0.223551
-0.240793,-0.278908,0.000000,-0.245557
-0.370910,0.649699,0.000000,-0.388910
0.326430,-0.078678,0.000000,0.338541
0.049606,0.959542,0.000000,0.049647
0.545678,0.275518,0.000000,0.607174
-0.563335,0.902687,0.000000,-0.631605
0.695806,0.308608,0.000000,0.835144
0.334355,0.703236,0.000000,0.347398
0.355204,0.821889,0.000000,0.370937
-0.571379,0.976033,0.000000,-0.642916
-0.045346,0.879019,0.000000,-0.045377
0.503788,0.702385,0.000000,0.551231
0.526589,0.481458,0.000000,0.581344
0.003741,-0.245838,0.000000,0.003741
-0.755809,-0.776324,0.000000,-0.942506
-0.026964,0.003398,0.000000,-0.026971
-0.055232,0.602126,0.000000,-0.055288
-0.346903,-0.728802,0.000000,-0.361523
-0.476552,0.702704,0.000000,-0.516236
-0.769260,-0.930874,0.000000,-0.968234
-0.021778,-0.332595,0.000000,-0.021781
0.971813,-0.325972,0.000000,1.464890
0.976013,0.306168,0.000000,1.478184
-0.622736,0.331217,0.000000,-0.718047
0.128056,-0.194115,0.000000,0.128761
0.307250,-0.917290,0.000000,0.317298
-0.315096,-0.188962,0.000000,-0.325956
0.785095,-0.788507,0.000000,0.999394
-0.707504,-0.211164,0.000000,-0.855198
-0.034345,-0.463313,0.000000,-0.034359
0.012512,0.938691,0.000000,0.012513
0.540085,0.957280,0.000000,0.599545
0.540816,-0.806818,0.000000,0.600539
-0.771522,-0.935736,0.000000,-0.972626
0.895886,-0.540781,0.000000,1.249566
-0.866610,-0.125892,0.000000,-1.177204
0.126623,-0.894797,0.000000,0.127304
0.548136,0.102636,0.000000,0.610543
0.411370,0.925400,0.000000,0.436261
-0.566147,-0.460574,0.000000,-0.635546
-0.268715,0.741103,0.000000,-0.275375
-0.377863,0.416189,0.000000,-0.396937
-0.447859,-0.592769,0.000000,-0.480417
0.000000,0.000000,0.000000,0.000000
0.062832,0.000000,0.000000,0.062915
0.125664,0.000000,0.000000,0.126329
0.188496,0.000000,0.000000,0.190760
0.251327,0.000000,0.000000,0.256756
0.314159,0.000000,0.000000,0.324920
0.376991,0.000000,0.000000,0.395928
0.439823,0.000000,0.000000,0.470564
0.502655,0.000000,0.000000,0.549755
0.565487,0.000000,0.000000,0.634619
0.628319,0.000000,0.000000,0.726543
0.691150,0.000000,0.000000,0.827272
0.753982,0.000000,0.000000,0.939063
0.816814,0.000000,0.000000,1.064892
0.879646,0.000000,0.000000,1.208792
0.942478,0.000000,0.000000,1.376382
1.005310,0.000000,0.000000,1.575748
1.068142,0.000000,0.000000,1.818993
1.130973,0.000000,0.000000,2.125108
1.193805,0.000000,0.000000,2.525712
1.256637,0.000000,0.000000,3.077684
1.319469,0.000000,0.000000,3.894743
1.382301,0.000000,0.000000,5.242184
1.445133,0.000000,0.000000,7.915815
1.507964,0.000000,0.000000,15.894545
1.633628,0.000000,0.000000,-15.894545
1.696460,0.000000,0.000000,-7.915815
1.759292,0.000000,0.000000,-5.242184
1.822124,0.000000,0.000000,-3.894743
1.884956,0.000000,0.000000,-3.077684
1.947787,0.000000,0.000000,-2.525712
2.010619,0.000000,0.000000,-2.125108
2.073451,0.000000,0.000000,-1.818993
2.136283,0.000000,0.000000,-1.575748
2.199115,0.000000,0.000000,-1.376382
2.261947,0.000000,0.000000,-1.208792
2.324779,0.000000,0.000000,-1.064892
2.387610,0.000000,0.000000,-0.939063
2.450442,0.000000,0.000000,-0.827272
2.513274,0.000000,0.000000,-0.726543
2.576106,0.000000,0.000000,-0.634619
2.638938,0.000000,0.000000,-0.549755
2.701770,0.000000,0.000000,-0.470564
2.764602,0.000000,0.000000,-0.395928
2.827433,0.000000,0.000000,-0.324920
2.890265,0.000000,0.000000,-0.256756
2.953097,0.000000,0.000000,-0.190760
3.015929,0.000000,0.000000,-0.126329
3.078761,0.000000,0.000000,-0.062915
3.141593,0.000000,0.000000,0.000000
3.204425,0.000000,0.000000,0.062915
3.267256,0.000000,0.000000,0.126329
3.330088,0.000000,0.000000,0.190760
3.392920,0.000000,0.000000,0.256756
3.455752,0.000000,0.000000,0.324920
3.518584,0.000000,0.000000,0.395928
3.581416,0.000000,0.000000,0.470564
3.644247,0.000000,0.000000,0.549755
3.707079,0.000000,0.000000,0.634619
3.769911,0.000000,0.000000,0.726543
3.832743,0.000000,0.000000,0.827272
3.895575,0.000000,0.000000,0.939063
3.958407,0.000000,0.000000,1.064892
4.021239,0.000000,0.000000,1.208792
4.084070,0.000000,0.000000,1.376382
4.146902,0.000000,0.000000,1.575748
4.209734,0.000000,0.000000,1.818993
4.272566,0.000000,0.000000,2.125108
4.335398,0.000000,0.000000,2.525712
4.398230,0.000000,0.000000,3.077684
4.461062,0.000000,0.000000,3.894743
4.523893,0.000000,0.000000,5.242184
4.586725,0.000000,0.000000,7.915815
4.649557,0.000000,0.000000,15.894545
4.775221,0.000000,0.000000,-15.894545
4.838053,0.000000,0.000000,-7.915815
4.900885,0.000000,0.000000,-5.242184
4.963716,0.000000,0.000000,-3.894743
5.026548,0.000000,0.000000,-3.077684
5.089380,0.000000,0.000000,-2.525712
5.152212,0.000000,0.000000,-2.125108
5.215044,0.000000,0.000000,-1.818993
5.277876,0.000000,0.000000,-1.575748
5.340708,0.000000,0.000000,-1.376382
5.403539,0.000000,0.000000,-1.208792
5.466371,0.000000,0.000000,-1.064892
5.529203,0.000000,0.000000,-0.939063
5.592035,0.000000,0.000000,-0.827272
5.654867,0.000000,0.000000,-0.726543
5.717699,0.000000,0.000000,-0.634619
5.780530,0.000000,0.000000,-0.549755
5.843362,0.000000,0.000000,-0.470564
5.906194,0.000000,0.000000,-0.395928
5.969026,0.000000,0.000000,-0.324920
6.031858,0.000000,0.000000,-0.256756
6.094690,0.000000,0.000000,-0.190760
6.157522,0.000000,0.000000,-0.126329
6.220353,0.000000,0.000000,-0.062915