Skip to content

Commit

Permalink
Make cmp constexpr so that all <=> for fp/fp2/g1/g2 become constexpr.
Browse files Browse the repository at this point in the history
  • Loading branch information
yarkinwho committed Nov 29, 2023
1 parent 6818a31 commit 8871e5e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
15 changes: 14 additions & 1 deletion include/bls12-381/fp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,20 @@ class fp
bool isEven() const;
bool isZero() const;
bool isOne() const;
std::strong_ordering cmp(const fp& e) const;
constexpr std::strong_ordering cmp(const fp& e) const {
for(int64_t i = 5; i >= 0; i--)
{
if(d[i] < e.d[i])
{
return std::strong_ordering::less;
}
if(d[i] > e.d[i])
{
return std::strong_ordering::greater;
}
}
return std::strong_ordering::equal;
};
bool equal(const fp& e) const;
bool sign() const;

Expand Down
5 changes: 0 additions & 5 deletions src/fp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,6 @@ bool fp::isOne() const
return equal(R1);
}

std::strong_ordering fp::cmp(const fp& e) const
{
return scalar::cmp<6>(d, e.d);
}

bool fp::equal(const fp& e) const
{
return d[0] == e.d[0] && d[1] == e.d[1] && d[2] == e.d[2] && d[3] == e.d[3] && d[4] == e.d[4] && d[5] == e.d[5];
Expand Down

0 comments on commit 8871e5e

Please sign in to comment.