Wildmeshing Toolkit
wmtk::Rational Class Reference

#include <Rational.hpp>

Public Member Functions

 Rational (bool rounded=false)
 
 Rational (int v, bool rounded=false)
 
 Rational (double d, bool rounded=false)
 
 Rational (const mpq_t &v_)
 
 Rational (const Rational &other)
 
 Rational (const Rational &other, bool rounded)
 
 Rational (const Eigen::VectorX< char > &data)
 
 Rational (const std::string &data, bool rounded=false)
 
Rationaloperator= (const Rational &x)
 
Rationaloperator= (const double x)
 
template<typename T >
void init (const T &v)
 
 ~Rational ()
 
void canonicalize ()
 
int get_sign () const
 
double to_double () const
 
 operator double () const
 
void round ()
 
bool can_be_rounded ()
 
void init_from_binary (const std::string &v)
 
std::string to_binary () const
 
std::string serialize () const
 
bool is_rounded () const
 

Private Member Functions

std::string numerator () const
 
std::string denominator () const
 

Private Attributes

mpq_t value
 
double d_value
 
bool m_is_rounded
 

Friends

Rational operator+ (const Rational &x, const Rational &y)
 
Rational operator- (const Rational &x, const Rational &y)
 
Rational operator- (const Rational &x)
 
Rational pow (const Rational &x, int p)
 
Rational abs (const Rational &r0)
 
Rational operator* (const Rational &x, const Rational &y)
 
Rational operator/ (const Rational &x, const Rational &y)
 
bool operator< (const Rational &r, const Rational &r1)
 
bool operator> (const Rational &r, const Rational &r1)
 
bool operator<= (const Rational &r, const Rational &r1)
 
bool operator>= (const Rational &r, const Rational &r1)
 
bool operator== (const Rational &r, const Rational &r1)
 
bool operator!= (const Rational &r, const Rational &r1)
 
std::ostream & operator<< (std::ostream &os, const Rational &r)
 
int cmp (const Rational &r, const Rational &r1)
 

Detailed Description

Definition at line 12 of file Rational.hpp.

Constructor & Destructor Documentation

◆ Rational() [1/8]

wmtk::Rational::Rational ( bool  rounded = false)

Definition at line 22 of file Rational.cpp.

◆ Rational() [2/8]

wmtk::Rational::Rational ( int  v,
bool  rounded = false 
)

Definition at line 26 of file Rational.cpp.

◆ Rational() [3/8]

wmtk::Rational::Rational ( double  d,
bool  rounded = false 
)

Definition at line 30 of file Rational.cpp.

References d_value, m_is_rounded, and value.

◆ Rational() [4/8]

wmtk::Rational::Rational ( const mpq_t &  v_)

Definition at line 44 of file Rational.cpp.

References d_value, m_is_rounded, and value.

◆ Rational() [5/8]

wmtk::Rational::Rational ( const Rational other)

Definition at line 54 of file Rational.cpp.

References m_is_rounded, and value.

◆ Rational() [6/8]

wmtk::Rational::Rational ( const Rational other,
bool  rounded 
)

Definition at line 63 of file Rational.cpp.

References d_value, m_is_rounded, to_double(), and value.

Here is the call graph for this function:

◆ Rational() [7/8]

wmtk::Rational::Rational ( const Eigen::VectorX< char > &  data)

Definition at line 371 of file Rational.cpp.

References d_value, m_is_rounded, and value.

◆ Rational() [8/8]

wmtk::Rational::Rational ( const std::string &  data,
bool  rounded = false 
)

Definition at line 82 of file Rational.cpp.

References d_value, m_is_rounded, and value.

◆ ~Rational()

wmtk::Rational::~Rational ( )

Definition at line 99 of file Rational.cpp.

References m_is_rounded, and value.

Member Function Documentation

◆ can_be_rounded()

bool wmtk::Rational::can_be_rounded ( )
inline

Definition at line 74 of file Rational.hpp.

References m_is_rounded, and to_double().

Here is the call graph for this function:

◆ canonicalize()

void wmtk::Rational::canonicalize ( )

Definition at line 9 of file Rational.cpp.

References m_is_rounded, and value.

◆ denominator()

std::string wmtk::Rational::denominator ( ) const
private

Definition at line 449 of file Rational.cpp.

References d_value, m_is_rounded, and value.

Referenced by serialize().

Here is the caller graph for this function:

◆ get_sign()

int wmtk::Rational::get_sign ( ) const

Definition at line 15 of file Rational.cpp.

References d_value, m_is_rounded, and value.

Referenced by wmtk::utils::segment_intersection_rational(), wmtk::components::internal::segment_segment_inter(), wmtk::utils::wmtk_orient2d(), and wmtk::utils::wmtk_orient3d().

Here is the caller graph for this function:

◆ init()

template<typename T >
void wmtk::Rational::init ( const T &  v)
inline

Definition at line 28 of file Rational.hpp.

References m_is_rounded, and value.

◆ init_from_binary()

void wmtk::Rational::init_from_binary ( const std::string &  v)

Definition at line 346 of file Rational.cpp.

References value.

Referenced by wmtk::HDF5Reader::read_mesh().

Here is the caller graph for this function:

◆ is_rounded()

bool wmtk::Rational::is_rounded ( ) const
inline

Definition at line 86 of file Rational.hpp.

References m_is_rounded.

Referenced by wmtk::utils::rational_to_interval(), and wmtk::utils::wmtk_orient3d().

Here is the caller graph for this function:

◆ numerator()

std::string wmtk::Rational::numerator ( ) const
private

Definition at line 427 of file Rational.cpp.

References d_value, m_is_rounded, and value.

Referenced by serialize().

Here is the caller graph for this function:

◆ operator double()

wmtk::Rational::operator double ( ) const
explicit

Definition at line 323 of file Rational.cpp.

◆ operator=() [1/2]

Rational & wmtk::Rational::operator= ( const double  x)

Definition at line 247 of file Rational.cpp.

References d_value, m_is_rounded, and value.

◆ operator=() [2/2]

Rational & wmtk::Rational::operator= ( const Rational x)

Definition at line 230 of file Rational.cpp.

References d_value, m_is_rounded, and value.

◆ round()

void wmtk::Rational::round ( )
inline

Definition at line 65 of file Rational.hpp.

References d_value, m_is_rounded, to_double(), and value.

Here is the call graph for this function:

◆ serialize()

std::string wmtk::Rational::serialize ( ) const

Definition at line 366 of file Rational.cpp.

References denominator(), m_is_rounded, and numerator().

Here is the call graph for this function:

◆ to_binary()

std::string wmtk::Rational::to_binary ( ) const

Definition at line 350 of file Rational.cpp.

References d_value, m_is_rounded, and value.

Referenced by wmtk::HDF5Writer::write().

Here is the caller graph for this function:

◆ to_double()

double wmtk::Rational::to_double ( ) const

Definition at line 317 of file Rational.cpp.

References d_value, m_is_rounded, and value.

Referenced by can_be_rounded(), Rational(), wmtk::utils::rational_to_interval(), round(), and wmtk::function::Tri_AMIPS_energy().

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ abs

Rational abs ( const Rational r0)
friend

Definition at line 328 of file Rational.cpp.

◆ cmp

int cmp ( const Rational r,
const Rational r1 
)
friend

Definition at line 259 of file Rational.cpp.

◆ operator!=

bool operator!= ( const Rational r,
const Rational r1 
)
friend

Definition at line 311 of file Rational.cpp.

◆ operator*

Rational operator* ( const Rational x,
const Rational y 
)
friend

Definition at line 178 of file Rational.cpp.

◆ operator+

Rational operator+ ( const Rational x,
const Rational y 
)
friend

Definition at line 104 of file Rational.cpp.

◆ operator- [1/2]

Rational operator- ( const Rational x)
friend

Definition at line 157 of file Rational.cpp.

◆ operator- [2/2]

Rational operator- ( const Rational x,
const Rational y 
)
friend

Definition at line 130 of file Rational.cpp.

◆ operator/

Rational operator/ ( const Rational x,
const Rational y 
)
friend

Definition at line 204 of file Rational.cpp.

◆ operator<

bool operator< ( const Rational r,
const Rational r1 
)
friend

Definition at line 51 of file Rational.hpp.

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const Rational r 
)
friend

Definition at line 340 of file Rational.cpp.

◆ operator<=

bool operator<= ( const Rational r,
const Rational r1 
)
friend

Definition at line 53 of file Rational.hpp.

◆ operator==

bool operator== ( const Rational r,
const Rational r1 
)
friend

Definition at line 286 of file Rational.cpp.

◆ operator>

bool operator> ( const Rational r,
const Rational r1 
)
friend

Definition at line 52 of file Rational.hpp.

◆ operator>=

bool operator>= ( const Rational r,
const Rational r1 
)
friend

Definition at line 54 of file Rational.hpp.

◆ pow

Rational pow ( const Rational x,
int  p 
)
friend

Definition at line 166 of file Rational.cpp.

Member Data Documentation

◆ d_value

double wmtk::Rational::d_value
private

◆ m_is_rounded

bool wmtk::Rational::m_is_rounded
private

◆ value

mpq_t wmtk::Rational::value
private

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