Code cleanup and description

This commit is contained in:
uhliksk 2020-09-22 23:29:48 +02:00
commit 8d02fb828f
No known key found for this signature in database
GPG key ID: 694EC7F466459F2D
3 changed files with 23 additions and 15 deletions

View file

@ -297,7 +297,7 @@ void powrat(PRAT *px, PRAT y, uint32_t radix, int32_t precision)
}
}
void powratNumeratorDenominatorPartial(PRAT *px, PRAT y, uint32_t radix, int32_t precision)
void powratPowerOfPowers(_Inout_ PRAT* px, PRAT y, uint32_t radix, int32_t precision)
{
// Prepare rationals
PRAT yNumerator = nullptr;
@ -392,8 +392,15 @@ void powratNumeratorDenominatorPartial(PRAT *px, PRAT y, uint32_t radix, int32_t
destroyrat(pxPow);
}
void powratNumeratorDenominator(PRAT *px, PRAT y, uint32_t radix, int32_t precision)
void powratNumeratorDenominator(_Inout_ PRAT* px, PRAT y, uint32_t radix, int32_t precision)
{
// To avoid rounding calculate power of numerator and denominator separately and divide the result:
// px ^ py == (xNum ^ py) / (xDenom ^ py)
// In powratPowerOfPowers the following rule is applied:
// px ^ py == px ^ (yNum/yDenom) == px ^ yNum ^ (1/yDenom)
// Final expression is then:
// px ^ py == (xNum ^ yNum ^ (1/yDenom)) / (xDenom ^ yNum ^ (1/yDenom))
// We need px as simple as possible
gcdrat(px, precision);
@ -406,8 +413,8 @@ void powratNumeratorDenominator(PRAT *px, PRAT y, uint32_t radix, int32_t precis
DUPNUM(pxDenominator->pp, (*px)->pq);
// Calculate pow for Numerator and Denominator separately
powratNumeratorDenominatorPartial(&pxNumerator, y, radix, precision);
powratNumeratorDenominatorPartial(&pxDenominator, y, radix, precision);
powratPowerOfPowers(&pxNumerator, y, radix, precision);
powratPowerOfPowers(&pxDenominator, y, radix, precision);
// Combine results back to px
DUPRAT(*px, pxNumerator);

View file

@ -434,6 +434,7 @@ extern void numpowlongx( _Inout_ PNUMBER *proot, long power );
extern void orrat( _Inout_ PRAT *pa, _In_ PRAT b, uint32_t radix, int32_t precision);
extern void powrat( _Inout_ PRAT *pa, _In_ PRAT b , uint32_t radix, int32_t precision);
extern void powratNumeratorDenominator(_Inout_ PRAT *pa, _In_ PRAT b, uint32_t radix, int32_t precision);
extern void powratPowerOfPowers(_Inout_ PRAT* pa, _In_ PRAT b, uint32_t radix, int32_t precision);
extern void powratcomp(_Inout_ PRAT *pa, _In_ PRAT b, uint32_t radix, int32_t precision);
extern void ratpowlong( _Inout_ PRAT *proot, long power, int32_t precision);
extern void remnum( _Inout_ PNUMBER *pa, _In_ PNUMBER b, uint32_t radix);