Skip to content

Commit

Permalink
Try to work around constexpr limits
Browse files Browse the repository at this point in the history
  • Loading branch information
randombit committed Jul 16, 2024
1 parent 3b11f09 commit 63940fd
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/lib/math/pcurves/pcurves_impl/pcurves_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,13 @@ class AffineCurvePoint {
FieldElement m_y;
};

template <typename FE>
const FE& inv_2() {
// TODO could be a constexpr, but some compilers get cranky
static const FE INV_2 = FE::from_word(2).invert();
return INV_2;
}

template <typename FieldElement, typename Params>
class ProjectiveCurvePoint {
public:
Expand All @@ -538,8 +545,6 @@ class ProjectiveCurvePoint {
// recreate it here from the words.
static constexpr FieldElement A = FieldElement::from_words(Params::AW);

static constexpr FieldElement INV_2 = FieldElement::from_word(2).invert();

static constexpr bool A_is_zero = A.is_zero().as_bool();
static constexpr bool A_is_minus_3 = (A == FieldElement::constant(-3)).as_bool();

Expand Down Expand Up @@ -733,7 +738,7 @@ class ProjectiveCurvePoint {
w *= ny4;
}
}
ny *= Self::INV_2;
ny *= inv_2<FieldElement>();
return Self(nx, ny, nz);
} else {
Self pt = (*this);
Expand Down

0 comments on commit 63940fd

Please sign in to comment.