added: Big::FromBig() and an operator= and a contructor
for converting from another kind of a Big class added: to the parser: avg(), sum() git-svn-id: svn://ttmath.org/publicrep/ttmath/trunk@56 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
25f876762a
commit
61886fc829
|
@ -1501,10 +1501,38 @@ public:
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
*
|
*
|
||||||
* convertion method
|
* convertion methods
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
converting from another type of a Big object
|
||||||
|
*/
|
||||||
|
template<uint another_exp, uint another_man>
|
||||||
|
uint FromBig(const Big<another_exp, another_man> & another)
|
||||||
|
{
|
||||||
|
info = another.info;
|
||||||
|
|
||||||
|
if( exponent.FromInt(another.exponent) )
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
uint man_len_min = (man < another_man)? man : another_man;
|
||||||
|
uint i;
|
||||||
|
|
||||||
|
for( i = 0 ; i<man_len_min ; ++i )
|
||||||
|
mantissa.table[man-1-i] = another.mantissa.table[another_man-1-i];
|
||||||
|
|
||||||
|
for( ; i<man ; ++i )
|
||||||
|
mantissa.table[man-1-i] = 0;
|
||||||
|
|
||||||
|
// mantissa is standardized
|
||||||
|
//c += Standardizing();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
this method sets 'result' as the one word of type uint
|
this method sets 'result' as the one word of type uint
|
||||||
|
|
||||||
|
@ -2258,6 +2286,27 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
an operator= for converting from 'Big<another_exp, another_man>' to this class
|
||||||
|
*/
|
||||||
|
template<uint another_exp, uint another_man>
|
||||||
|
Big<exp,man> & operator=(const Big<another_exp, another_man> & value)
|
||||||
|
{
|
||||||
|
FromBig(value);
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
a constructor for converting from 'Big<another_exp, another_man>' to this class
|
||||||
|
*/
|
||||||
|
template<uint another_exp, uint another_man>
|
||||||
|
Big(const Big<another_exp, another_man> & value)
|
||||||
|
{
|
||||||
|
FromBig(value);
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
a default constructor
|
a default constructor
|
||||||
|
|
||||||
|
|
|
@ -1158,6 +1158,35 @@ void BitXor(int sindex, int amount_of_args, ValueType & result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Sum(int sindex, int amount_of_args, ValueType & result)
|
||||||
|
{
|
||||||
|
if( amount_of_args == 0 )
|
||||||
|
Error( err_improper_amount_of_arguments );
|
||||||
|
|
||||||
|
result = stack[sindex].value;
|
||||||
|
|
||||||
|
for(int i=1 ; i<amount_of_args ; ++i )
|
||||||
|
if( result.Add( stack[ sindex + i*2 ].value ) )
|
||||||
|
Error( err_overflow );
|
||||||
|
}
|
||||||
|
|
||||||
|
void Avg(int sindex, int amount_of_args, ValueType & result)
|
||||||
|
{
|
||||||
|
if( amount_of_args == 0 )
|
||||||
|
Error( err_improper_amount_of_arguments );
|
||||||
|
|
||||||
|
result = stack[sindex].value;
|
||||||
|
|
||||||
|
for(int i=1 ; i<amount_of_args ; ++i )
|
||||||
|
if( result.Add( stack[ sindex + i*2 ].value ) )
|
||||||
|
Error( err_overflow );
|
||||||
|
|
||||||
|
if( result.Div( amount_of_args ) )
|
||||||
|
Error( err_overflow );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
this method returns the value from a user-defined function
|
this method returns the value from a user-defined function
|
||||||
|
|
||||||
|
@ -1319,6 +1348,8 @@ void CreateFunctionsTable()
|
||||||
InsertFunctionToTable(std::string("band"), &Parser<ValueType>::BitAnd);
|
InsertFunctionToTable(std::string("band"), &Parser<ValueType>::BitAnd);
|
||||||
InsertFunctionToTable(std::string("bor"), &Parser<ValueType>::BitOr);
|
InsertFunctionToTable(std::string("bor"), &Parser<ValueType>::BitOr);
|
||||||
InsertFunctionToTable(std::string("bxor"), &Parser<ValueType>::BitXor);
|
InsertFunctionToTable(std::string("bxor"), &Parser<ValueType>::BitXor);
|
||||||
|
InsertFunctionToTable(std::string("sum"), &Parser<ValueType>::Sum);
|
||||||
|
InsertFunctionToTable(std::string("avg"), &Parser<ValueType>::Avg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue