CalcEngine: Manage precision internally to Rational and convert functions to operator overrides (#35)
* Convert Rational::Negate to an operator override * Convert Rational::Add to + and += operator overrides. * Convert Rational::Sub to - and -= operator overrides. * Convert Rational::Div and ::Mul to use /, /=, *, *= operator overrides. * Convert Rational::Mod to use %= and % operator overrides * Convert Rational::Rsh and ::Lsh to use >>=, >>, <<=, << operator overrides * Convert Rational::And, ::Or, ::Xor to use &=, &, |=, |, ^=, ^ operator overrides * Convert Rational relational functions to operator overrides * Remove unnecessary precision arguments from Rational class and remove use of explicit Rational constructors in favor of implicit conversions for value types * Remove unnecessary precision variable from RationalMath operations * Replace unnecessary Rational::Not with Xor operation * Remove unnecessary Rational::IsZero() in favor of == 0 comparisons * Fix rounding issues in ratpak that result from using large precisions. * Move assignment stmt out of IsCurrentTooBigForTrig
This commit is contained in:
@@ -14,7 +14,6 @@
|
||||
*
|
||||
\****************************************************************************/
|
||||
|
||||
#include "scimath.h"
|
||||
#include "CCommand.h"
|
||||
#include "EngineStrings.h"
|
||||
#include "../Command.h"
|
||||
@@ -24,6 +23,7 @@
|
||||
#include "History.h" // for History Collector
|
||||
#include "CalcInput.h"
|
||||
#include "ICalcDisplay.h"
|
||||
#include "scimath.h"
|
||||
#include "Rational.h"
|
||||
|
||||
// The following are NOT real exports of CalcEngine, but for forward declarations
|
||||
|
@@ -10,6 +10,9 @@ namespace CalcEngine
|
||||
// RatPack calculations currently support up to Base64.
|
||||
inline constexpr uint32_t RATIONAL_BASE = 10;
|
||||
|
||||
// Default Precision to use for Rational calculations
|
||||
inline constexpr int32_t RATIONAL_PRECISION = 128;
|
||||
|
||||
class Rational
|
||||
{
|
||||
public:
|
||||
@@ -18,7 +21,7 @@ namespace CalcEngine
|
||||
Rational(Number const& p, Number const& q) noexcept;
|
||||
Rational(int32_t i);
|
||||
Rational(uint32_t ui);
|
||||
Rational(uint64_t ui, int32_t precision);
|
||||
Rational(uint64_t ui);
|
||||
|
||||
explicit Rational(PRAT prat) noexcept;
|
||||
PRAT ToPRAT() const;
|
||||
@@ -26,29 +29,42 @@ namespace CalcEngine
|
||||
Number const& P() const;
|
||||
Number const& Q() const;
|
||||
|
||||
Rational Negate() const;
|
||||
Rational Add(Rational const& rhs, int32_t precision) const;
|
||||
Rational Sub(Rational const& rhs, int32_t precision) const;
|
||||
Rational Mul(Rational const& rhs, int32_t precision) const;
|
||||
Rational Div(Rational const& rhs, int32_t precision) const;
|
||||
Rational Mod(Rational const& rhs) const;
|
||||
Rational operator-() const;
|
||||
Rational& operator+=(Rational const& rhs);
|
||||
Rational& operator-=(Rational const& rhs);
|
||||
Rational& operator*=(Rational const& rhs);
|
||||
Rational& operator/=(Rational const& rhs);
|
||||
Rational& operator%=(Rational const& rhs);
|
||||
|
||||
Rational Lsh(Rational const& r, int32_t precision) const;
|
||||
Rational Rsh(Rational const& r, int32_t precision) const;
|
||||
Rational& operator<<=(Rational const& rhs);
|
||||
Rational& operator>>=(Rational const& rhs);
|
||||
|
||||
Rational Not(Rational const& chopNum, int32_t precision) const;
|
||||
Rational And(Rational const& r, int32_t precision) const;
|
||||
Rational Or(Rational const& r, int32_t precision) const;
|
||||
Rational Xor(Rational const& r, int32_t precision) const;
|
||||
Rational& operator&=(Rational const& rhs);
|
||||
Rational& operator|=(Rational const& rhs);
|
||||
Rational& operator^=(Rational const& rhs);
|
||||
|
||||
bool IsZero() const;
|
||||
bool IsLess(Rational const& r, int32_t precision) const;
|
||||
bool IsLessEq(Rational const& r, int32_t precision) const;
|
||||
bool IsGreaterEq(Rational const& r, int32_t precision) const;
|
||||
bool IsEq(Rational const& r, int32_t precision) const;
|
||||
friend Rational operator+(Rational lhs, Rational const& rhs);
|
||||
friend Rational operator-(Rational lhs, Rational const& rhs);
|
||||
friend Rational operator*(Rational lhs, Rational const& rhs);
|
||||
friend Rational operator/(Rational lhs, Rational const& rhs);
|
||||
friend Rational operator%(Rational lhs, Rational const& rhs);
|
||||
|
||||
friend Rational operator<<(Rational lhs, Rational const& rhs);
|
||||
friend Rational operator>>(Rational lhs, Rational const& rhs);
|
||||
|
||||
friend Rational operator&(Rational lhs, Rational const& rhs);
|
||||
friend Rational operator|(Rational lhs, Rational const& rhs);
|
||||
friend Rational operator^(Rational lhs, Rational const& rhs);
|
||||
|
||||
friend bool operator==(Rational const& lhs, Rational const& rhs);
|
||||
friend bool operator!=(Rational const& lhs, Rational const& rhs);
|
||||
friend bool operator<(Rational const& lhs, Rational const& rhs);
|
||||
friend bool operator>(Rational const& lhs, Rational const& rhs);
|
||||
friend bool operator<=(Rational const& lhs, Rational const& rhs);
|
||||
friend bool operator>=(Rational const& lhs, Rational const& rhs);
|
||||
|
||||
std::wstring ToString(uint32_t radix, NUMOBJ_FMT format, int32_t precision) const;
|
||||
uint64_t ToUInt64_t(int32_t precision) const;
|
||||
uint64_t ToUInt64_t() const;
|
||||
|
||||
private:
|
||||
Number m_p;
|
||||
|
@@ -5,31 +5,31 @@
|
||||
|
||||
namespace CalcEngine::RationalMath
|
||||
{
|
||||
Rational Frac(Rational const& rat, int32_t precision);
|
||||
Rational Integer(Rational const& rat, int32_t precision);
|
||||
Rational Frac(Rational const& rat);
|
||||
Rational Integer(Rational const& rat);
|
||||
|
||||
Rational Pow(Rational const& base, Rational const& pow, int32_t precision);
|
||||
Rational Root(Rational const& base, Rational const& root, int32_t precision);
|
||||
Rational Fact(Rational const& rat, int32_t precision);
|
||||
Rational Pow(Rational const& base, Rational const& pow);
|
||||
Rational Root(Rational const& base, Rational const& root);
|
||||
Rational Fact(Rational const& rat);
|
||||
|
||||
Rational Exp(Rational const& rat, int32_t precision);
|
||||
Rational Log(Rational const& rat, int32_t precision);
|
||||
Rational Log10(Rational const& rat, int32_t precision);
|
||||
Rational Exp(Rational const& rat);
|
||||
Rational Log(Rational const& rat);
|
||||
Rational Log10(Rational const& rat);
|
||||
|
||||
Rational Invert(Rational const& rat, int32_t precision);
|
||||
Rational Invert(Rational const& rat);
|
||||
Rational Abs(Rational const& rat);
|
||||
|
||||
Rational Sin(Rational const& rat, ANGLE_TYPE angletype, int32_t precision);
|
||||
Rational Cos(Rational const& rat, ANGLE_TYPE angletype, int32_t precision);
|
||||
Rational Tan(Rational const& rat, ANGLE_TYPE angletype, int32_t precision);
|
||||
Rational ASin(Rational const& rat, ANGLE_TYPE angletype, int32_t precision);
|
||||
Rational ACos(Rational const& rat, ANGLE_TYPE angletype, int32_t precision);
|
||||
Rational ATan(Rational const& rat, ANGLE_TYPE angletype, int32_t precision);
|
||||
Rational Sin(Rational const& rat, ANGLE_TYPE angletype);
|
||||
Rational Cos(Rational const& rat, ANGLE_TYPE angletype);
|
||||
Rational Tan(Rational const& rat, ANGLE_TYPE angletype);
|
||||
Rational ASin(Rational const& rat, ANGLE_TYPE angletype);
|
||||
Rational ACos(Rational const& rat, ANGLE_TYPE angletype);
|
||||
Rational ATan(Rational const& rat, ANGLE_TYPE angletype);
|
||||
|
||||
Rational Sinh(Rational const& rat, int32_t precision);
|
||||
Rational Cosh(Rational const& rat, int32_t precision);
|
||||
Rational Tanh(Rational const& rat, int32_t precision);
|
||||
Rational ASinh(Rational const& rat, int32_t precision);
|
||||
Rational ACosh(Rational const& rat, int32_t precision);
|
||||
Rational ATanh(Rational const& rat, int32_t precision);
|
||||
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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user