added: to the parser: operator percentage

e.g. 1000-50%=1000-(1000*0,5)=500



git-svn-id: svn://ttmath.org/publicrep/ttmath/trunk@217 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2009-10-18 12:37:14 +00:00
parent af4fbf3098
commit bf520689fb
3 changed files with 35 additions and 4 deletions

View File

@ -1,4 +1,4 @@
Version 0.9.0 prerelease (2009.10.16):
Version 0.9.0 prerelease (2009.10.18):
* fixed: Big::operator>>(std::istream&, Big<> &) didn't recognize values
in scientific mode (with 'e' character)
* fixed: UInt::SetBitInWord(uint & value, uint bit) set 1 if the bit was
@ -42,6 +42,8 @@ Version 0.9.0 prerelease (2009.10.16):
* added: bool Parser::Calculated()
this method returns true is something was calculated
(at least one mathematical operator was used or a function or variable)
* added: to the parser: operator percentage
e.g. 1000-50%=1000-(1000*0,5)=500
* changed: Factorial() is using the Gamma() function now
* changed: Big::Div(ss2)
Big::Mod(ss2)

View File

@ -1939,6 +1939,31 @@ typename OperatorsTable::iterator iter_old, iter_new;
}
/*!
this method makes a calculation for the percentage operator
e.g.
1000-50% = 1000-(1000*0,5) = 500
*/
void OperatorPercentage()
{
if( stack_index < 3 ||
stack[stack_index-1].type != Item::numerical_value ||
stack[stack_index-2].type != Item::mat_operator ||
stack[stack_index-3].type != Item::numerical_value )
Error(err_percent_from);
++pstring;
SkipWhiteCharacters();
uint c = 0;
c += stack[stack_index-1].value.Div(100);
c += stack[stack_index-1].value.Mul(stack[stack_index-3].value);
if( c )
Error(err_overflow);
}
/*!
this method reads a mathematic operators
or the final bracket or the semicolon operator
@ -1950,7 +1975,11 @@ typename OperatorsTable::iterator iter_old, iter_new;
int ReadOperator(Item & result)
{
SkipWhiteCharacters();
if( *pstring == '%' )
OperatorPercentage();
if( *pstring == 0 )
return 1;
else
@ -2055,7 +2084,6 @@ uint res;
break;
default:
/*
on the stack left an unknown operator but we had to recognize its before

View File

@ -331,7 +331,8 @@ namespace ttmath
err_object_exists,
err_unknown_object,
err_still_calculating,
err_in_short_form_used_function
err_in_short_form_used_function,
err_percent_from
};