[go: up one dir, main page]

Menu

[r171]: / release-2 / cocolib / defs.h  Maximize  Restore  History

Download this file

58 lines (44 with data), 1.3 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef CUDA_LIB_DEFS
#define CUDA_LIB_DEFS
#include <math.h>
#include <assert.h>
// Uncomment if double capability is desired
// EXPERIMENTAL FEATURE, NOT FULLY IMPLEMENTED YET.
//#define CUDA_DOUBLE
#ifdef CUDA_DOUBLE
typedef double cuflt;
#else
typedef float cuflt;
#endif
// TODO: switch to local block sizes everywhere
#define CUDA_BLOCK_SIZE 8
#define CUDA_SAFE_CALL(c) if ( c != cudaSuccess ) { printf("CUDA error: %s, line %d\n", cudaGetErrorString( cudaGetLastError() ), __LINE__); assert( false ); }
// some useful inline functions
/// Clamps a value to a given range
/** \ingroup mathutil */
template<class T> inline T clamp( const T& v, const T& min, const T& max ) {
if (v<min) return min;
if (v>max) return max;
return v;
};
/// Square of a number
/** \ingroup mathutil */
template<class T> T square( const T& v ) {
return (T)pow( v,2 );
};
/// Convert degrees to radian
/** \ingroup mathutil */
template<class T> T d2r( const T& x ) {
return x*M_PI / 180.0f;
};
/// Interpolation from a to b at t
/** \ingroup mathutil */
template<class T> T interpolate( const T& a, const T& b, const T& t ) {
return t*b + (1-t)*a;
};
/// Convert radian to degrees
/** \ingroup mathutil */
template<class T> T r2d( const T& x ) {
return x*180.0f/M_PI;
};
#endif