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

HNumber::HNumber ( const char *  str )

Creates a new number from a string.

Definition at line 331 of file hmath.cpp.

{
  h_init();
  d = new Private;
  d->nan = false;
  d->num = h_create();

  if( str )
  if( strlen(str) == 3 )
  if( tolower(str[0])=='n' )
  if( tolower(str[1])=='a' )
  if( tolower(str[2])=='n' )
    d->nan = true;

  if( str && !d->nan )
  {
    char* s = new char[ strlen(str)+1 ];
    strcpy( s, str );
    
    char* p = s;
    for( ;; p++ )
    {
      if( *p != '+' )
      if( *p != '-' )
      if( *p != '.' )
      if( !isdigit(*p) )
        break;
     }
     
    int expd = 0;  
    
    if( ( *p == 'e' ) || ( *p == 'E' ) )
    {
      *p = '\0';
      expd = atoi( p+1 );
    }
    
    h_destroy( d->num );
    d->num = h_str2num( s );
    delete [] s;

    if( expd >= HMATH_MAX_PREC || // too large
        expd <= -HMATH_MAX_PREC ) // too small
    {
      d->nan = true;
    }

    if( expd != 0 )
    {
      bc_num factor = h_raise10( expd );
      bc_num nn = h_copy( d->num );
      h_destroy( d->num );
      d->num = h_mul( nn, factor );
      h_destroy( nn );
      h_destroy( factor );
    }
    h_trimzeros( d->num );
  }
  
}

Generated by  Doxygen 1.6.0   Back to index