diff options
author | Yi Sun <yi.sun@intel.com> | 2014-03-10 11:32:12 +0800 |
---|---|---|
committer | Zhigang Gong <zhigang.gong@intel.com> | 2014-03-13 09:17:24 +0800 |
commit | 908e4a2f31f5590ce1a084be11ec2061287afee8 (patch) | |
tree | 15e56789d3f8d4802b9ed9037e3f7c9dcedd9bf8 /utests | |
parent | 394d5d42aae84ab09cd125e55a82809630caf60d (diff) |
utests: Refine cases for sinpi.
The general algorithm is that reducing the x to area [-0.5,0.5] then calculate results.
v2. Correct the algorithm of sinpi.
Add some input data temporarily, and we're going to design and implement a input data generator which is similar as what Conformance does.
Signed-off-by: Yi Sun <yi.sun@intel.com>
Reviewed-by: "Song, Ruiling" <ruiling.song@intel.com>
Diffstat (limited to 'utests')
-rwxr-xr-x | utests/utest_math_gen.py | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/utests/utest_math_gen.py b/utests/utest_math_gen.py index 20ae3f10..5a015adf 100755 --- a/utests/utest_math_gen.py +++ b/utests/utest_math_gen.py @@ -466,12 +466,45 @@ static float rsqrt(float x) sinhUtests = func('sinh','sinh',[sinh_input_type],sinh_output_type,[sinh_input_values],'4 * FLT_ULP') ##### gentype sinpi(gentype x) - sinpi_input_values = base_input_values + sinpi_input_values = [0, 1, 3.14, -0.88, -0.12, -0.5, 0.5, -0.49, 0.49, 0.51, -0.51, -0.1, 0.1] sinpi_input_type = ['float','float2','float4','float8','float16'] sinpi_output_type = ['float','float2','float4','float8','float16'] sinpi_cpu_func=''' +static float reduce1( float x ) +{ + SF fx, fy; + fx.f = fy.f = x; + int n; + + fy.spliter.exponent = fx.spliter.exponent - 1; + n = (int)fy.f; + + fx.f = fx.f - 2.0 * n; + + return fx.f; +} + static float sinpi(float x){ - return sin(M_PI*x); + float r = x; + if ( x > 1 || x < -1) r = reduce1(x); + + // reduce to [-0.5, 0.5] + if(r < -0.5) + r = -1 - r; + else if (r > 0.5) + r = 1 - r; + + if (r > 0.25 && r <= 0.5) + return cos((0.5 - r) * M_PI); + else if (r >= 0 && r <= 0.25) + return sin(r * M_PI); + else if (r >= -0.25 && r < 0) + return -sin(r * -M_PI); + else if (r >= -0.5 && r < -0.25){ + return -cos((0.5 + r) * M_PI);} + + // Error return + return 0xffffffff; } ''' sinpiUtests = func('sinpi','sinpi',[sinpi_input_type],sinpi_output_type,[sinpi_input_values],'4 * FLT_ULP',sinpi_cpu_func) |