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
25 _CLC_OVERLOAD _CLC_DEF float normalize
(float p
) {
29 _CLC_OVERLOAD _CLC_DEF float2 normalize
(float2 p
) {
30 if
(all(p == (float2)0.0F
))
38 } else if
(l2 == INFINITY
) {
42 p
= copysign
(select((float2)0.0F
, (float2)1.0F
, isinf
(p)), p
);
49 _CLC_OVERLOAD _CLC_DEF float3 normalize
(float3 p
) {
50 if
(all(p == (float3)0.0F
))
58 } else if
(l2 == INFINITY
) {
62 p
= copysign
(select((float3)0.0F
, (float3)1.0F
, isinf
(p)), p
);
69 _CLC_OVERLOAD _CLC_DEF float4 normalize
(float4 p
) {
70 if
(all(p == (float4)0.0F
))
78 } else if
(l2 == INFINITY
) {
82 p
= copysign
(select((float4)0.0F
, (float4)1.0F
, isinf
(p)), p
);
91 #pragma OPENCL EXTENSION cl_khr_fp64
: enable
93 _CLC_OVERLOAD _CLC_DEF double normalize
(double p
) {
97 _CLC_OVERLOAD _CLC_DEF double2 normalize
(double2 p
) {
98 if
(all(p == (double2)0.0))
101 double l2
= dot
(p, p
);
106 } else if
(l2 == INFINITY
) {
109 if
(l2 == INFINITY
) {
110 p
= copysign
(select((double2)0.0, (double2)1.0, isinf
(p)), p
);
114 return p
* rsqrt
(l2);
117 _CLC_OVERLOAD _CLC_DEF double3 normalize
(double3 p
) {
118 if
(all(p == (double3)0.0))
121 double l2
= dot
(p, p
);
126 } else if
(l2 == INFINITY
) {
129 if
(l2 == INFINITY
) {
130 p
= copysign
(select((double3)0.0, (double3)1.0, isinf
(p)), p
);
134 return p
* rsqrt
(l2);
137 _CLC_OVERLOAD _CLC_DEF double4 normalize
(double4 p
) {
138 if
(all(p == (double4)0.0))
141 double l2
= dot
(p, p
);
146 } else if
(l2 == INFINITY
) {
149 if
(l2 == INFINITY
) {
150 p
= copysign
(select((double4)0.0, (double4)1.0, isinf
(p)), p
);
154 return p
* rsqrt
(l2);