targetsif 语句中的两个赋值会引发以下错误。
error: expression must have integral or enum type
Run Code Online (Sandbox Code Playgroud)
操作中的所有变量都是或返回浮点值,正如它们所声明的那样。但它不喜欢转换为整数。为什么是这样?不同种类的浮点数或整数之间有区别吗?
__global__
void generateTargets(int* targets, int targetAmount, float radius, float angleStep){
float i = blockIdx.x;
if(i < targetAmount){ // Ensure it stays in range
// Access the 1d array representation of the 2d array [MAX_TARGETS][2]
targets[i + MAX_TARGETS*0] = __float2int_rd(radius*__cosf(i*angleStep)); // X value
targets[i + MAX_TARGETS*1] = __float2int_rd(radius*__sinf(i*angleStep)); // Y value
}
}
Run Code Online (Sandbox Code Playgroud)