Skip to content

Commit

Permalink
Use class constants
Browse files Browse the repository at this point in the history
  • Loading branch information
TLCFEM committed May 12, 2024
1 parent 2e4156d commit 67ac71f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 10 additions & 7 deletions src/Gauss.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@

using namespace mpfr;

inline mpreal MP_PI = [] {
mpreal::set_default_prec(512);
return const_pi();
}();
inline mpreal MP_PI = const_pi();
inline mpreal MP_PI_HALF{MP_PI / 2};
extern int DIGIT;

class Evaluation {
const mpreal ONE = mpreal(1, DIGIT);
const mpreal TWO = mpreal(2, DIGIT);

const size_t degree;

mpreal _x, _v, _d;
Expand All @@ -52,13 +52,13 @@ class Evaluation {
mpreal left{x}, right{1, DIGIT};

for(size_t i = 2; i <= degree; ++i) {
this->_v = ((mpreal(2, DIGIT) * i - mpreal(1, DIGIT)) * x * left - (i - mpreal(1, DIGIT)) * right) / i;
this->_v = ((TWO * i - ONE) * x * left - (i - ONE) * right) / i;

right = left;
left = this->_v;
}

this->_d = degree / (x * x - mpreal(1, DIGIT)) * (x * this->_v - right);
this->_d = degree / (x * x - ONE) * (x * this->_v - right);
}

[[nodiscard]] mpreal v() const { return this->_v; }
Expand All @@ -69,6 +69,9 @@ class Evaluation {
};

class LegendrePolynomial {
const mpreal ONE = mpreal(1, DIGIT);
const mpreal TWO = mpreal(2, DIGIT);

public:
const size_t degree;

Expand All @@ -91,7 +94,7 @@ class LegendrePolynomial {
while(abs(dr) > std::numeric_limits<mpreal>::epsilon());

this->_r[i] = eval.x();
this->_w[i] = mpreal(2, DIGIT) / ((mpreal(1, DIGIT) - eval.x() * eval.x()) * eval.d() * eval.d());
this->_w[i] = TWO / ((ONE - eval.x() * eval.x()) * eval.d() * eval.d());
});

tbb::parallel_for(degree / 2, degree, [&](const size_t i) {
Expand Down
2 changes: 1 addition & 1 deletion src/VPMR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ int main(const int argc, const char** argv) {

TOL.setPrecision(DIGIT);

MP_PI = const_pi(2 * DIGIT);
MP_PI = const_pi(DIGIT);
MP_PI_HALF = MP_PI / 2;

TOL /= 2;
Expand Down

0 comments on commit 67ac71f

Please sign in to comment.