added: Big::Mod - the remainder from a division
added: Big::Sgn - the 'sign' from the value (-1,0,1) added: global functions Mod and Sgn too git-svn-id: svn://ttmath.org/publicrep/ttmath/trunk@19 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
e14e65002b
commit
1a12d3692a
|
@ -1,6 +1,6 @@
|
||||||
Version 0.7.1 (2007.02.27):
|
Version 0.7.1 (2007.02.27):
|
||||||
* fixed the error 'overflow during printing' which was caused by Big::FromInt(Int<int_size> value)
|
* fixed the error 'overflow during printing' which was caused
|
||||||
(the sign has to be set at the end)
|
by Big::FromInt(Int<int_size> value) (the sign has to be set at the end)
|
||||||
* fixed many small errors
|
* fixed many small errors
|
||||||
* added ATan (arctan), ACTan (arc ctan) functions
|
* added ATan (arctan), ACTan (arc ctan) functions
|
||||||
|
|
||||||
|
|
2
TODO
2
TODO
|
@ -1,7 +1,7 @@
|
||||||
TODO TTMath Library
|
TODO TTMath Library
|
||||||
===================
|
===================
|
||||||
|
|
||||||
* to add the method Mod (a remainder from a division) for the Big type
|
|
||||||
* to add operators (or functions) and, or, xor
|
* to add operators (or functions) and, or, xor
|
||||||
* to add functions for generating random values
|
* to add functions for generating random values
|
||||||
* to add constructors (UInt, Int) for 64bit platforms (constractors which take int and unsigned)
|
* to add constructors (UInt, Int) for 64bit platforms (constractors which take int and unsigned)
|
||||||
|
* to add 'history' for functions like 'factorial' which take a lot of time during calculating
|
||||||
|
|
|
@ -133,7 +133,40 @@ namespace ttmath
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
it returns the sign of the value
|
||||||
|
e.g. -2 = 1
|
||||||
|
0 = 0
|
||||||
|
10 = 1
|
||||||
|
*/
|
||||||
|
template<class ValueType>
|
||||||
|
ValueType Sgn(ValueType x)
|
||||||
|
{
|
||||||
|
x.Sgn();
|
||||||
|
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
the remainder from the division
|
||||||
|
|
||||||
|
e.g.
|
||||||
|
mod( 12.6 ; 3) = 0.6 because 12.6 = 3*4 + 0.6
|
||||||
|
mod(-12.6 ; 3) = -0.6
|
||||||
|
mod( 12.6 ; -3) = 0.6
|
||||||
|
mod(-12.6 ; -3) = -0.6
|
||||||
|
*/
|
||||||
|
template<class ValueType>
|
||||||
|
ValueType Mod(ValueType a, const ValueType & b)
|
||||||
|
{
|
||||||
|
a.Mod(b);
|
||||||
|
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
this method skips the fraction from x
|
this method skips the fraction from x
|
||||||
e.g 2.2 = 2
|
e.g 2.2 = 2
|
||||||
|
|
|
@ -348,6 +348,28 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
it remains the 'sign' of the value
|
||||||
|
e.g. -2 = 1
|
||||||
|
0 = 0
|
||||||
|
10 = 1
|
||||||
|
*/
|
||||||
|
void Sgn()
|
||||||
|
{
|
||||||
|
if( IsSign() )
|
||||||
|
{
|
||||||
|
SetOne();
|
||||||
|
SetSign();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if( IsZero() )
|
||||||
|
SetZero();
|
||||||
|
else
|
||||||
|
SetOne();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
it sets the sign
|
it sets the sign
|
||||||
|
|
||||||
|
@ -569,6 +591,36 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
the remainder from the division
|
||||||
|
|
||||||
|
e.g.
|
||||||
|
12.6 mod 3 = 0.6 because 12.6 = 3*4 + 0.6
|
||||||
|
-12.6 mod 3 = -0.6
|
||||||
|
12.6 mod -3 = 0.6
|
||||||
|
-12.6 mod -3 = -0.6
|
||||||
|
|
||||||
|
it means:
|
||||||
|
in other words: this(old) = ss2 * q + this(new)(result)
|
||||||
|
*/
|
||||||
|
uint Mod(const Big<exp, man> & ss2)
|
||||||
|
{
|
||||||
|
TTMATH_REFERENCE_ASSERT( ss2 )
|
||||||
|
|
||||||
|
uint c = 0;
|
||||||
|
|
||||||
|
Big<exp, man> temp(*this);
|
||||||
|
|
||||||
|
c += temp.Div(ss2);
|
||||||
|
temp.SkipFraction();
|
||||||
|
c += temp.Mul(ss2);
|
||||||
|
c += Sub(temp);
|
||||||
|
|
||||||
|
return (c==0)? 0 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
power this = this ^ pow
|
power this = this ^ pow
|
||||||
pow without a sign
|
pow without a sign
|
||||||
|
|
|
@ -748,6 +748,32 @@ void ACTan(int sindex, int amount_of_args, ValueType & result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Sgn(int sindex, int amount_of_args, ValueType & result)
|
||||||
|
{
|
||||||
|
if( amount_of_args != 1 )
|
||||||
|
Error( err_improper_amount_of_arguments );
|
||||||
|
|
||||||
|
result = ttmath::Sgn(stack[sindex].value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Mod(int sindex, int amount_of_args, ValueType & result)
|
||||||
|
{
|
||||||
|
if( amount_of_args != 2 )
|
||||||
|
Error( err_improper_amount_of_arguments );
|
||||||
|
|
||||||
|
if( stack[sindex+2].value.IsZero() )
|
||||||
|
Error( err_improper_argument );
|
||||||
|
|
||||||
|
result = stack[sindex].value;
|
||||||
|
uint c = result.Mod(stack[sindex+2].value);
|
||||||
|
|
||||||
|
if( c )
|
||||||
|
Error( err_overflow );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
this method returns the value from a user-defined function
|
this method returns the value from a user-defined function
|
||||||
|
|
||||||
|
@ -874,6 +900,8 @@ void CreateFunctionsTable()
|
||||||
InsertFunctionToTable(std::string("acos"), &Parser<ValueType>::ACos);
|
InsertFunctionToTable(std::string("acos"), &Parser<ValueType>::ACos);
|
||||||
InsertFunctionToTable(std::string("atan"), &Parser<ValueType>::ATan);
|
InsertFunctionToTable(std::string("atan"), &Parser<ValueType>::ATan);
|
||||||
InsertFunctionToTable(std::string("actan"), &Parser<ValueType>::ACTan);
|
InsertFunctionToTable(std::string("actan"), &Parser<ValueType>::ACTan);
|
||||||
|
InsertFunctionToTable(std::string("sgn"), &Parser<ValueType>::Sgn);
|
||||||
|
InsertFunctionToTable(std::string("mod"), &Parser<ValueType>::Mod);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1728,8 +1756,6 @@ ErrorCode Parse(const char * str)
|
||||||
|
|
||||||
stack.resize( default_stack_size );
|
stack.resize( default_stack_size );
|
||||||
|
|
||||||
// char buf_temp[] = "-(1)";
|
|
||||||
// pstring = buf_temp;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue