fixed: Factorial(const ValueType & x, ErrorCode * err = 0)
didn't want to compile moved: UInt<>::SkipWhiteCharacters() to Misc::SkipWhiteCharacters() UInt<>::CharToDigit() to Misc::CharToDigit() UInt<>::DigitToChar() to Misc::DigitToChar() removed: Parser::CharToDigit() - was duplicated (it's the same as Misc::CharToDigit()) git-svn-id: svn://ttmath.org/publicrep/ttmath/trunk@198 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
adc5015ad9
commit
f19078f9f1
|
@ -2681,7 +2681,9 @@ namespace ttmath
|
|||
x! = gamma(x+1)
|
||||
*/
|
||||
template<class ValueType>
|
||||
ValueType Factorial2(ValueType x, CGamma<ValueType> * cgamma = 0, ErrorCode * err = 0,
|
||||
ValueType Factorial2(ValueType x,
|
||||
CGamma<ValueType> * cgamma = 0,
|
||||
ErrorCode * err = 0,
|
||||
const volatile StopCalculating * stop = 0)
|
||||
{
|
||||
ValueType result, one;
|
||||
|
@ -2742,7 +2744,7 @@ namespace ttmath
|
|||
template<class ValueType>
|
||||
ValueType Factorial(const ValueType & x, ErrorCode * err = 0)
|
||||
{
|
||||
return auxiliaryfunctions::Factorial2(x, 0, err, 0);
|
||||
return auxiliaryfunctions::Factorial2(x, (CGamma<ValueType>*)0, err, 0);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3308,7 +3308,7 @@ private:
|
|||
typename string_type::size_type i = new_man.length() - 1;
|
||||
|
||||
// we're erasing the last character
|
||||
uint digit = UInt<man>::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<man>::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<char_type>( UInt<man>::DigitToChar(digit) );
|
||||
new_man[i] = static_cast<char_type>( Misc::DigitToChar(digit) );
|
||||
}
|
||||
|
||||
if( i<0 && was_carry )
|
||||
|
@ -3606,7 +3606,7 @@ private:
|
|||
if( static_cast<typename string_type::size_type>(max_digit_after_comma) >= after_comma )
|
||||
return;
|
||||
|
||||
uint last_digit = UInt<man>::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<class char_type>
|
||||
void FromString_TestSign( const char_type * & source, bool & is_sign )
|
||||
{
|
||||
UInt<man>::SkipWhiteCharacters(source);
|
||||
Misc::SkipWhiteCharacters(source);
|
||||
|
||||
is_sign = false;
|
||||
|
||||
|
@ -3770,9 +3770,9 @@ private:
|
|||
Big<exp, man> temp;
|
||||
Big<exp, man> base_( base );
|
||||
|
||||
UInt<man>::SkipWhiteCharacters( source );
|
||||
Misc::SkipWhiteCharacters( source );
|
||||
|
||||
for( ; (character=UInt<man>::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<man>::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<man>::CharToDigit(*source, base) != -1 ; ++source );
|
||||
for( ; Misc::CharToDigit(*source, base) != -1 ; ++source );
|
||||
|
||||
return (c==0)? 0 : 1;
|
||||
}
|
||||
|
@ -3879,7 +3879,7 @@ private:
|
|||
template<class char_type>
|
||||
bool FromString_TestScientific(const char_type * & source)
|
||||
{
|
||||
UInt<man>::SkipWhiteCharacters(source);
|
||||
Misc::SkipWhiteCharacters(source);
|
||||
|
||||
if( *source=='e' || *source=='E' )
|
||||
{
|
||||
|
@ -3930,12 +3930,12 @@ private:
|
|||
sint character;
|
||||
Big<exp, man> base, temp;
|
||||
|
||||
UInt<man>::SkipWhiteCharacters(source);
|
||||
Misc::SkipWhiteCharacters(source);
|
||||
|
||||
new_exponent.SetZero();
|
||||
base = 10;
|
||||
|
||||
for( ; (character=UInt<man>::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<man>::CharToDigit(z, 10) < 0 )
|
||||
if( Misc::CharToDigit(z, 10) < 0 )
|
||||
break;
|
||||
|
||||
|
||||
|
|
|
@ -936,17 +936,17 @@ private:
|
|||
{
|
||||
bool is_sign = false;
|
||||
|
||||
UInt<value_size>::SkipWhiteCharacters(s);
|
||||
Misc::SkipWhiteCharacters(s);
|
||||
|
||||
if( *s == '-' )
|
||||
{
|
||||
is_sign = true;
|
||||
UInt<value_size>::SkipWhiteCharacters(++s);
|
||||
Misc::SkipWhiteCharacters(++s);
|
||||
}
|
||||
else
|
||||
if( *s == '+' )
|
||||
{
|
||||
UInt<value_size>::SkipWhiteCharacters(++s);
|
||||
Misc::SkipWhiteCharacters(++s);
|
||||
}
|
||||
|
||||
if( UInt<value_size>::FromString(s,b,after_source,value_read) )
|
||||
|
@ -1422,7 +1422,7 @@ private:
|
|||
}
|
||||
|
||||
// we're reading only digits (base=10)
|
||||
while( s.good() && UInt<value_size>::CharToDigit(z, 10)>=0 )
|
||||
while( s.good() && Misc::CharToDigit(z, 10)>=0 )
|
||||
{
|
||||
ss += z;
|
||||
z = static_cast<char_type>(s.get());
|
||||
|
|
|
@ -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<class char_type>
|
||||
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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<another_size> type to this class
|
||||
|
||||
|
@ -2735,7 +2661,7 @@ private:
|
|||
do
|
||||
{
|
||||
temp.DivInt(b, &rem);
|
||||
character = static_cast<char>( DigitToChar(rem) );
|
||||
character = static_cast<char>( 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<class char_type>
|
||||
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<char_type>(s.get());
|
||||
|
|
Loading…
Reference in New Issue