From 61886fc82919bc01c02c08a5ac3bc0396134c123 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Sun, 4 Nov 2007 21:56:04 +0000 Subject: [PATCH] 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 --- ttmath/ttmathbig.h | 51 ++++++++++++++++++++++++++++++++++++++++++- ttmath/ttmathparser.h | 31 ++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-) diff --git a/ttmath/ttmathbig.h b/ttmath/ttmathbig.h index 43a596b..e216a95 100644 --- a/ttmath/ttmathbig.h +++ b/ttmath/ttmathbig.h @@ -1501,10 +1501,38 @@ public: /*! * - * convertion method + * convertion methods * */ + + /*! + converting from another type of a Big object + */ + template + uint FromBig(const Big & 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' to this class + */ + template + Big & operator=(const Big & value) + { + FromBig(value); + + return *this; + } + + + /*! + a constructor for converting from 'Big' to this class + */ + template + Big(const Big & value) + { + FromBig(value); + } + /*! a default constructor diff --git a/ttmath/ttmathparser.h b/ttmath/ttmathparser.h index e0bdc83..dfacefa 100644 --- a/ttmath/ttmathparser.h +++ b/ttmath/ttmathparser.h @@ -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::BitAnd); InsertFunctionToTable(std::string("bor"), &Parser::BitOr); InsertFunctionToTable(std::string("bxor"), &Parser::BitXor); + InsertFunctionToTable(std::string("sum"), &Parser::Sum); + InsertFunctionToTable(std::string("avg"), &Parser::Avg); }