Modify how modulo is calculated in Normal and Scientific mode. (#412)
## Fixes #111 > The modulo operator on this calculator gives the result that is different to the most used calculators. The current `modrate` function is the equivalent of rem(...)/remainder(...), not mod(...)/modulo(...) available in some popular Math apps. ### Description of the changes: - rename `modrate` in `remrate` to be more accurate. - add `modrate`, calculating modulo similarly to Matlab, Bing, Google calculator, Maxima, Wolfram Alpha and Microsoft Excel - Add `RationalMath::Mod` using `modrate` as an alternative to `Rational::operator%` using `remrate` - Add a helper `SIGN` to retrieve the sign of a `Rational`. - modify `CalcEngine` to use `modrate` in Normal and Scientific mode and `remrate` in Programmer mode. ### How changes were validated: - manually and unit tests added
This commit is contained in:
committed by
Daniel Belcher
parent
ad25feda6b
commit
7a7ceb5888
@@ -148,6 +148,9 @@ extern PRAT rat_min_i32;
|
||||
#define LOGNUM2(pnum) ((pnum)->cdigit+(pnum)->exp)
|
||||
#define LOGRAT2(prat) (LOGNUM2((prat)->pp)-LOGNUM2((prat)->pq))
|
||||
|
||||
// SIGN returns the sign of the rational
|
||||
#define SIGN(prat) ((prat)->pp->sign*(prat)->pq->sign)
|
||||
|
||||
#if defined( DEBUG_RATPAK )
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
@@ -423,7 +426,8 @@ extern void divnumx( _Inout_ PNUMBER *pa, _In_ PNUMBER b, int32_t precision);
|
||||
extern void divrat( _Inout_ PRAT *pa, _In_ PRAT b, int32_t precision);
|
||||
extern void fracrat( _Inout_ PRAT *pa , uint32_t radix, int32_t precision);
|
||||
extern void factrat( _Inout_ PRAT *pa, uint32_t radix, int32_t precision);
|
||||
extern void modrat( _Inout_ PRAT *pa, _In_ PRAT b );
|
||||
extern void remrat(_Inout_ PRAT *pa, _In_ PRAT b);
|
||||
extern void modrat(_Inout_ PRAT *pa, _In_ PRAT b);
|
||||
extern void gcdrat( _Inout_ PRAT *pa, int32_t precision);
|
||||
extern void intrat( _Inout_ PRAT *px, uint32_t radix, int32_t precision);
|
||||
extern void mulnum( _Inout_ PNUMBER *pa, _In_ PNUMBER b, uint32_t radix);
|
||||
|
||||
Reference in New Issue
Block a user