Logo Search packages:      
Sourcecode: abakus version File versions  Download package

HNumber HMath::raise ( const HNumber n1,
const HNumber n2 
) [static]

Raises n1 to n2.

Definition at line 879 of file hmath.cpp.

References exp(), format(), integer(), HNumber::isNan(), HNumber::isZero(), ln(), HNumber::nan(), and raise().

{
  if( n1.isNan() ) return HNumber::nan();
  if( n2.isNan() ) return HNumber::nan();

  if( n1.isZero() ) return HNumber(0);
  if( n1 == HNumber(1) ) return n1;
  if( n2.isZero() ) return HNumber(1);
  if( n2 == HNumber(1) ) return n1;
  
  if( n2 == HMath::integer(n2) )
  {
    // Evil hack.
    char *str = HMath::format( n2 );
    int i = atoi(str);
    free (str);

    return HMath::raise( n1, i );
  }

  // x^y = exp( y*ln(x) )
  HNumber result = n2 * HMath::ln(n1);
  result = HMath::exp( result );
  
  return result;
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index