2 * Copyright (c) 2014 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 #include <clc/math/clc_mad.h>
24 // Evaluate single precisions in and cos of value in interval [-pi/4, pi/4]
25 _CLC_INLINE float2
__libclc__sincosf_piby4(float x
) {
26 // Taylor series for sin(x) is x - x^3/3! + x^5/5! - x^7/7! ...
27 // = x * (1 - x^2/3! + x^4/5! - x^6/7! ...
29 // where w = x*x and f(w) = (1 - w/3! + w^2/5! - w^3/7! ...
30 // We use a minimax approximation of (f(w) - 1) / w
31 // because this produces an expansion in even powers of x.
33 // Taylor series for cos(x) is 1 - x^2/2! + x^4/4! - x^6/6! ...
35 // where w = x*x and f(w) = (1 - w/2! + w^2/4! - w^3/6! ...
36 // We use a minimax approximation of (f(w) - 1 + w/2) / (w*w)
37 // because this produces an expansion in even powers of x.
39 const float sc1
= -0.166666666638608441788607926e0F
;
40 const float sc2
= 0.833333187633086262120839299e-2F
;
41 const float sc3
= -0.198400874359527693921333720e-3F
;
42 const float sc4
= 0.272500015145584081596826911e-5F
;
44 const float cc1
= 0.41666666664325175238031e-1F
;
45 const float cc2
= -0.13888887673175665567647e-2F
;
46 const float cc3
= 0.24800600878112441958053e-4F
;
47 const float cc4
= -0.27301013343179832472841e-6F
;
53 x
* x2
, __clc_mad(x2
, __clc_mad(x2
, __clc_mad(x2
, sc4
, sc3
), sc2
), sc1
),
56 x2
* x2
, __clc_mad(x2
, __clc_mad(x2
, __clc_mad(x2
, cc4
, cc3
), cc2
), cc1
),
57 __clc_mad(x2
, -0.5f
, 1.0f
));