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

HNumber HMath::exp ( const HNumber x ) [static]

Returns e raised to x.

Definition at line 906 of file hmath.cpp.

References abs(), div(), HNumber::isNan(), HNumber::isNegative(), HNumber::isZero(), and HNumber::nan().

Referenced by cosh(), raise(), and sinh().

{
  if( x.isNan() )
    return HNumber::nan();
    
  bool negative = x.isNegative();
  HNumber xs = HMath::abs( x );

  // adjust so that x is less than 1
  // Taylor expansion: e^x = 1 + x + x^2/2! + x^3/3! + ...
  HNumber num = xs;
  HNumber den = 1;
  HNumber sum = xs + 1;
  
  // now loop to sum the series
  for( int i = 2; i < HMATH_MAX_PREC; i++ )
  {
    num *= xs;
    den *= HNumber(i);
    if( num.isZero() ) break;
    HNumber s = HMath::div( num, den );
    if( s.isZero() ) break;
    sum += s;
  }
  
  HNumber result = sum;
  if( negative )
    result = HMath::div( HNumber(1), result );
  
  return result;
};

Here is the call graph for this function:

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index