CGAL 6.3-dev - Number Types
Loading...
Searching...
No Matches
CGAL::Zp< p, T, IsPrime > Class Template Reference

#include <CGAL/Zp.h>

Definition

template<std::size_t p, typename T = unsigned int, bool IsPrime = true>
class CGAL::Zp< p, T, IsPrime >

The class Zp implements the concept IntegralDomainWithoutDivision with the ring \(\mathbb Z/p\mathbb Z\) (which is a field when p is prime).

This is a "lightweight" implementation which aims at providing fast operations and constructors.

According to the value of p, users can chose the size of the representation used to store values (default size: int).

Warning
For \(\mathbb Z/2\mathbb Z\), prefer the class Z2 which is optimized.
Is model of
IntegralDomainWithoutDivision
Template Parameters
pa positive integer.
Ta type used for the inner storage of the values (default: int).
IsPrimea bool encoding wether p is a prime number or not.

Public Member Functions

 Zp (T i=0)
 Constructor from a value.
 Zp (const Zp &a)
T operator() ()
 Returns the value of p.
bool is_zero () const
 Tests if the element is 0.
Zp & operator= (const Zp &a)
 Operator=.
bool operator< (const Zp &a)
 Comparison operator.
Zp & operator+= (const Zp &a)
 Operator+=.
Zp & operator-= (const Zp &a)
 Operator-=.
Zp & operator*= (const Zp &a)
 Operator*=.
Zp & operator/= (const Zp &a)
 Operator/=.
Zp power (size_t n) const
 Computes the nth power of the element.
bool is_invertible () const
 Returns the invertibility of the element.
Zp inverse () const
 For invertible values, returns the inverse.

Friends

Zp operator+ (const Zp &a)
 Unary operator+.
Zp operator- (const Zp &a)
 Unary operator-.
Zp operator+ (const Zp &a, const Zp &b)
 Operator+.
Zp operator- (const Zp &a, const Zp &b)
 Operator-.
Zp operator* (const Zp &a, const Zp &b)
 Operator*.
Zp operator/ (const Zp &a, const Zp &b)
 Operator/.
bool operator== (const Zp &a, const Zp &b)
 Operator==.
bool operator!= (const Zp &a, const Zp &b)
 Operator!=.
Zp abs (const Zp &a)
 Absolute value.
std::ostream & operator<< (std::ostream &out, const Zp &a)
 Operator<<.
std::istream & operator>> (std::istream &in, Zp &a)
 Operator>>.

Member Function Documentation

◆ power()

template<std::size_t p, typename T = unsigned int, bool IsPrime = true>
Zp CGAL::Zp< p, T, IsPrime >::power ( size_t n) const

Computes the nth power of the element.

Computation is based on iterated squares (complexity \(\mathcal O(\log n)\)).