changed: the way of parsing operators in the mathematical parser
(the parser is not too much greedy now) git-svn-id: svn://ttmath.org/publicrep/ttmath/trunk@38 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
2116418f08
commit
bb16c871c9
38
CHANGELOG
38
CHANGELOG
|
@ -1,3 +1,41 @@
|
||||||
|
Version 0.8.1 (2007.04.17):
|
||||||
|
* fixed: Big::PowFrac(..) didn't return a correct error code
|
||||||
|
(when 'this' was negative)
|
||||||
|
* added: Root(x; index) (and to the parser as well)
|
||||||
|
* added: macro: TTMATH_PRERELEASE_VER (can be either zero or one)
|
||||||
|
* added: UInt::MulInt(int, UInt<int another_size>::&)
|
||||||
|
* added: Big::MulUInt(uint)
|
||||||
|
* changed: Big::MulInt(sint)
|
||||||
|
* added: Big::ToUInt(uint &)
|
||||||
|
* changed: Big::ToInt(sint&)
|
||||||
|
* changed: Factorial() it uses Big::MulUInt() at the beginning
|
||||||
|
(faster now especially more on a 32bit platform)
|
||||||
|
* added: doxygen.cfg for generating a documentation from the doxygen
|
||||||
|
* changed: UInt::Rcl(uint c=0) and UInt::Rcr(uint c=0) into
|
||||||
|
UInt::Rcl2(uint bits, uint c) and UInt::Rcr2(uint bits, uint c)
|
||||||
|
now they can move more than one bit and they are only private
|
||||||
|
* fixed: UInt::Rcl(uint bits, uint c) and UInt::Rcr(uint bits, uint c)
|
||||||
|
didn't correctly return a carry if the 'bits' were equal
|
||||||
|
to 'value_size*TTMATH_BITS_PER_UINT'
|
||||||
|
* changed: UInt::Rcl(uint bits, uint c) and UInt::Rcr(uint bits, uint c)
|
||||||
|
into UInt::Rcl(uint bits, uint c=0) and
|
||||||
|
UInt::Rcr(uint bits, uint c=0)
|
||||||
|
they are faster now when the bits is greater than a half of
|
||||||
|
the TTMATH_BITS_PER_UINT
|
||||||
|
* changed: UInt::CompensationToLeft() it's faster now
|
||||||
|
* changed: more small changes where there were UInt::Rcl(uint c=0) and
|
||||||
|
UInt::Rcr(uint c=0) used
|
||||||
|
* changed: as the Big type uses UInt::Rcl() and UInt::Rcr() a lot then
|
||||||
|
it is much faster now (about 5-25%)
|
||||||
|
* added: ASinh(), ACosh(), ATanh() /ATgh()/, ACoth() /ACtgh()/
|
||||||
|
and to the parser as well
|
||||||
|
* added: UInt::BitAnd(), UInt::BitOr(), UInt::BitXor(), UInt::BitNot(),
|
||||||
|
Big::BitAnd(), Big::BitOr(), Big::BitXor()
|
||||||
|
* added: to the parser: bitand(), bitor(), bitxor()
|
||||||
|
/band(), bor(), bxor()/
|
||||||
|
* changed: the way of parsing operators in the mathematical parser
|
||||||
|
(the parser is not too much greedy now)
|
||||||
|
|
||||||
Version 0.8.0 (2007.03.28):
|
Version 0.8.0 (2007.03.28):
|
||||||
* added: into the parser: SetFactorialMax()
|
* added: into the parser: SetFactorialMax()
|
||||||
* added: DegToDeg(deg, min, sec), DegToRad(deg), DegToRad(deg, min, sec),
|
* added: DegToDeg(deg, min, sec), DegToRad(deg), DegToRad(deg, min, sec),
|
||||||
|
|
|
@ -549,7 +549,7 @@ public:
|
||||||
exp_offset.Sub( ss2.exponent );
|
exp_offset.Sub( ss2.exponent );
|
||||||
exp_offset.Abs();
|
exp_offset.Abs();
|
||||||
|
|
||||||
// abs(this) will be >= abs(ss2)
|
// (1) abs(this) will be >= abs(ss2)
|
||||||
if( SmallerWithoutSignThan(ss2) )
|
if( SmallerWithoutSignThan(ss2) )
|
||||||
{
|
{
|
||||||
Big<exp, man> temp(ss2);
|
Big<exp, man> temp(ss2);
|
||||||
|
@ -567,11 +567,12 @@ public:
|
||||||
else
|
else
|
||||||
if( exp_offset < mantissa_size_in_bits )
|
if( exp_offset < mantissa_size_in_bits )
|
||||||
{
|
{
|
||||||
// moving 'exp_offset' times
|
// (2) moving 'exp_offset' times
|
||||||
ss2.mantissa.Rcr( exp_offset.ToInt(), 0 );
|
ss2.mantissa.Rcr( exp_offset.ToInt(), 0 );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// (3)
|
||||||
// exp_offset == mantissa_size_in_bits
|
// exp_offset == mantissa_size_in_bits
|
||||||
// we're rounding 'this' about one (up or down depending on a ss2 sign)
|
// we're rounding 'this' about one (up or down depending on a ss2 sign)
|
||||||
ss2.mantissa.SetOne();
|
ss2.mantissa.SetOne();
|
||||||
|
@ -590,11 +591,12 @@ public:
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// values have different signs
|
// values have different signs
|
||||||
if( mantissa.Sub(ss2.mantissa) )
|
// there shouldn't be a carry here because
|
||||||
{
|
// (1) (2) and (3) guarantee that the mantissa of this
|
||||||
mantissa.Rcl(1,1); // maybe without this rcl and subone()? !!!!
|
// is greater than the mantissa of the ss2
|
||||||
c = exponent.SubOne();
|
uint c_temp = mantissa.Sub(ss2.mantissa);
|
||||||
}
|
|
||||||
|
TTMATH_ASSERT( c_temp == 0 )
|
||||||
}
|
}
|
||||||
|
|
||||||
c += Standardizing();
|
c += Standardizing();
|
||||||
|
|
|
@ -1619,13 +1619,22 @@ void CreateMathematicalOperatorsTable()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool CanBeMathematicalOperator(unsigned char c)
|
/*!
|
||||||
{
|
returns true if 'str2' is the substring of str1
|
||||||
if( c=='|' || c=='&' || c=='!' || c=='=' || c=='<' || c=='>' ||
|
|
||||||
c=='*' || c=='/' || c=='+' || c=='-' || c=='^' )
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
e.g.
|
||||||
|
true when str1="test" and str2="te"
|
||||||
|
*/
|
||||||
|
bool IsSubstring(const std::string & str1, const std::string & str2)
|
||||||
|
{
|
||||||
|
if( str2.length() > str1.length() )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for(std::string::size_type i=0 ; i<str2.length() ; ++i)
|
||||||
|
if( str1[i] != str2[i] )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1635,17 +1644,31 @@ return false;
|
||||||
void ReadMathematicalOperator(Item & result)
|
void ReadMathematicalOperator(Item & result)
|
||||||
{
|
{
|
||||||
std::string oper;
|
std::string oper;
|
||||||
|
typename OperatorsTable::iterator iter_old, iter_new;
|
||||||
|
|
||||||
for( ; CanBeMathematicalOperator(*pstring) ; ++pstring )
|
iter_old = operators_table.end();
|
||||||
|
|
||||||
|
for( ; true ; ++pstring )
|
||||||
|
{
|
||||||
oper += *pstring;
|
oper += *pstring;
|
||||||
|
iter_new = operators_table.lower_bound(oper);
|
||||||
|
|
||||||
|
if( iter_new == operators_table.end() || !IsSubstring(iter_new->first, oper) )
|
||||||
|
{
|
||||||
|
oper.erase( --oper.end() ); // we've got mininum one element
|
||||||
|
|
||||||
typename OperatorsTable::iterator iter = operators_table.find(oper);
|
if( iter_old != operators_table.end() && iter_old->first == oper )
|
||||||
|
{
|
||||||
if( iter == operators_table.end() )
|
result.type = Item::mat_operator;
|
||||||
Error( err_unknown_operator );
|
result.moperator.SetType( iter_old->second );
|
||||||
|
break;
|
||||||
result.type = Item::mat_operator;
|
}
|
||||||
result.moperator.SetType( iter->second );
|
|
||||||
|
Error( err_unknown_operator );
|
||||||
|
}
|
||||||
|
|
||||||
|
iter_old = iter_new;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1676,10 +1699,7 @@ int ReadOperator(Item & result)
|
||||||
++pstring;
|
++pstring;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if( CanBeMathematicalOperator(*pstring) )
|
|
||||||
ReadMathematicalOperator(result);
|
ReadMathematicalOperator(result);
|
||||||
else
|
|
||||||
Error( err_unknown_character );
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@
|
||||||
#define TTMATH_MAJOR_VER 0
|
#define TTMATH_MAJOR_VER 0
|
||||||
#define TTMATH_MINOR_VER 8
|
#define TTMATH_MINOR_VER 8
|
||||||
#define TTMATH_REVISION_VER 1
|
#define TTMATH_REVISION_VER 1
|
||||||
#define TTMATH_PRERELEASE_VER 1
|
#define TTMATH_PRERELEASE_VER 0
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
Loading…
Reference in New Issue