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
23 #include
<clc
/clcmacro.h
>
26 #include
"sincos_helpers.h"
29 _CLC_DEF _CLC_OVERLOAD float __clc_tanpi
(float x
)
32 int xsgn
= ix
& 0x80000000;
33 int xnsgn
= xsgn ^
0x80000000;
35 float ax
= as_float
(ix);
38 int xodd
= xsgn ^
(iax & 0x1 ?
0x80000000 : 0);
40 // Initialize with return for
+-Inf and NaN
43 // 2^
24 <= |x|
< Inf
, the result is always even integer
44 ir
= ix
< 0x7f800000 ? xsgn
: ir
;
46 // 2^
23 <= |x|
< 2^
24, the result is always integer
47 ir
= ix
< 0x4b800000 ? xodd
: ir
;
49 // 0x1.0p-7
<= |x|
< 2^
23, result depends on which
0.25 interval
73 float t
= __clc_tanf_piby4
(a * M_PI_F
, 0);
74 float tr
= -native_recip
(t);
75 int jr
= s ^ as_int
(e ? tr
: t
);
77 jr
= r
== 0.5f ? xodd |
0x7f800000 : jr
;
79 ir
= ix
< 0x4b000000 ? jr
: ir
;
83 _CLC_UNARY_VECTORIZE
(_CLC_DEF _CLC_OVERLOAD
, float
, __clc_tanpi
, float
);
86 #include
"sincosD_piby4.h"
88 _CLC_DEF _CLC_OVERLOAD double __clc_tanpi
(double x
)
91 long xsgn
= ix
& 0x8000000000000000L
;
92 long xnsgn
= xsgn ^
0x8000000000000000L
;
94 double ax
= as_double
(ix);
97 long xodd
= xsgn ^
(iax & 0x1 ?
0x8000000000000000L
: 0L);
99 // Initialize with return for
+-Inf and NaN
100 long ir
= 0x7ff8000000000000L
;
102 // 2^
53 <= |x|
< Inf
, the result is always even integer
103 ir
= ix
< 0x7ff0000000000000L ? xsgn
: ir
;
105 // 2^
52 <= |x|
< 2^
53, the result is always integer
106 ir
= ix
< 0x4340000000000000L ? xodd
: ir
;
108 // 0x1.0p-14
<= |x|
< 2^
53, result depends on which
0.25 interval
134 double api
= a
* M_PI
;
135 double2 tt
= __clc_tan_piby4
(api, 0.0);
136 long jr
= s ^ as_long
(e ? tt.hi
: tt.lo
);
138 long si
= xodd |
0x7ff0000000000000L
;
139 jr
= r
== 0.5 ? si
: jr
;
141 ir
= ix
< 0x4330000000000000L ? jr
: ir
;
143 return as_double
(ir);
145 _CLC_UNARY_VECTORIZE
(_CLC_DEF _CLC_OVERLOAD
, double
, __clc_tanpi
, double
);