changed: small changes in: Big::SetPi(), Big::Set05Pi(), Big::Set2Pi(),
Big::ChangeSign() added: ASinh(), ACosh(), ATanh() /ATgh()/, ACoth() /ACtgh()/ and to the parser as well git-svn-id: svn://ttmath.org/publicrep/ttmath/trunk@35 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
0170572f84
commit
062881900a
167
ttmath/ttmath.h
167
ttmath/ttmath.h
|
@ -1171,6 +1171,173 @@ namespace ttmath
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* inverse hyperbolic functions
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/*!
|
||||
inverse hyperbolic sine
|
||||
|
||||
asinh(x) = ln( x + sqrt(x^2 + 1) )
|
||||
*/
|
||||
template<class ValueType>
|
||||
ValueType ASinh(const ValueType & x, ErrorCode * err = 0)
|
||||
{
|
||||
ValueType xx(x), one, result;
|
||||
uint c = 0;
|
||||
one.SetOne();
|
||||
|
||||
c += xx.Mul(x);
|
||||
c += xx.Add(one);
|
||||
one.exponent.SubOne(); // one=0.5
|
||||
// xx is >= 1
|
||||
c += xx.PowFrac(one); // xx=sqrt(xx)
|
||||
c += xx.Add(x);
|
||||
c += result.Ln(xx); // xx > 0
|
||||
|
||||
// here can only be a carry
|
||||
if( err )
|
||||
*err = c ? err_overflow : err_ok;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
inverse hyperbolic cosine
|
||||
|
||||
acosh(x) = ln( x + sqrt(x^2 - 1) ) x in <1, infinity)
|
||||
*/
|
||||
template<class ValueType>
|
||||
ValueType ACosh(const ValueType & x, ErrorCode * err = 0)
|
||||
{
|
||||
ValueType xx(x), one, result;
|
||||
uint c = 0;
|
||||
one.SetOne();
|
||||
|
||||
if( x < one )
|
||||
{
|
||||
if( err )
|
||||
*err = err_improper_argument;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
c += xx.Mul(x);
|
||||
c += xx.Sub(one);
|
||||
// xx is >= 0
|
||||
// we can't call a PowFrac when the 'x' is zero
|
||||
// if x is 0 the sqrt(0) is 0
|
||||
if( !xx.IsZero() )
|
||||
{
|
||||
one.exponent.SubOne(); // one=0.5
|
||||
c += xx.PowFrac(one); // xx=sqrt(xx)
|
||||
}
|
||||
c += xx.Add(x);
|
||||
c += result.Ln(xx); // xx >= 1
|
||||
|
||||
// here can only be a carry
|
||||
if( err )
|
||||
*err = c ? err_overflow : err_ok;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
inverse hyperbolic tangent
|
||||
|
||||
atanh(x) = 0.5 * ln( (1+x) / (1-x) ) x in (-1, 1)
|
||||
*/
|
||||
template<class ValueType>
|
||||
ValueType ATanh(const ValueType & x, ErrorCode * err = 0)
|
||||
{
|
||||
ValueType nominator(x), denominator, one, result;
|
||||
uint c = 0;
|
||||
one.SetOne();
|
||||
|
||||
if( !x.SmallerWithoutSignThan(one) )
|
||||
{
|
||||
if( err )
|
||||
*err = err_improper_argument;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
c += nominator.Add(one);
|
||||
denominator = one;
|
||||
c += denominator.Sub(x);
|
||||
c += nominator.Div(denominator);
|
||||
c += result.Ln(nominator);
|
||||
c += result.exponent.SubOne();
|
||||
|
||||
// here can only be a carry
|
||||
if( err )
|
||||
*err = c ? err_overflow : err_ok;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
inverse hyperbolic tantent
|
||||
*/
|
||||
template<class ValueType>
|
||||
ValueType ATgh(const ValueType & x, ErrorCode * err = 0)
|
||||
{
|
||||
return ATanh(x, err);
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
inverse hyperbolic cotangent
|
||||
|
||||
acoth(x) = 0.5 * ln( (x+1) / (x-1) ) x in (-infinity, -1) or (1, infinity)
|
||||
*/
|
||||
template<class ValueType>
|
||||
ValueType ACoth(const ValueType & x, ErrorCode * err = 0)
|
||||
{
|
||||
ValueType nominator(x), denominator(x), one, result;
|
||||
uint c = 0;
|
||||
one.SetOne();
|
||||
|
||||
if( !x.GreaterWithoutSignThan(one) )
|
||||
{
|
||||
if( err )
|
||||
*err = err_improper_argument;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
c += nominator.Add(one);
|
||||
c += denominator.Sub(one);
|
||||
c += nominator.Div(denominator);
|
||||
c += result.Ln(nominator);
|
||||
c += result.exponent.SubOne();
|
||||
|
||||
// here can only be a carry
|
||||
if( err )
|
||||
*err = c ? err_overflow : err_ok;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
inverse hyperbolic cotantent
|
||||
*/
|
||||
template<class ValueType>
|
||||
ValueType ACtgh(const ValueType & x, ErrorCode * err = 0)
|
||||
{
|
||||
return ACoth(x, err);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
|
|
@ -182,10 +182,13 @@ public:
|
|||
}
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
/*!
|
||||
it sets value pi
|
||||
sets the mantissa of the value pi
|
||||
*/
|
||||
void SetPi()
|
||||
void SetMantissaPi()
|
||||
{
|
||||
// this is a static table which represents the value Pi (mantissa of it)
|
||||
// (first is the highest word)
|
||||
|
@ -223,8 +226,19 @@ public:
|
|||
// and on 64bit platform value 64 (128/2=64))
|
||||
|
||||
mantissa.SetFromTable(temp_table, sizeof(temp_table) / sizeof(int));
|
||||
exponent = -sint(man)*sint(TTMATH_BITS_PER_UINT) + 2;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
|
||||
/*!
|
||||
sets the value of pi
|
||||
*/
|
||||
void SetPi()
|
||||
{
|
||||
SetMantissaPi();
|
||||
info = 0;
|
||||
exponent = -sint(man)*sint(TTMATH_BITS_PER_UINT) + 2;
|
||||
}
|
||||
|
||||
|
||||
|
@ -233,7 +247,8 @@ public:
|
|||
*/
|
||||
void Set05Pi()
|
||||
{
|
||||
SetPi();
|
||||
SetMantissaPi();
|
||||
info = 0;
|
||||
exponent = -sint(man)*sint(TTMATH_BITS_PER_UINT) + 1;
|
||||
}
|
||||
|
||||
|
@ -243,7 +258,8 @@ public:
|
|||
*/
|
||||
void Set2Pi()
|
||||
{
|
||||
SetPi();
|
||||
SetMantissaPi();
|
||||
info = 0;
|
||||
exponent = -sint(man)*sint(TTMATH_BITS_PER_UINT) + 3;
|
||||
}
|
||||
|
||||
|
@ -495,10 +511,16 @@ public:
|
|||
*/
|
||||
void ChangeSign()
|
||||
{
|
||||
if( info & TTMATH_BIG_SIGN )
|
||||
{
|
||||
info &= ~TTMATH_BIG_SIGN;
|
||||
return;
|
||||
}
|
||||
|
||||
if( IsZero() )
|
||||
return;
|
||||
|
||||
info = (info & (~TTMATH_BIG_SIGN)) | ((~info) & TTMATH_BIG_SIGN);
|
||||
info |= TTMATH_BIG_SIGN;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1043,6 +1043,60 @@ void Root(int sindex, int amount_of_args, ValueType & result)
|
|||
Error( err );
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ASinh(int sindex, int amount_of_args, ValueType & result)
|
||||
{
|
||||
if( amount_of_args != 1 )
|
||||
Error( err_improper_amount_of_arguments );
|
||||
|
||||
ErrorCode err;
|
||||
result = ttmath::ASinh(stack[sindex].value, &err);
|
||||
|
||||
if( err != err_ok )
|
||||
Error( err );
|
||||
}
|
||||
|
||||
|
||||
void ACosh(int sindex, int amount_of_args, ValueType & result)
|
||||
{
|
||||
if( amount_of_args != 1 )
|
||||
Error( err_improper_amount_of_arguments );
|
||||
|
||||
ErrorCode err;
|
||||
result = ttmath::ACosh(stack[sindex].value, &err);
|
||||
|
||||
if( err != err_ok )
|
||||
Error( err );
|
||||
}
|
||||
|
||||
|
||||
void ATanh(int sindex, int amount_of_args, ValueType & result)
|
||||
{
|
||||
if( amount_of_args != 1 )
|
||||
Error( err_improper_amount_of_arguments );
|
||||
|
||||
ErrorCode err;
|
||||
result = ttmath::ATanh(stack[sindex].value, &err);
|
||||
|
||||
if( err != err_ok )
|
||||
Error( err );
|
||||
}
|
||||
|
||||
|
||||
void ACoth(int sindex, int amount_of_args, ValueType & result)
|
||||
{
|
||||
if( amount_of_args != 1 )
|
||||
Error( err_improper_amount_of_arguments );
|
||||
|
||||
ErrorCode err;
|
||||
result = ttmath::ACoth(stack[sindex].value, &err);
|
||||
|
||||
if( err != err_ok )
|
||||
Error( err );
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
this method returns the value from a user-defined function
|
||||
|
||||
|
@ -1192,6 +1246,12 @@ void CreateFunctionsTable()
|
|||
InsertFunctionToTable(std::string("coth"), &Parser<ValueType>::Coth);
|
||||
InsertFunctionToTable(std::string("ctgh"), &Parser<ValueType>::Coth);
|
||||
InsertFunctionToTable(std::string("root"), &Parser<ValueType>::Root);
|
||||
InsertFunctionToTable(std::string("asinh"), &Parser<ValueType>::ASinh);
|
||||
InsertFunctionToTable(std::string("acosh"), &Parser<ValueType>::ACosh);
|
||||
InsertFunctionToTable(std::string("atanh"), &Parser<ValueType>::ATanh);
|
||||
InsertFunctionToTable(std::string("atgh"), &Parser<ValueType>::ATanh);
|
||||
InsertFunctionToTable(std::string("acoth"), &Parser<ValueType>::ACoth);
|
||||
InsertFunctionToTable(std::string("actgh"), &Parser<ValueType>::ACoth);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue