WebGL isinf功能

时间:2013-11-13 20:09:06

标签: floating-point webgl

如何检查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;
}

有更标准的方法吗?

1 个答案:

答案 0 :(得分:0)

我会把无限放在常数中:

const float inf = 1.0/0.0;

bool isinf(float n){
    return abs(n) == inf;
}