\( \newcommand{\E}{\mathrm{E}} \) \( \newcommand{\A}{\mathrm{A}} \) \( \newcommand{\R}{\mathrm{R}} \) \( \newcommand{\N}{\mathrm{N}} \) \( \newcommand{\Q}{\mathrm{Q}} \) \( \newcommand{\Z}{\mathrm{Z}} \) \( \def\ccSum #1#2#3{ \sum_{#1}^{#2}{#3} } \def\ccProd #1#2#3{ \sum_{#1}^{#2}{#3} }\)
CGAL 4.7 - Number Types
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
CGAL::Gmpq Class Reference

#include <CGAL/Gmpq.h>

Definition

An object of the class Gmpq is an arbitrary precision rational number based on the Gmp library.

Is Model Of:

Field

RealEmbeddable

Fraction

Implementation

Gmpqs are reference counted.

Related Functions

(Note that these are not member functions.)

std::ostream & operator<< (std::ostream &out, const Gmpq &q)
 writes q to the ostream out, in the form n/d. More...
 
std::istream & operator>> (std::istream &in, Gmpq &q)
 reads a number from in, then converts it to a Gmpq. More...
 

Creation

 Gmpq ()
 creates an uninitialized Gmpq q. More...
 
 Gmpq (int i)
 creates a Gmpq initialized with i. More...
 
 Gmpq (Gmpz n)
 creates a Gmpq initialized with n. More...
 
 Gmpq (Gmpfr f)
 creates a Gmpq initialized with f. More...
 
 Gmpq (int n, int d)
 creates a Gmpq initialized with n/d. More...
 
 Gmpq (signed long n, unsigned long d)
 creates a Gmpq initialized with n/d. More...
 
 Gmpq (unsigned long n, unsigned long d)
 creates a Gmpq initialized with n/d. More...
 
 Gmpq (Gmpz n, Gmpz d)
 creates a Gmpq initialized with n/d. More...
 
 Gmpq (double d)
 creates a Gmpq initialized with d. More...
 
 Gmpq (const std::string &str)
 creates a Gmpq initialized with str, which can be an integer like "41" or a fraction like "41/152". More...
 
 Gmpq (const std::string &str, int base)
 creates a Gmpq initialized with str in base base, which is an integer between 2 and 62. More...
 

Operations

There are two access functions, namely to the numerator and the denominator of a rational.

Note that these values are not uniquely defined. It is guaranteed that q.numerator() and q.denominator() return values nt_num and nt_den such that q = nt_num/nt_den, only if q.numerator() and q.denominator() are called consecutively wrt. q, i.e. q is not involved in any other operation between these calls.

Gmpz numerator () const
 returns the numerator of q. More...
 
Gmpz denominator () const
 returns the denominator of q. More...
 

Constructor & Destructor Documentation

CGAL::Gmpq::Gmpq ( )

creates an uninitialized Gmpq q.

CGAL::Gmpq::Gmpq ( int  i)

creates a Gmpq initialized with i.

CGAL::Gmpq::Gmpq ( Gmpz  n)

creates a Gmpq initialized with n.

CGAL::Gmpq::Gmpq ( Gmpfr  f)

creates a Gmpq initialized with f.

CGAL::Gmpq::Gmpq ( int  n,
int  d 
)

creates a Gmpq initialized with n/d.

CGAL::Gmpq::Gmpq ( signed long  n,
unsigned long  d 
)

creates a Gmpq initialized with n/d.

CGAL::Gmpq::Gmpq ( unsigned long  n,
unsigned long  d 
)

creates a Gmpq initialized with n/d.

CGAL::Gmpq::Gmpq ( Gmpz  n,
Gmpz  d 
)

creates a Gmpq initialized with n/d.

CGAL::Gmpq::Gmpq ( double  d)

creates a Gmpq initialized with d.

CGAL::Gmpq::Gmpq ( const std::string &  str)

creates a Gmpq initialized with str, which can be an integer like "41" or a fraction like "41/152".

White space is allowed in the string, and ignored.

CGAL::Gmpq::Gmpq ( const std::string &  str,
int  base 
)

creates a Gmpq initialized with str in base base, which is an integer between 2 and 62.

White space in the string is ignored.

Member Function Documentation

Gmpz CGAL::Gmpq::denominator ( ) const

returns the denominator of q.

Gmpz CGAL::Gmpq::numerator ( ) const

returns the numerator of q.

Friends And Related Function Documentation

std::ostream & operator<< ( std::ostream &  out,
const Gmpq q 
)
related

writes q to the ostream out, in the form n/d.

std::istream & operator>> ( std::istream &  in,
Gmpq q 
)
related

reads a number from in, then converts it to a Gmpq.

The number may be an integer, a rational number in the form n/d, or a floating-point number.