如何检查WebGL中float
是否无限?
这些似乎对我有用:
bool isinf(float n) {
// one is actually required, without it n > inf if n is infinite
// assuming n is infinite, using just inf = 1.0 / 0.0, results in n > inf
float one = 1.0;
float inf = one / 0.0;
return abs(n) == inf;
}
bool isinf2(float n) {
float small_inf = 1.0 / 0.0;
return abs(n) > small_inf;
}
有更标准的方法吗?
答案 0 :(得分:0)
我会把无限放在常数中:
const float inf = 1.0/0.0;
bool isinf(float n){
return abs(n) == inf;
}