rego-cpp 1.0.0
A C++ implementation of the Rego language and runtime
Loading...
Searching...
No Matches
rego::BigInt Class Reference

Big Integer implemention based on strings. More...

#include <rego.hh>

Public Member Functions

 BigInt ()
 Default constructor, initializes to zero.
 
 BigInt (const Location &value)
 Constructs a BigInt from a Location representing a arbitrary precision integer string.
 
 BigInt (std::int64_t value)
 Constructs a BigInt from a 64-bit integer.
 
 BigInt (std::size_t value)
 Constructs a BigInt from a size_t integer.
 
const Location & loc () const
 Gets the Location representing the integer string.
 
std::optional< std::int64_t > to_int () const
 Attempts to convert the BigInt to a 64-bit integer.
 
std::optional< std::size_t > to_size () const
 Attempts to convert the BigInt to a size_t integer.
 
bool is_negative () const
 Checks if the BigInt is negative.
 
bool is_zero () const
 Checks if the BigInt is zero.
 
BigInt increment () const
 Increments the BigInt by one.
 
BigInt decrement () const
 Decrements the BigInt by one.
 
BigInt abs () const
 Gets the absolute value of the BigInt.
 
BigInt negate () const
 Negates the BigInt.
 

Static Public Member Functions

static bool is_int (const Location &loc)
 Checks if a Location represents a valid integer string.
 

Friends

BigInt operator+ (const BigInt &lhs, const BigInt &rhs)
 Adds two BigInts.
 
BigInt operator- (const BigInt &lhs, const BigInt &rhs)
 Subtracts two BigInts.
 
BigInt operator* (const BigInt &lhs, const BigInt &rhs)
 Multiplies two BigInts.
 
BigInt operator/ (const BigInt &lhs, const BigInt &rhs)
 Divides two BigInts.
 
BigInt operator% (const BigInt &lhs, const BigInt &rhs)
 Computes the remainder of dividing two BigInts.
 
bool operator> (const BigInt &lhs, const BigInt &rhs)
 Compares two BigInts for greater-than.
 
bool operator< (const BigInt &lhs, const BigInt &rhs)
 Compares two BigInts for less-than.
 
bool operator<= (const BigInt &lhs, const BigInt &rhs)
 Compares two BigInts for less-than-or-equal.
 
bool operator>= (const BigInt &lhs, const BigInt &rhs)
 Compares two BigInts for greater-than-or-equal.
 
bool operator== (const BigInt &lhs, const BigInt &rhs)
 Compares two BigInts for equality.
 
bool operator!= (const BigInt &lhs, const BigInt &rhs)
 Compares two BigInts for inequality.
 
std::ostream & operator<< (std::ostream &os, const BigInt &value)
 Outputs a BigInt to a stream.
 

Detailed Description

Big Integer implemention based on strings.

using strings. In most circumstances this would be considerably slower than other approaches, but given the way in which Trieste nodes store their content as Location objects into a source document, and given how this class operates over those Locations, it is actually quite efficient when compared to parsing and serializing the Location into a vector of unsigned longs.

Constructor & Destructor Documentation

◆ BigInt() [1/3]

rego::BigInt::BigInt ( const Location & value)

Constructs a BigInt from a Location representing a arbitrary precision integer string.

Parameters
valueThe Location to construct from.

◆ BigInt() [2/3]

rego::BigInt::BigInt ( std::int64_t value)

Constructs a BigInt from a 64-bit integer.

Parameters
valueThe 64-bit integer to construct from.

◆ BigInt() [3/3]

rego::BigInt::BigInt ( std::size_t value)

Constructs a BigInt from a size_t integer.

Parameters
valueThe size_t integer to construct from.

Member Function Documentation

◆ abs()

BigInt rego::BigInt::abs ( ) const

Gets the absolute value of the BigInt.

Returns
A new BigInt representing the absolute value.

◆ decrement()

BigInt rego::BigInt::decrement ( ) const

Decrements the BigInt by one.

Returns
A new BigInt representing the decremented value.

◆ increment()

BigInt rego::BigInt::increment ( ) const

Increments the BigInt by one.

Returns
A new BigInt representing the incremented value.

◆ is_int()

static bool rego::BigInt::is_int ( const Location & loc)
static

Checks if a Location represents a valid integer string.

Parameters
locThe Location to check.
Returns
True if the Location represents a valid integer string, false otherwise.

◆ is_negative()

bool rego::BigInt::is_negative ( ) const

Checks if the BigInt is negative.

Returns
True if the BigInt is negative, false otherwise.

◆ is_zero()

bool rego::BigInt::is_zero ( ) const

Checks if the BigInt is zero.

Returns
True if the BigInt is zero, false otherwise.

◆ loc()

const Location & rego::BigInt::loc ( ) const

Gets the Location representing the integer string.

Returns
The Location representing the integer string.

◆ negate()

BigInt rego::BigInt::negate ( ) const

Negates the BigInt.

Returns
A new BigInt representing the negated value.

◆ to_int()

std::optional< std::int64_t > rego::BigInt::to_int ( ) const

Attempts to convert the BigInt to a 64-bit integer.

Returns
The 64-bit integer representation of the BigInt, or std::nullopt if out of range.

◆ to_size()

std::optional< std::size_t > rego::BigInt::to_size ( ) const

Attempts to convert the BigInt to a size_t integer.

Returns
The size_t integer representation of the BigInt, or std::nullopt if out of range.

Friends And Related Symbol Documentation

◆ operator!=

bool operator!= ( const BigInt & lhs,
const BigInt & rhs )
friend

Compares two BigInts for inequality.

Parameters
lhsThe left-hand side operand.
rhsThe right-hand side operand.
Returns
True if lhs is not equal to rhs, false otherwise.

◆ operator%

BigInt operator% ( const BigInt & lhs,
const BigInt & rhs )
friend

Computes the remainder of dividing two BigInts.

Parameters
lhsThe left-hand side operand.
rhsThe right-hand side operand.
Returns
The remainder of the two BigInts.

◆ operator*

BigInt operator* ( const BigInt & lhs,
const BigInt & rhs )
friend

Multiplies two BigInts.

Parameters
lhsThe left-hand side operand.
rhsThe right-hand side operand.
Returns
The product of the two BigInts.

◆ operator+

BigInt operator+ ( const BigInt & lhs,
const BigInt & rhs )
friend

Adds two BigInts.

Parameters
lhsThe left-hand side operand.
rhsThe right-hand side operand.
Returns
The sum of the two BigInts.

◆ operator-

BigInt operator- ( const BigInt & lhs,
const BigInt & rhs )
friend

Subtracts two BigInts.

Parameters
lhsThe left-hand side operand.
rhsThe right-hand side operand.
Returns
The difference of the two BigInts.

◆ operator/

BigInt operator/ ( const BigInt & lhs,
const BigInt & rhs )
friend

Divides two BigInts.

Parameters
lhsThe left-hand side operand.
rhsThe right-hand side operand.
Returns
The quotient of the two BigInts.

◆ operator<

bool operator< ( const BigInt & lhs,
const BigInt & rhs )
friend

Compares two BigInts for less-than.

Parameters
lhsThe left-hand side operand.
rhsThe right-hand side operand.
Returns
True if lhs is less than rhs, false otherwise.

◆ operator<<

std::ostream & operator<< ( std::ostream & os,
const BigInt & value )
friend

Outputs a BigInt to a stream.

Parameters
osThe output stream.
valueThe BigInt value.
Returns
The output stream.

◆ operator<=

bool operator<= ( const BigInt & lhs,
const BigInt & rhs )
friend

Compares two BigInts for less-than-or-equal.

Parameters
lhsThe left-hand side operand.
rhsThe right-hand side operand.
Returns
True if lhs is less than or equal to rhs, false otherwise.

◆ operator==

bool operator== ( const BigInt & lhs,
const BigInt & rhs )
friend

Compares two BigInts for equality.

Parameters
lhsThe left-hand side operand.
rhsThe right-hand side operand.
Returns
True if lhs is equal to rhs, false otherwise.

◆ operator>

bool operator> ( const BigInt & lhs,
const BigInt & rhs )
friend

Compares two BigInts for greater-than.

Parameters
lhsThe left-hand side operand.
rhsThe right-hand side operand.
Returns
True if lhs is greater than rhs, false otherwise.

◆ operator>=

bool operator>= ( const BigInt & lhs,
const BigInt & rhs )
friend

Compares two BigInts for greater-than-or-equal.

Parameters
lhsThe left-hand side operand.
rhsThe right-hand side operand.
Returns
True if lhs is greater than or equal to rhs, false otherwise.

The documentation for this class was generated from the following file: