public static float cuCabs(cuComplex x){
  float p=cuCreal(x);
  float q=cuCimag(x);
  float r;
  if (p == 0)   return q;
  if (q == 0)   return p;
  p=(float)Math.sqrt(p);
  q=(float)Math.sqrt(q);
  if (p < q) {
    r=p;
    p=q;
    q=r;
  }
  r=q / p;
  return p * (float)Math.sqrt(1.0f + r * r);
}

public static float cuCabs ( cuComplex x ) { float p = cuCreal ( x ) ; float q = cuCimag ( x ) ; float r ; if ( p == 0 ) return q ; if ( q == 0 ) return p ; p = ( float ) Math . sqrt ( p ) ; q = ( float ) Math . sqrt ( q ) ; if ( p < q ) { r = p ; p = q ; q = r ; } r = q / p ; return p * ( float ) Math . sqrt ( 1.0f + r * r ) ; }
returns the absolute value of the given complex number . < br / > < br / > original comment : < br / > < br / > this implementation guards against intermediate underflow and overflow by scaling . otherwise the we ' d lose half the exponent range . there are various ways of doing guarded computation . for now chose the simplest and fastest solution , however this may suffer from inaccuracies if sqrt and division are not ieee compliant .
