diff --git a/ttmath/ttmath.h b/ttmath/ttmath.h index ddb4a17..9d4e4c2 100644 --- a/ttmath/ttmath.h +++ b/ttmath/ttmath.h @@ -2681,7 +2681,9 @@ namespace ttmath x! = gamma(x+1) */ template - ValueType Factorial2(ValueType x, CGamma * cgamma = 0, ErrorCode * err = 0, + ValueType Factorial2(ValueType x, + CGamma * cgamma = 0, + ErrorCode * err = 0, const volatile StopCalculating * stop = 0) { ValueType result, one; @@ -2742,7 +2744,7 @@ namespace ttmath template ValueType Factorial(const ValueType & x, ErrorCode * err = 0) { - return auxiliaryfunctions::Factorial2(x, 0, err, 0); + return auxiliaryfunctions::Factorial2(x, (CGamma*)0, err, 0); } diff --git a/ttmath/ttmathbig.h b/ttmath/ttmathbig.h index df051d5..48e80e6 100644 --- a/ttmath/ttmathbig.h +++ b/ttmath/ttmathbig.h @@ -3308,7 +3308,7 @@ private: typename string_type::size_type i = new_man.length() - 1; // we're erasing the last character - uint digit = UInt::CharToDigit( new_man[i] ); + uint digit = Misc::CharToDigit( new_man[i] ); new_man.erase( i, 1 ); uint carry = new_exp.AddOne(); @@ -3344,14 +3344,14 @@ private: continue; // we're adding one - uint digit = UInt::CharToDigit( new_man[i] ) + 1; + uint digit = Misc::CharToDigit( new_man[i] ) + 1; if( digit == base ) digit = 0; else was_carry = false; - new_man[i] = static_cast( UInt::DigitToChar(digit) ); + new_man[i] = static_cast( Misc::DigitToChar(digit) ); } if( i<0 && was_carry ) @@ -3606,7 +3606,7 @@ private: if( static_cast(max_digit_after_comma) >= after_comma ) return; - uint last_digit = UInt::CharToDigit( new_man[ index + max_digit_after_comma + 1 ], base ); + uint last_digit = Misc::CharToDigit( new_man[ index + max_digit_after_comma + 1 ], base ); // we're cutting the rest of the string new_man.erase(index + max_digit_after_comma + 1, after_comma - max_digit_after_comma); @@ -3724,7 +3724,7 @@ private: template void FromString_TestSign( const char_type * & source, bool & is_sign ) { - UInt::SkipWhiteCharacters(source); + Misc::SkipWhiteCharacters(source); is_sign = false; @@ -3770,9 +3770,9 @@ private: Big temp; Big base_( base ); - UInt::SkipWhiteCharacters( source ); + Misc::SkipWhiteCharacters( source ); - for( ; (character=UInt::CharToDigit(*source, base)) != -1 ; ++source ) + for( ; (character=Misc::CharToDigit(*source, base)) != -1 ; ++source ) { value_read = true; @@ -3808,7 +3808,7 @@ private: power.SetOne(); - for( ; (character=UInt::CharToDigit(*source, base)) != -1 ; ++source, ++index ) + for( ; (character=Misc::CharToDigit(*source, base)) != -1 ; ++source, ++index ) { value_read = true; @@ -3841,7 +3841,7 @@ private: // we could break the parsing somewhere in the middle of the string, // but the result (value) still can be good // we should set a correct value of 'source' now - for( ; UInt::CharToDigit(*source, base) != -1 ; ++source ); + for( ; Misc::CharToDigit(*source, base) != -1 ; ++source ); return (c==0)? 0 : 1; } @@ -3879,7 +3879,7 @@ private: template bool FromString_TestScientific(const char_type * & source) { - UInt::SkipWhiteCharacters(source); + Misc::SkipWhiteCharacters(source); if( *source=='e' || *source=='E' ) { @@ -3930,12 +3930,12 @@ private: sint character; Big base, temp; - UInt::SkipWhiteCharacters(source); + Misc::SkipWhiteCharacters(source); new_exponent.SetZero(); base = 10; - for( ; (character=UInt::CharToDigit(*source, 10)) != -1 ; ++source ) + for( ; (character=Misc::CharToDigit(*source, 10)) != -1 ; ++source ) { scientific_read = true; @@ -4662,7 +4662,7 @@ private: break; } else - if( UInt::CharToDigit(z, 10) < 0 ) + if( Misc::CharToDigit(z, 10) < 0 ) break; diff --git a/ttmath/ttmathint.h b/ttmath/ttmathint.h index 32a2a2e..f6c8bcf 100644 --- a/ttmath/ttmathint.h +++ b/ttmath/ttmathint.h @@ -936,17 +936,17 @@ private: { bool is_sign = false; - UInt::SkipWhiteCharacters(s); + Misc::SkipWhiteCharacters(s); if( *s == '-' ) { is_sign = true; - UInt::SkipWhiteCharacters(++s); + Misc::SkipWhiteCharacters(++s); } else if( *s == '+' ) { - UInt::SkipWhiteCharacters(++s); + Misc::SkipWhiteCharacters(++s); } if( UInt::FromString(s,b,after_source,value_read) ) @@ -1422,7 +1422,7 @@ private: } // we're reading only digits (base=10) - while( s.good() && UInt::CharToDigit(z, 10)>=0 ) + while( s.good() && Misc::CharToDigit(z, 10)>=0 ) { ss += z; z = static_cast(s.get()); diff --git a/ttmath/ttmathmisc.h b/ttmath/ttmathmisc.h index 8e5398d..38ab596 100644 --- a/ttmath/ttmathmisc.h +++ b/ttmath/ttmathmisc.h @@ -145,6 +145,94 @@ static void AddString(std::wstring & result, const char * str) +/* + this method omits any white characters from the string + char_type is char or wchar_t +*/ +template +static void SkipWhiteCharacters(const char_type * & c) +{ + // 13 is at the end in a DOS text file (\r\n) + while( (*c==' ' ) || (*c=='\t') || (*c==13 ) || (*c=='\n') ) + ++c; +} + + + + +/*! + this static method converts one character into its value + + for example: + 1 -> 1 + 8 -> 8 + A -> 10 + f -> 15 + + this method don't check whether c is correct or not +*/ +static uint CharToDigit(uint c) +{ + if(c>='0' && c<='9') + return c-'0'; + + if(c>='a' && c<='z') + return c-'a'+10; + +return c-'A'+10; +} + + +/*! + this method changes a character 'c' into its value + (if there can't be a correct value it returns -1) + + for example: + c=2, base=10 -> function returns 2 + c=A, base=10 -> function returns -1 + c=A, base=16 -> function returns 10 +*/ +static sint CharToDigit(uint c, uint base) +{ + if( c>='0' && c<='9' ) + c=c-'0'; + else + if( c>='a' && c<='z' ) + c=c-'a'+10; + else + if( c>='A' && c<='Z' ) + c=c-'A'+10; + else + return -1; + + + if( c >= base ) + return -1; + + +return sint(c); +} + + + +/*! + this method converts a digit into a char + digit should be from <0,F> + (we don't have to get a base) + + for example: + 1 -> 1 + 8 -> 8 + 10 -> A + 15 -> F +*/ +static uint DigitToChar(uint digit) +{ + if( digit < 10 ) + return digit + '0'; + +return digit - 10 + 'A'; +} }; // struct Misc diff --git a/ttmath/ttmathparser.h b/ttmath/ttmathparser.h index 664ab85..9e98398 100644 --- a/ttmath/ttmathparser.h +++ b/ttmath/ttmathparser.h @@ -1716,31 +1716,6 @@ bool value_read; } -/*! - this method converts the character ascii c into the value in range <0;base-1> - - if the character is incorrect for this base the funcion will return -1 -*/ -int CharToDigit(int c, int base) -{ - if( c>='0' && c<='9' ) - c=c-'0'; - else - if( c>='a' && c<='z' ) - c=c-'a'+10; - else - if( c>='A' && c<='Z' ) - c=c-'A'+10; - else - return -1; - - if( c >= base ) - return -1; - -return c; -} - - /*! this method returns true if 'character' is a proper first digit for the value (or a comma -- can be first too) */ @@ -1752,7 +1727,7 @@ bool ValueStarts(int character, int base) if( TTMATH_COMMA_CHARACTER_2 != 0 && character == TTMATH_COMMA_CHARACTER_2 ) return true; - if( CharToDigit(character, base) != -1 ) + if( Misc::CharToDigit(character, base) != -1 ) return true; return false; diff --git a/ttmath/ttmathuint.h b/ttmath/ttmathuint.h index c4f2e80..3ccb829 100644 --- a/ttmath/ttmathuint.h +++ b/ttmath/ttmathuint.h @@ -2315,80 +2315,6 @@ public: - /*! - this static method converts one character into its value - - for example: - 1 -> 1 - 8 -> 8 - A -> 10 - f -> 15 - - this method don't check whether c is correct or not - */ - static uint CharToDigit(uint c) - { - if(c>='0' && c<='9') - return c-'0'; - - if(c>='a' && c<='z') - return c-'a'+10; - - return c-'A'+10; - } - - - /*! - this method changes a character 'c' into its value - (if there can't be a correct value it returns -1) - - for example: - c=2, base=10 -> function returns 2 - c=A, base=10 -> function returns -1 - c=A, base=16 -> function returns 10 - */ - static sint CharToDigit(uint c, uint base) - { - if( c>='0' && c<='9' ) - c=c-'0'; - else - if( c>='a' && c<='z' ) - c=c-'a'+10; - else - if( c>='A' && c<='Z' ) - c=c-'A'+10; - else - return -1; - - - if( c >= base ) - return -1; - - - return sint(c); - } - - - /*! - this method converts a digit into a char - digit should be from <0,F> - (we don't have to get a base) - - for example: - 1 -> 1 - 8 -> 8 - 10 -> A - 15 -> F - */ - static uint DigitToChar(uint digit) - { - if( digit < 10 ) - return digit + '0'; - - return digit - 10 + 'A'; - } - - /*! this method converts an UInt type to this class @@ -2735,7 +2661,7 @@ private: do { temp.DivInt(b, &rem); - character = static_cast( DigitToChar(rem) ); + character = static_cast( Misc::DigitToChar(rem) ); result.insert(result.begin(), character); } while( !temp.IsZero() ); @@ -2761,18 +2687,6 @@ public: - /* - this method's ommiting any white characters from the string - char_type is char or wchar_t - */ - template - static void SkipWhiteCharacters(const char_type * & c) - { - while( (*c==' ' ) || (*c=='\t') || (*c==13 ) || (*c=='\n') ) - ++c; - } - - private: /*! @@ -2800,7 +2714,7 @@ private: return 1; - for( ; (z=CharToDigit(*s, b)) != -1 ; ++s) + for( ; (z=Misc::CharToDigit(*s, b)) != -1 ; ++s) { if( value_read ) *value_read = true; @@ -3339,7 +3253,7 @@ private: s >> z; // we're reading only digits (base=10) - while( s.good() && CharToDigit(z, 10)>=0 ) + while( s.good() && Misc::CharToDigit(z, 10)>=0 ) { ss += z; z = static_cast(s.get());