46 #ifndef CUTIL_MATH_BUGFIXES_H 47 #define CUTIL_MATH_BUGFIXES_H 49 #ifdef CUTIL_MATH_H //Danny 53 #error cutil_math_bugfixes.h has to be included before cutil_math.h!!! 55 #define CUTIL_MATH_H //make sure that the buggy cutil_math.h will not be included 57 #include "cuda_runtime.h" 66 inline float fminf(
float a,
float b)
71 inline float fmaxf(
float a,
float b)
76 inline int max(
int a,
int b)
81 inline int min(
int a,
int b)
91 inline __device__ __host__
float lerp(
float a,
float b,
float t)
97 inline __device__ __host__
float clamp(
float f,
float a,
float b)
106 inline __host__ __device__ int2
operator+(int2 a, int2 b)
108 return make_int2(a.x + b.x, a.y + b.y);
112 a.x += b.x; a.y += b.y;
116 inline __host__ __device__ int2
operator-(int2 a, int2 b)
118 return make_int2(a.x - b.x, a.y - b.y);
122 a.x -= b.x; a.y -= b.y;
126 inline __host__ __device__ int2
operator*(int2 a, int2 b)
128 return make_int2(a.x * b.x, a.y * b.y);
130 inline __host__ __device__ int2
operator*(int2 a,
int s)
132 return make_int2(a.x * s, a.y * s);
134 inline __host__ __device__ int2
operator*(
int s, int2 a)
136 return make_int2(a.x * s, a.y * s);
157 inline __host__ __device__ float2
operator+(float2 a, float2 b)
161 inline __host__ __device__
void operator+=(float2 &a, float2 b)
163 a.x += b.x; a.y += b.y;
167 inline __host__ __device__ float2
operator-(float2 a, float2 b)
171 inline __host__ __device__
void operator-=(float2 &a, float2 b)
173 a.x -= b.x; a.y -= b.y;
177 inline __host__ __device__ float2
operator*(float2 a, float2 b)
181 inline __host__ __device__ float2
operator*(float2 a,
float s)
185 inline __host__ __device__ float2
operator*(
float s, float2 a)
189 inline __host__ __device__
void operator*=(float2 &a,
float s)
195 inline __host__ __device__ float2
operator/(float2 a, float2 b)
199 inline __host__ __device__ float2
operator/(float2 a,
float s)
201 float inv = 1.0f / s;
204 inline __host__ __device__ float2
operator/(
float s, float2 a)
210 inline __host__ __device__
void operator/=(float2 &a,
float s)
212 float inv = 1.0f / s;
217 inline __device__ __host__ float2
lerp(float2 a, float2 b,
float t)
223 inline __device__ __host__ float2
clamp(float2 v,
float a,
float b)
228 inline __device__ __host__ float2
clamp(float2 v, float2 a, float2 b)
234 inline __host__ __device__
float dot(float2 a, float2 b)
236 return a.x * b.x + a.y * b.y;
240 inline __host__ __device__
float length(float2 v)
242 return sqrtf(
dot(v, v));
248 float invLen = 1.0f / sqrtf(
dot(v, v));
253 inline __host__ __device__ float2
floor(
const float2 v)
259 inline __host__ __device__ float2
reflect(float2 i, float2 n)
261 return i - 2.0f * n *
dot(n,i);
286 return make_float3(
float(a.x),
float(a.y),
float(a.z));
290 static __inline__ __host__ __device__ float3
fminf(float3 a, float3 b)
296 static __inline__ __host__ __device__ float3
fmaxf(float3 a, float3 b)
302 inline __host__ __device__ float3
operator+(float3 a, float3 b)
304 return make_float3(a.x + b.x, a.y + b.y, a.z + b.z);
306 inline __host__ __device__ float3
operator+(float3 a,
float b)
310 inline __host__ __device__
void operator+=(float3 &a, float3 b)
312 a.x += b.x; a.y += b.y; a.z += b.z;
316 inline __host__ __device__ float3
operator-(float3 a, float3 b)
318 return make_float3(a.x - b.x, a.y - b.y, a.z - b.z);
320 inline __host__ __device__ float3
operator-(float3 a,
float b)
324 inline __host__ __device__
void operator-=(float3 &a, float3 b)
326 a.x -= b.x; a.y -= b.y; a.z -= b.z;
330 inline __host__ __device__ float3
operator*(float3 a, float3 b)
332 return make_float3(a.x * b.x, a.y * b.y, a.z * b.z);
334 inline __host__ __device__ float3
operator*(float3 a,
float s)
338 inline __host__ __device__ float3
operator*(
float s, float3 a)
342 inline __host__ __device__
void operator*=(float3 &a,
float s)
344 a.x *= s; a.y *= s; a.z *= s;
348 inline __host__ __device__ float3
operator/(float3 a, float3 b)
350 return make_float3(a.x / b.x, a.y / b.y, a.z / b.z);
352 inline __host__ __device__ float3
operator/(float3 a,
float s)
354 float inv = 1.0f / s;
357 inline __host__ __device__ float3
operator/(
float s, float3 a)
363 inline __host__ __device__
void operator/=(float3 &a,
float s)
365 float inv = 1.0f / s;
370 inline __device__ __host__ float3
lerp(float3 a, float3 b,
float t)
376 inline __device__ __host__ float3
clamp(float3 v,
float a,
float b)
381 inline __device__ __host__ float3
clamp(float3 v, float3 a, float3 b)
387 inline __host__ __device__
float dot(float3 a, float3 b)
389 return a.x * b.x + a.y * b.y + a.z * b.z;
393 inline __host__ __device__ float3
cross(float3 a, float3 b)
395 return make_float3(a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x);
399 inline __host__ __device__
float length(float3 v)
401 return sqrtf(
dot(v, v));
407 float invLen = 1.0f / sqrtf(
dot(v, v));
412 inline __host__ __device__ float3
floor(
const float3 v)
418 inline __host__ __device__ float3
reflect(float3 i, float3 n)
420 return i - 2.0f * n *
dot(n,i);
441 return make_float4(
float(a.x),
float(a.y),
float(a.z),
float(a.w));
445 static __inline__ __host__ __device__ float4
fminf(float4 a, float4 b)
451 static __inline__ __host__ __device__ float4
fmaxf(float4 a, float4 b)
457 inline __host__ __device__ float4
operator+(float4 a, float4 b)
459 return make_float4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
461 inline __host__ __device__
void operator+=(float4 &a, float4 b)
463 a.x += b.x; a.y += b.y; a.z += b.z; a.w += b.w;
467 inline __host__ __device__ float4
operator-(float4 a, float4 b)
469 return make_float4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
471 inline __host__ __device__
void operator-=(float4 &a, float4 b)
473 a.x -= b.x; a.y -= b.y; a.z -= b.z; a.w -= b.w;
477 inline __host__ __device__ float4
operator*(float4 a,
float s)
479 return make_float4(a.x * s, a.y * s, a.z * s, a.w * s);
481 inline __host__ __device__ float4
operator*(
float s, float4 a)
483 return make_float4(a.x * s, a.y * s, a.z * s, a.w * s);
485 inline __host__ __device__
void operator*=(float4 &a,
float s)
487 a.x *= s; a.y *= s; a.z *= s; a.w *= s;
491 inline __host__ __device__ float4
operator/(float4 a, float4 b)
493 return make_float4(a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w);
495 inline __host__ __device__ float4
operator/(float4 a,
float s)
497 float inv = 1.0f / s;
500 inline __host__ __device__ float4
operator/(
float s, float4 a)
504 return make_float4(s / a.x, s / a.y, s / a.z, s / a.w);
506 inline __host__ __device__
void operator/=(float4 &a,
float s)
508 float inv = 1.0f / s;
513 inline __device__ __host__ float4
lerp(float4 a, float4 b,
float t)
519 inline __device__ __host__ float4
clamp(float4 v,
float a,
float b)
521 return make_float4(
clamp(v.x, a, b),
clamp(v.y, a, b),
clamp(v.z, a, b),
clamp(v.w, a, b));
524 inline __device__ __host__ float4
clamp(float4 v, float4 a, float4 b)
526 return make_float4(
clamp(v.x, a.x, b.x),
clamp(v.y, a.y, b.y),
clamp(v.z, a.z, b.z),
clamp(v.w, a.w, b.w));
530 inline __host__ __device__
float dot(float4 a, float4 b)
532 return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
536 inline __host__ __device__
float length(float4 r)
538 return sqrtf(
dot(r, r));
544 float invLen = 1.0f / sqrtf(
dot(v, v));
549 inline __host__ __device__ float4
floor(
const float4 v)
564 return make_int3(
int(a.x),
int(a.y),
int(a.z));
568 inline __host__ __device__ int3
min(int3 a, int3 b)
574 inline __host__ __device__ int3
max(int3 a, int3 b)
580 inline __host__ __device__ int3
operator+(int3 a, int3 b)
582 return make_int3(a.x + b.x, a.y + b.y, a.z + b.z);
586 a.x += b.x; a.y += b.y; a.z += b.z;
590 inline __host__ __device__ int3
operator-(int3 a, int3 b)
592 return make_int3(a.x - b.x, a.y - b.y, a.z - b.z);
597 a.x -= b.x; a.y -= b.y; a.z -= b.z;
601 inline __host__ __device__ int3
operator*(int3 a, int3 b)
603 return make_int3(a.x * b.x, a.y * b.y, a.z * b.z);
605 inline __host__ __device__ int3
operator*(int3 a,
int s)
607 return make_int3(a.x * s, a.y * s, a.z * s);
609 inline __host__ __device__ int3
operator*(
int s, int3 a)
611 return make_int3(a.x * s, a.y * s, a.z * s);
615 a.x *= s; a.y *= s; a.z *= s;
619 inline __host__ __device__ int3
operator/(int3 a, int3 b)
621 return make_int3(a.x / b.x, a.y / b.y, a.z / b.z);
623 inline __host__ __device__ int3
operator/(int3 a,
int s)
625 return make_int3(a.x / s, a.y / s, a.z / s);
627 inline __host__ __device__ int3
operator/(
int s, int3 a)
629 return make_int3(a.x / s, a.y / s, a.z / s);
633 a.x /= s; a.y /= s; a.z /= s;
637 inline __device__ __host__
int clamp(
int f,
int a,
int b)
642 inline __device__ __host__ int3
clamp(int3 v,
int a,
int b)
647 inline __device__ __host__ int3
clamp(int3 v, int3 a, int3 b)
667 inline __host__ __device__ uint3
min(uint3 a, uint3 b)
673 inline __host__ __device__ uint3
max(uint3 a, uint3 b)
679 inline __host__ __device__ uint3
operator+(uint3 a, uint3 b)
681 return make_uint3(a.x + b.x, a.y + b.y, a.z + b.z);
683 inline __host__ __device__
void operator+=(uint3 &a, uint3 b)
685 a.x += b.x; a.y += b.y; a.z += b.z;
689 inline __host__ __device__ uint3
operator-(uint3 a, uint3 b)
691 return make_uint3(a.x - b.x, a.y - b.y, a.z - b.z);
694 inline __host__ __device__
void operator-=(uint3 &a, uint3 b)
696 a.x -= b.x; a.y -= b.y; a.z -= b.z;
700 inline __host__ __device__ uint3
operator*(uint3 a, uint3 b)
702 return make_uint3(a.x * b.x, a.y * b.y, a.z * b.z);
714 a.x *= s; a.y *= s; a.z *= s;
718 inline __host__ __device__ uint3
operator/(uint3 a, uint3 b)
720 return make_uint3(a.x / b.x, a.y / b.y, a.z / b.z);
732 a.x /= s; a.y /= s; a.z /= s;
746 inline __device__ __host__ uint3
clamp(uint3 v, uint3 a, uint3 b)
__host__ __device__ float dot(float2 a, float2 b)
float fmaxf(float a, float b)
__device__ __host__ float clamp(float f, float a, float b)
__host__ __device__ uint3 make_uint3(uint s)
__host__ __device__ float2 floor(const float2 v)
__host__ __device__ float4 make_float4(float s)
__host__ __device__ int2 operator+(int2 a, int2 b)
__host__ __device__ void operator-=(int2 &a, int2 b)
__host__ __device__ void operator*=(int2 &a, int s)
__host__ __device__ float2 normalize(float2 v)
__host__ __device__ float2 reflect(float2 i, float2 n)
__host__ __device__ float3 cross(float3 a, float3 b)
__host__ __device__ int2 operator*(int2 a, int2 b)
__host__ __device__ float3 make_float3(float s)
__host__ __device__ float2 make_float2(float s)
__host__ __device__ float2 operator/(float2 a, float2 b)
__device__ __host__ float lerp(float a, float b, float t)
float fminf(float a, float b)
__host__ __device__ void operator+=(int2 &a, int2 b)
__host__ __device__ int2 operator-(int2 a, int2 b)
__host__ __device__ int3 make_int3(int s)
__host__ __device__ float length(float2 v)
__host__ __device__ void operator/=(float2 &a, float s)