15 #ifndef CORE_GPU_HELPER_MATH_DOUBLE_H_
16 #define CORE_GPU_HELPER_MATH_DOUBLE_H_
24 inline __device__
real_t rsqrtf(
real_t x) {
return 1.0f / sqrtf(x); }
30 inline __device__ real_t2 make_real_t2(
real_t s) {
return make_real_t2(s, s); }
31 inline __device__ real_t2 make_real_t2(real_t3 a) {
32 return make_real_t2(a.x, a.y);
34 inline __device__ real_t2 make_real_t2(int2 a) {
37 inline __device__ real_t2 make_real_t2(uint2 a) {
41 inline __device__ int2 make_int2(real_t2 a) {
42 return make_int2(
int(a.x),
int(a.y));
45 inline __device__ real_t3 make_real_t3(
real_t s) {
46 return make_real_t3(s, s, s);
48 inline __device__ real_t3 make_real_t3(real_t2 a) {
49 return make_real_t3(a.x, a.y, 0.0f);
51 inline __device__ real_t3 make_real_t3(real_t2 a,
real_t s) {
52 return make_real_t3(a.x, a.y, s);
54 inline __device__ real_t3 make_real_t3(real_t4 a) {
55 return make_real_t3(a.x, a.y, a.z);
57 inline __device__ real_t3 make_real_t3(int3 a) {
60 inline __device__ real_t3 make_real_t3(uint3 a) {
64 inline __device__ int3 make_int3(real_t3 a) {
65 return make_int3(
int(a.x),
int(a.y),
int(a.z));
68 inline __device__ real_t4 make_real_t4(
real_t s) {
69 return make_real_t4(s, s, s, s);
71 inline __device__ real_t4 make_real_t4(real_t3 a) {
72 return make_real_t4(a.x, a.y, a.z, 0.0f);
74 inline __device__ real_t4 make_real_t4(real_t3 a,
real_t w) {
75 return make_real_t4(a.x, a.y, a.z, w);
77 inline __device__ real_t4 make_real_t4(int4 a) {
80 inline __device__ real_t4 make_real_t4(uint4 a) {
84 inline __device__ int4 make_int4(real_t4 a) {
85 return make_int4(
int(a.x),
int(a.y),
int(a.z),
int(a.w));
92 inline __device__ real_t2 operator-(real_t2 &a) {
93 return make_real_t2(-a.x, -a.y);
95 inline __device__ real_t3 operator-(real_t3 &a) {
96 return make_real_t3(-a.x, -a.y, -a.z);
98 inline __device__ real_t4 operator-(real_t4 &a) {
99 return make_real_t4(-a.x, -a.y, -a.z, -a.w);
106 inline __device__ real_t2 operator+(real_t2 a, real_t2 b) {
107 return make_real_t2(a.x + b.x, a.y + b.y);
109 inline __device__
void operator+=(real_t2 &a, real_t2 b) {
113 inline __device__ real_t2 operator+(real_t2 a,
real_t b) {
114 return make_real_t2(a.x + b, a.y + b);
116 inline __device__ real_t2 operator+(
real_t b, real_t2 a) {
117 return make_real_t2(a.x + b, a.y + b);
119 inline __device__
void operator+=(real_t2 &a,
real_t b) {
124 inline __device__ real_t3 operator+(real_t3 a, real_t3 b) {
125 return make_real_t3(a.x + b.x, a.y + b.y, a.z + b.z);
127 inline __device__
void operator+=(real_t3 &a, real_t3 b) {
132 inline __device__ real_t3 operator+(real_t3 a,
real_t b) {
133 return make_real_t3(a.x + b, a.y + b, a.z + b);
135 inline __device__
void operator+=(real_t3 &a,
real_t b) {
141 inline __device__ real_t3 operator+(
real_t b, real_t3 a) {
142 return make_real_t3(a.x + b, a.y + b, a.z + b);
145 inline __device__ real_t4 operator+(real_t4 a, real_t4 b) {
146 return make_real_t4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
148 inline __device__
void operator+=(real_t4 &a, real_t4 b) {
154 inline __device__ real_t4 operator+(real_t4 a,
real_t b) {
155 return make_real_t4(a.x + b, a.y + b, a.z + b, a.w + b);
157 inline __device__ real_t4 operator+(
real_t b, real_t4 a) {
158 return make_real_t4(a.x + b, a.y + b, a.z + b, a.w + b);
160 inline __device__
void operator+=(real_t4 &a,
real_t b) {
171 inline __device__ real_t2 operator-(real_t2 a, real_t2 b) {
172 return make_real_t2(a.x - b.x, a.y - b.y);
174 inline __device__
void operator-=(real_t2 &a, real_t2 b) {
178 inline __device__ real_t2 operator-(real_t2 a,
real_t b) {
179 return make_real_t2(a.x - b, a.y - b);
181 inline __device__ real_t2 operator-(
real_t b, real_t2 a) {
182 return make_real_t2(b - a.x, b - a.y);
184 inline __device__
void operator-=(real_t2 &a,
real_t b) {
189 inline __device__ real_t3 operator-(real_t3 a, real_t3 b) {
190 return make_real_t3(a.x - b.x, a.y - b.y, a.z - b.z);
192 inline __device__
void operator-=(real_t3 &a, real_t3 b) {
197 inline __device__ real_t3 operator-(real_t3 a,
real_t b) {
198 return make_real_t3(a.x - b, a.y - b, a.z - b);
200 inline __device__ real_t3 operator-(
real_t b, real_t3 a) {
201 return make_real_t3(b - a.x, b - a.y, b - a.z);
203 inline __device__
void operator-=(real_t3 &a,
real_t b) {
209 inline __device__ real_t4 operator-(real_t4 a, real_t4 b) {
210 return make_real_t4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
212 inline __device__
void operator-=(real_t4 &a, real_t4 b) {
218 inline __device__ real_t4 operator-(real_t4 a,
real_t b) {
219 return make_real_t4(a.x - b, a.y - b, a.z - b, a.w - b);
221 inline __device__
void operator-=(real_t4 &a,
real_t b) {
232 inline __device__ real_t2
operator*(real_t2 a, real_t2 b) {
233 return make_real_t2(a.x * b.x, a.y * b.y);
235 inline __device__
void operator*=(real_t2 &a, real_t2 b) {
240 return make_real_t2(a.x * b, a.y * b);
243 return make_real_t2(b * a.x, b * a.y);
245 inline __device__
void operator*=(real_t2 &a,
real_t b) {
250 inline __device__ real_t3
operator*(real_t3 a, real_t3 b) {
251 return make_real_t3(a.x * b.x, a.y * b.y, a.z * b.z);
253 inline __device__
void operator*=(real_t3 &a, real_t3 b) {
259 return make_real_t3(a.x * b, a.y * b, a.z * b);
262 return make_real_t3(b * a.x, b * a.y, b * a.z);
264 inline __device__
void operator*=(real_t3 &a,
real_t b) {
270 inline __device__ real_t4
operator*(real_t4 a, real_t4 b) {
271 return make_real_t4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w);
273 inline __device__
void operator*=(real_t4 &a, real_t4 b) {
280 return make_real_t4(a.x * b, a.y * b, a.z * b, a.w * b);
283 return make_real_t4(b * a.x, b * a.y, b * a.z, b * a.w);
285 inline __device__
void operator*=(real_t4 &a,
real_t b) {
296 inline __device__ real_t2 operator/(real_t2 a, real_t2 b) {
297 return make_real_t2(a.x / b.x, a.y / b.y);
299 inline __device__
void operator/=(real_t2 &a, real_t2 b) {
303 inline __device__ real_t2 operator/(real_t2 a,
real_t b) {
304 return make_real_t2(a.x / b, a.y / b);
306 inline __device__
void operator/=(real_t2 &a,
real_t b) {
310 inline __device__ real_t2 operator/(
real_t b, real_t2 a) {
311 return make_real_t2(b / a.x, b / a.y);
314 inline __device__ real_t3 operator/(real_t3 a, real_t3 b) {
315 return make_real_t3(a.x / b.x, a.y / b.y, a.z / b.z);
317 inline __device__
void operator/=(real_t3 &a, real_t3 b) {
322 inline __device__ real_t3 operator/(real_t3 a,
real_t b) {
323 return make_real_t3(a.x / b, a.y / b, a.z / b);
325 inline __device__
void operator/=(real_t3 &a,
real_t b) {
330 inline __device__ real_t3 operator/(
real_t b, real_t3 a) {
331 return make_real_t3(b / a.x, b / a.y, b / a.z);
334 inline __device__ real_t4 operator/(real_t4 a, real_t4 b) {
335 return make_real_t4(a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w);
337 inline __device__
void operator/=(real_t4 &a, real_t4 b) {
343 inline __device__ real_t4 operator/(real_t4 a,
real_t b) {
344 return make_real_t4(a.x / b, a.y / b, a.z / b, a.w / b);
346 inline __device__
void operator/=(real_t4 &a,
real_t b) {
352 inline __device__ real_t4 operator/(
real_t b, real_t4 a) {
353 return make_real_t4(b / a.x, b / a.y, b / a.z, b / a.w);
360 inline __device__ real_t2 fminf(real_t2 a, real_t2 b) {
361 return make_real_t2(fminf(a.x, b.x), fminf(a.y, b.y));
363 inline __device__ real_t3 fminf(real_t3 a, real_t3 b) {
364 return make_real_t3(fminf(a.x, b.x), fminf(a.y, b.y), fminf(a.z, b.z));
366 inline __device__ real_t4 fminf(real_t4 a, real_t4 b) {
367 return make_real_t4(fminf(a.x, b.x), fminf(a.y, b.y), fminf(a.z, b.z),
375 inline __device__ real_t2 fmaxf(real_t2 a, real_t2 b) {
376 return make_real_t2(fmaxf(a.x, b.x), fmaxf(a.y, b.y));
378 inline __device__ real_t3 fmaxf(real_t3 a, real_t3 b) {
379 return make_real_t3(fmaxf(a.x, b.x), fmaxf(a.y, b.y), fmaxf(a.z, b.z));
381 inline __device__ real_t4 fmaxf(real_t4 a, real_t4 b) {
382 return make_real_t4(fmaxf(a.x, b.x), fmaxf(a.y, b.y), fmaxf(a.z, b.z),
390 inline __device__
real_t dot(real_t2 a, real_t2 b) {
391 return a.x * b.x + a.y * b.y;
393 inline __device__
real_t dot(real_t3 a, real_t3 b) {
394 return a.x * b.x + a.y * b.y + a.z * b.z;
396 inline __device__
real_t dot(real_t4 a, real_t4 b) {
397 return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
404 inline __device__
real_t length(real_t2 v) {
return sqrtf(dot(v, v)); }
405 inline __device__
real_t length(real_t3 v) {
return sqrtf(dot(v, v)); }
406 inline __device__
real_t length(real_t4 v) {
return sqrtf(dot(v, v)); }
412 inline __device__ real_t2 normalize(real_t2 v) {
413 real_t invLen = rsqrtf(dot(v, v));
416 inline __device__ real_t3 normalize(real_t3 v) {
417 real_t invLen = rsqrtf(dot(v, v));
420 inline __device__ real_t4 normalize(real_t4 v) {
421 real_t invLen = rsqrtf(dot(v, v));
429 inline __device__ real_t2 floorf(real_t2 v) {
430 return make_real_t2(floorf(v.x), floorf(v.y));
432 inline __device__ real_t3 floorf(real_t3 v) {
433 return make_real_t3(floorf(v.x), floorf(v.y), floorf(v.z));
435 inline __device__ real_t4 floorf(real_t4 v) {
436 return make_real_t4(floorf(v.x), floorf(v.y), floorf(v.z), floorf(v.w));
443 inline __device__
real_t fracf(
real_t v) {
return v - floorf(v); }
444 inline __device__ real_t2 fracf(real_t2 v) {
445 return make_real_t2(fracf(v.x), fracf(v.y));
447 inline __device__ real_t3 fracf(real_t3 v) {
448 return make_real_t3(fracf(v.x), fracf(v.y), fracf(v.z));
450 inline __device__ real_t4 fracf(real_t4 v) {
451 return make_real_t4(fracf(v.x), fracf(v.y), fracf(v.z), fracf(v.w));
458 inline __device__ real_t2 fmodf(real_t2 a, real_t2 b) {
459 return make_real_t2(fmodf(a.x, b.x), fmodf(a.y, b.y));
461 inline __device__ real_t3 fmodf(real_t3 a, real_t3 b) {
462 return make_real_t3(fmodf(a.x, b.x), fmodf(a.y, b.y), fmodf(a.z, b.z));
464 inline __device__ real_t4 fmodf(real_t4 a, real_t4 b) {
465 return make_real_t4(fmodf(a.x, b.x), fmodf(a.y, b.y), fmodf(a.z, b.z),
473 inline __device__ real_t2 fabs(real_t2 v) {
474 return make_real_t2(fabs(v.x), fabs(v.y));
476 inline __device__ real_t3 fabs(real_t3 v) {
477 return make_real_t3(fabs(v.x), fabs(v.y), fabs(v.z));
479 inline __device__ real_t4 fabs(real_t4 v) {
480 return make_real_t4(fabs(v.x), fabs(v.y), fabs(v.z), fabs(v.w));
487 inline __device__ real_t3 cross(real_t3 a, real_t3 b) {
488 return make_real_t3(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z,
489 a.x * b.y - a.y * b.x);
494 #endif // CORE_GPU_HELPER_MATH_DOUBLE_H_