This commit is contained in:
Avighna 2023-05-26 22:57:27 +02:00 committed by GitHub
commit af3abbf105
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 199 additions and 57 deletions

View file

@ -267,13 +267,13 @@ Rational RationalMath::ATan(Rational const& rat, AngleType angletype)
return result;
}
Rational RationalMath::Sinh(Rational const& rat)
Rational RationalMath::Sinh(Rational const& rat, AngleType angletype)
{
PRAT prat = rat.ToPRAT();
try
{
sinhrat(&prat, RATIONAL_BASE, RATIONAL_PRECISION);
sinhanglerat(&prat, angletype, RATIONAL_BASE, RATIONAL_PRECISION);
}
catch (uint32_t error)
{
@ -287,13 +287,13 @@ Rational RationalMath::Sinh(Rational const& rat)
return result;
}
Rational RationalMath::Cosh(Rational const& rat)
Rational RationalMath::Cosh(Rational const& rat, AngleType angletype)
{
PRAT prat = rat.ToPRAT();
try
{
coshrat(&prat, RATIONAL_BASE, RATIONAL_PRECISION);
coshanglerat(&prat, angletype, RATIONAL_BASE, RATIONAL_PRECISION);
}
catch (uint32_t error)
{
@ -307,13 +307,13 @@ Rational RationalMath::Cosh(Rational const& rat)
return result;
}
Rational RationalMath::Tanh(Rational const& rat)
Rational RationalMath::Tanh(Rational const& rat, AngleType angletype)
{
PRAT prat = rat.ToPRAT();
try
{
tanhrat(&prat, RATIONAL_BASE, RATIONAL_PRECISION);
tanhanglerat(&prat, angletype, RATIONAL_BASE, RATIONAL_PRECISION);
}
catch (uint32_t error)
{
@ -327,13 +327,13 @@ Rational RationalMath::Tanh(Rational const& rat)
return result;
}
Rational RationalMath::ASinh(Rational const& rat)
Rational RationalMath::ASinh(Rational const& rat, AngleType angletype)
{
PRAT prat = rat.ToPRAT();
try
{
asinhrat(&prat, RATIONAL_BASE, RATIONAL_PRECISION);
asinhanglerat(&prat, angletype, RATIONAL_BASE, RATIONAL_PRECISION);
}
catch (uint32_t error)
{
@ -347,13 +347,13 @@ Rational RationalMath::ASinh(Rational const& rat)
return result;
}
Rational RationalMath::ACosh(Rational const& rat)
Rational RationalMath::ACosh(Rational const& rat, AngleType angletype)
{
PRAT prat = rat.ToPRAT();
try
{
acoshrat(&prat, RATIONAL_BASE, RATIONAL_PRECISION);
acoshanglerat(&prat, angletype, RATIONAL_BASE, RATIONAL_PRECISION);
}
catch (uint32_t error)
{
@ -367,13 +367,13 @@ Rational RationalMath::ACosh(Rational const& rat)
return result;
}
Rational RationalMath::ATanh(Rational const& rat)
Rational RationalMath::ATanh(Rational const& rat, AngleType angletype)
{
PRAT prat = rat.ToPRAT();
try
{
atanhrat(&prat, RATIONAL_PRECISION);
atanhanglerat(&prat, angletype, RATIONAL_PRECISION);
}
catch (uint32_t error)
{

View file

@ -120,7 +120,7 @@ CalcEngine::Rational CCalcEngine::SciCalcFunctions(CalcEngine::Rational const& r
case IDC_SINH: /* Sine- hyperbolic and archyperbolic */
if (!m_fIntegerMode)
{
result = m_bInv ? ASinh(rat) : Sinh(rat);
result = m_bInv ? ASinh(rat, m_angletype) : Sinh(rat, m_angletype);
}
break;
@ -134,7 +134,7 @@ CalcEngine::Rational CCalcEngine::SciCalcFunctions(CalcEngine::Rational const& r
case IDC_COSH: /* Cosine hyperbolic, follows convention of sine h function. */
if (!m_fIntegerMode)
{
result = m_bInv ? ACosh(rat) : Cosh(rat);
result = m_bInv ? ACosh(rat, m_angletype) : Cosh(rat, m_angletype);
}
break;
@ -148,7 +148,7 @@ CalcEngine::Rational CCalcEngine::SciCalcFunctions(CalcEngine::Rational const& r
case IDC_TANH: /* Same as sine h and cosine h. */
if (!m_fIntegerMode)
{
result = m_bInv ? ATanh(rat) : Tanh(rat);
result = m_bInv ? ATanh(rat, m_angletype) : Tanh(rat, m_angletype);
}
break;
@ -176,21 +176,21 @@ CalcEngine::Rational CCalcEngine::SciCalcFunctions(CalcEngine::Rational const& r
case IDC_SECH:
if (!m_fIntegerMode)
{
result = m_bInv ? ACosh(Invert(rat)) : Invert(Cosh(rat));
result = m_bInv ? ACosh(Invert(rat), m_angletype) : Invert(Cosh(rat, m_angletype));
}
break;
case IDC_CSCH:
if (!m_fIntegerMode)
{
result = m_bInv ? ASinh(Invert(rat)) : Invert(Sinh(rat));
result = m_bInv ? ASinh(Invert(rat), m_angletype) : Invert(Sinh(rat, m_angletype));
}
break;
case IDC_COTH:
if (!m_fIntegerMode)
{
result = m_bInv ? ATanh(Invert(rat)) : Invert(Tanh(rat));
result = m_bInv ? ATanh(Invert(rat), m_angletype) : Invert(Tanh(rat, m_angletype));
}
break;

View file

@ -29,10 +29,10 @@ namespace CalcEngine::RationalMath
Rational ACos(Rational const& rat, AngleType angletype);
Rational ATan(Rational const& rat, AngleType angletype);
Rational Sinh(Rational const& rat);
Rational Cosh(Rational const& rat);
Rational Tanh(Rational const& rat);
Rational ASinh(Rational const& rat);
Rational ACosh(Rational const& rat);
Rational ATanh(Rational const& rat);
Rational Sinh(Rational const& rat, AngleType angletype);
Rational Cosh(Rational const& rat, AngleType angletype);
Rational Tanh(Rational const& rat, AngleType angletype);
Rational ASinh(Rational const& rat, AngleType angletype);
Rational ACosh(Rational const& rat, AngleType angletype);
Rational ATanh(Rational const& rat, AngleType angletype);
}

View file

@ -17,23 +17,6 @@
//-----------------------------------------------------------------------------
#include "ratpak.h"
void ascalerat(_Inout_ PRAT* pa, AngleType angletype, int32_t precision)
{
switch (angletype)
{
case AngleType::Radians:
break;
case AngleType::Degrees:
divrat(pa, two_pi, precision);
mulrat(pa, rat_360, precision);
break;
case AngleType::Gradians:
divrat(pa, two_pi, precision);
mulrat(pa, rat_400, precision);
break;
}
}
//-----------------------------------------------------------------------------
//
// FUNCTION: asinrat, _asinrat

View file

@ -85,6 +85,13 @@ void asinhrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision)
destroyrat(neg_pt_eight_five);
}
void asinhanglerat(_Inout_ PRAT* pa, AngleType angletype, uint32_t radix, int32_t precision)
{
asinhrat(pa, radix, precision);
ascalerat(pa, angletype, precision);
}
//-----------------------------------------------------------------------------
//
// FUNCTION: acoshrat
@ -121,6 +128,13 @@ void acoshrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision)
}
}
void acoshanglerat(_Inout_ PRAT* pa, AngleType angletype, uint32_t radix, int32_t precision)
{
acoshrat(pa, radix, precision);
ascalerat(pa, angletype, precision);
}
//-----------------------------------------------------------------------------
//
// FUNCTION: atanhrat
@ -151,3 +165,10 @@ void atanhrat(_Inout_ PRAT* px, int32_t precision)
divrat(px, rat_two, precision);
destroyrat(ptmp);
}
void atanhanglerat(_Inout_ PRAT* pa, AngleType angletype, int32_t precision)
{
atanhrat(pa, precision);
ascalerat(pa, angletype, precision);
}

View file

@ -373,12 +373,20 @@ extern PRAT _createrat(void);
// angle type
extern void acosanglerat(_Inout_ PRAT* px, AngleType angletype, uint32_t radix, int32_t precision);
// returns a new rat structure with the acosh of x->p/x->q taking into account
// angle type
extern void acoshanglerat(_Inout_ PRAT* pa, AngleType angletype, uint32_t radix, int32_t precision);
// returns a new rat structure with the acosh of x->p/x->q
extern void acoshrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision);
// returns a new rat structure with the acos of x->p/x->q
extern void acosrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision);
// returns a new rat structure with the asinh of x->p/x->q taking into account
// angle type
extern void asinhanglerat(_Inout_ PRAT* pa, AngleType angletype, uint32_t radix, int32_t precision);
// returns a new rat structure with the asin of x->p/x->q taking into account
// angle type
extern void asinanglerat(_Inout_ PRAT* px, AngleType angletype, uint32_t radix, int32_t precision);
@ -393,12 +401,20 @@ extern void asinrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision);
// angle type
extern void atananglerat(_Inout_ PRAT* px, AngleType angletype, uint32_t radix, int32_t precision);
// returns a new rat structure with the atanh of x->p/x->q taking into account
// angle type
extern void atanhanglerat(_Inout_ PRAT* pa, AngleType angletype, int32_t precision);
// returns a new rat structure with the atanh of x->p/x->q
extern void atanhrat(_Inout_ PRAT* px, int32_t precision);
// returns a new rat structure with the atan of x->p/x->q
extern void atanrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision);
// returns a new rat structure with the hyperbolic cosine of x->p/x->q taking into account
// angle type
extern void coshanglerat(_Inout_ PRAT* pa, AngleType angletype, uint32_t radix, int32_t precision);
// returns a new rat structure with the cosh of x->p/x->q
extern void coshrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision);
@ -425,6 +441,10 @@ extern PRAT i32torat(int32_t ini32);
extern PRAT Ui32torat(uint32_t inui32);
extern PRAT numtorat(_In_ PNUMBER pin, uint32_t radix);
// returns a new rat structure with the hyperbolic sin of x->p/x->q taking into account
// angle type
extern void sinhanglerat(_Inout_ PRAT* pa, AngleType angletype, uint32_t radix, int32_t precision);
extern void sinhrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision);
extern void sinrat(_Inout_ PRAT* px);
@ -432,6 +452,10 @@ extern void sinrat(_Inout_ PRAT* px);
// angle type
extern void sinanglerat(_Inout_ PRAT* px, AngleType angletype, uint32_t radix, int32_t precision);
// returns a new rat structure with the hyperbolic tan of x->p/x->q taking into account
// angle type
extern void tanhanglerat(_Inout_ PRAT* pa, AngleType angletype, uint32_t radix, int32_t precision);
extern void tanhrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision);
extern void tanrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision);
@ -483,3 +507,5 @@ extern void inbetween(_In_ PRAT* px, _In_ PRAT range, int32_t precision);
extern void trimit(_Inout_ PRAT* px, int32_t precision);
extern void _dumprawrat(_In_ const wchar_t* varname, _In_ PRAT rat, std::wostream& out);
extern void _dumprawnum(_In_ const wchar_t* varname, _In_ PNUMBER num, std::wostream& out);
extern void scalerat(_Inout_ PRAT* pa, AngleType angletype, uint32_t radix, int32_t precision);
extern void ascalerat(_Inout_ PRAT* pa, AngleType angletype, int32_t precision);

View file

@ -530,6 +530,39 @@ void scale2pi(_Inout_ PRAT* px, uint32_t radix, int32_t precision)
destroyrat(pret);
}
void scalerat(_Inout_ PRAT* pa, AngleType angletype, uint32_t radix, int32_t precision)
{
switch (angletype)
{
case AngleType::Radians:
scale2pi(pa, radix, precision);
break;
case AngleType::Degrees:
scale(pa, rat_360, radix, precision);
break;
case AngleType::Gradians:
scale(pa, rat_400, radix, precision);
break;
}
}
void ascalerat(_Inout_ PRAT* pa, AngleType angletype, int32_t precision)
{
switch (angletype)
{
case AngleType::Radians:
break;
case AngleType::Degrees:
divrat(pa, two_pi, precision);
mulrat(pa, rat_360, precision);
break;
case AngleType::Gradians:
divrat(pa, two_pi, precision);
mulrat(pa, rat_400, precision);
break;
}
}
//---------------------------------------------------------------------------
//
// FUNCTION: inbetween

View file

@ -16,22 +16,6 @@
#include "ratpak.h"
void scalerat(_Inout_ PRAT* pa, AngleType angletype, uint32_t radix, int32_t precision)
{
switch (angletype)
{
case AngleType::Radians:
scale2pi(pa, radix, precision);
break;
case AngleType::Degrees:
scale(pa, rat_360, radix, precision);
break;
case AngleType::Gradians:
scale(pa, rat_400, radix, precision);
break;
}
}
//-----------------------------------------------------------------------------
//
// FUNCTION: sinrat, _sinrat

View file

@ -109,6 +109,35 @@ void sinhrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision)
}
}
void sinhanglerat(_Inout_ PRAT* pa, AngleType angletype, uint32_t radix, int32_t precision)
{
if (angletype != AngleType::Radians)
{
scalerat(pa, angletype, radix, precision);
}
switch (angletype)
{
case AngleType::Degrees:
if (rat_gt(*pa, rat_180, precision))
{
subrat(pa, rat_360, precision);
}
divrat(pa, rat_180, precision);
mulrat(pa, pi, precision);
break;
case AngleType::Gradians:
if (rat_gt(*pa, rat_200, precision))
{
subrat(pa, rat_400, precision);
}
divrat(pa, rat_200, precision);
mulrat(pa, pi, precision);
break;
}
_sinhrat(pa, precision);
}
//-----------------------------------------------------------------------------
//
// FUNCTION: coshrat
@ -198,6 +227,43 @@ void coshrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision)
}
}
void coshanglerat(_Inout_ PRAT* pa, AngleType angletype, uint32_t radix, int32_t precision)
{
if (angletype != AngleType::Radians)
{
scalerat(pa, angletype, radix, precision);
}
switch (angletype)
{
case AngleType::Degrees:
if (rat_gt(*pa, rat_180, precision))
{
PRAT ptmp = nullptr;
DUPRAT(ptmp, rat_360);
subrat(&ptmp, *pa, precision);
destroyrat(*pa);
*pa = ptmp;
}
divrat(pa, rat_180, precision);
mulrat(pa, pi, precision);
break;
case AngleType::Gradians:
if (rat_gt(*pa, rat_200, precision))
{
PRAT ptmp = nullptr;
DUPRAT(ptmp, rat_400);
subrat(&ptmp, *pa, precision);
destroyrat(*pa);
*pa = ptmp;
}
divrat(pa, rat_200, precision);
mulrat(pa, pi, precision);
break;
}
_coshrat(pa, radix, precision);
}
//-----------------------------------------------------------------------------
//
// FUNCTION: tanhrat
@ -224,3 +290,32 @@ void tanhrat(_Inout_ PRAT* px, uint32_t radix, int32_t precision)
destroyrat(ptmp);
}
void tanhanglerat(_Inout_ PRAT* pa, AngleType angletype, uint32_t radix, int32_t precision)
{
if (angletype != AngleType::Radians)
{
scalerat(pa, angletype, radix, precision);
}
switch (angletype)
{
case AngleType::Degrees:
if (rat_gt(*pa, rat_180, precision))
{
subrat(pa, rat_180, precision);
}
divrat(pa, rat_180, precision);
mulrat(pa, pi, precision);
break;
case AngleType::Gradians:
if (rat_gt(*pa, rat_200, precision))
{
subrat(pa, rat_200, precision);
}
divrat(pa, rat_200, precision);
mulrat(pa, pi, precision);
break;
}
tanhrat(pa, radix, precision);
}