Skip to content
it's /me edited this page Mar 2, 2021 · 2 revisions

There are shader translations in which unexpected results occur as a result of a pow calculation. This is due to the different handling of the result. The problem can be eliminated with the help of this substitute function:

// corrected pow-function by Chris Ridings
__DEVICE__ float powcf(float x, float y) {
  float ret = _powf(x,y);
  if (isnan(ret)) {
    ret = 0.0001f;
  }
  return ret;
}

Alternative method

__DEVICE__ float lpowf(float a, float b) {
  float la = _logf(a);
  float bl = b * la;		
  return _expf(bl);
}
Clone this wiki locally