APRONXX  0.9.12
Public Types | Protected Attributes | List of all members
apron::scalar Class Reference

Scalar (ap_scalar_t wrapper). More...

#include <apxx_scalar.hh>

Inherits apron::use_malloc.

Public Types

enum  order { LESS = -1, EQUAL = 0, GREATER = 1 }
 Returned by ordering functions. More...
 

Public Member Functions

Constructors
 scalar ()
 Makes a double scalar equal to 0.0. More...
 
 scalar (int x)
 Makes a MPQ scalar from a native integer. More...
 
 scalar (long x)
 Makes a MPQ scalar from a native integer. More...
 
 scalar (double x)
 Makes a double scalar from a double. More...
 
 scalar (const frac &x)
 Makes a MPQ scalar from a fraction with native integer coefficients. More...
 
 scalar (infty x)
 Makes a double scalar equal to +oo or -oo. More...
 
 scalar (const mpq_class &x)
 Makes a MPQ scalar from a MPQ (copied). More...
 
 scalar (mpfr_t x)
 Makes a MPFR scalar from a MPFR number (copied). More...
 
 scalar (const scalar &x)
 Makes a copy of a scalar. More...
 
Destructor
 ~scalar ()
 
Accesses
ap_scalar_discr_t get_discr () const
 Whether the object wraps a double or a MPQ. More...
 
double & get_double ()
 Returns a (modifiable) reference to the double contained in the scalar. More...
 
const double & get_double () const
 Returns a reference to the double contained in the scalar. More...
 
mpq_class & get_mpq ()
 Returns a (modifiable) reference to the MPQ contained in the scalar. More...
 
const mpq_class & get_mpq () const
 Return a reference to the MPQ contained in the scalar. More...
 
Conversions
mpq_class to_mpq (mp_rnd_t round, order &conv) const
 Returns a new MPQ containing the (possibly converted) value of the scalar. More...
 
double to_double (mp_rnd_t round, order &conv) const
 Returns a double containing the (possibly converted) value of the scalar. More...
 
void to_mpfr (mpfr_t x, mp_rnd_t round, order &conv) const
 Copies the (possibly converted) value of the scalar into the MPFR. More...
 
 operator mpq_class () const
 Returns a new MPQ containing the (possibly converted) value of the scalar. No rounding. More...
 
 operator double () const
 Returns a double containing the (possibly converted) value of the scalar. Rounding to nearest. More...
 
Operators
void neg ()
 Negates *this. More...
 
scalar operator- () const
 Returns the opposite of *this. More...
 
void inv ()
 Inverses *this. Not exact for double type. More...
 
scalar operator~ () const
 Returns the inverse of *this. Not exact for double type. More...
 
long hash () const
 Returns a hash code. More...
 
C API compatibility
const ap_scalar_t * get_ap_scalar_t () const
 Returns a pointer to the internal APRON object stored in *this. More...
 
ap_scalar_t * get_ap_scalar_t ()
 Returns a pointer to the internal APRON object stored in *this. More...
 
- Public Member Functions inherited from apron::use_malloc
void * operator new (size_t sz)
 
void * operator new[] (size_t sz)
 
void operator delete (void *p)
 
void operator delete[] (void *p)
 

Protected Attributes

ap_scalar_t c
 Structure managed by APRON. More...
 

Assignments

scalaroperator= (int x)
 Assigns a native integer to *this, setting its type to MPQ. More...
 
scalaroperator= (long x)
 Assigns a native integer to *this, setting its type to MPQ. More...
 
scalaroperator= (double x)
 Assigns a double to *this, setting its type to double. More...
 
scalaroperator= (const frac &x)
 Assigns a fraction to *this, setting its type to MPQ. More...
 
scalaroperator= (infty x)
 Assigns +oo or -oo to *this, no change in scalar type. More...
 
scalaroperator= (const mpq_class &x)
 Assigns a MPQ to *this (copied), setting its type to MPQ. More...
 
scalaroperator= (mpfr_t x)
 Assigns a MPFR to *this (copied), setting its type to MPFR. More...
 
scalaroperator= (const scalar &x)
 Sets the type and value of *this to that of x. More...
 
void swap (scalar &a, scalar &b)
 Swaps the contents (type and value) of two scalars. More...
 

Printing

void print (FILE *stream=stdout) const
 Prints to a C stream. More...
 
std::ostream & operator<< (std::ostream &os, const scalar &s)
 Printing. More...
 

Tests

order is_infty () const
 Returns LESS if -oo, GREATER if +oo, EQUAL if finite. More...
 
order sgn () const
 Returns LESS if negative, GREATER if positive, EQUAL if null. More...
 
order cmp (const scalar &a, const scalar &b)
 Returns LESS if a<b, GREATER if a>b, EQUAL if a=b (total order). More...
 
bool operator>= (const scalar &a, const scalar &b)
 
bool operator<= (const scalar &a, const scalar &b)
 
bool operator> (const scalar &a, const scalar &b)
 
bool operator< (const scalar &a, const scalar &b)
 
bool operator== (const scalar &a, const scalar &b)
 
bool operator!= (const scalar &a, const scalar &b)
 
order cmp (const scalar &a, int b)
 
bool operator>= (const scalar &a, int b)
 
bool operator<= (const scalar &a, int b)
 
bool operator> (const scalar &a, int b)
 
bool operator< (const scalar &a, int b)
 
bool operator== (const scalar &a, int b)
 
bool operator!= (const scalar &a, int b)
 
order cmp (int a, const scalar &b)
 
bool operator>= (int a, const scalar &b)
 
bool operator<= (int a, const scalar &b)
 
bool operator> (int a, const scalar &b)
 
bool operator< (int a, const scalar &b)
 
bool operator== (int a, const scalar &b)
 
bool operator!= (int a, const scalar &b)
 

Detailed Description

Scalar (ap_scalar_t wrapper).

A scalar object represents a (possibly +oo or -oo) number, using either a double or a MPQ (multi-precision fraction). All operations are exact unless explicitly noted.

Member Enumeration Documentation

◆ order

Returned by ordering functions.

Enumerator
LESS 

Means less than, negative, or -oo (depending on context).

EQUAL 

Means equal or null (depending on context).

GREATER 

Means greater than, positive, or +oo (depending on context).

Constructor & Destructor Documentation

◆ scalar() [1/9]

scalar::scalar ( )
inline

Makes a double scalar equal to 0.0.

◆ scalar() [2/9]

scalar::scalar ( int  x)
inline

Makes a MPQ scalar from a native integer.

◆ scalar() [3/9]

scalar::scalar ( long  x)
inline

Makes a MPQ scalar from a native integer.

◆ scalar() [4/9]

scalar::scalar ( double  x)
inline

Makes a double scalar from a double.

◆ scalar() [5/9]

scalar::scalar ( const frac x)
inline

Makes a MPQ scalar from a fraction with native integer coefficients.

◆ scalar() [6/9]

scalar::scalar ( infty  x)
inline

Makes a double scalar equal to +oo or -oo.

◆ scalar() [7/9]

scalar::scalar ( const mpq_class &  x)
inline

Makes a MPQ scalar from a MPQ (copied).

◆ scalar() [8/9]

scalar::scalar ( mpfr_t  x)
inline

Makes a MPFR scalar from a MPFR number (copied).

◆ scalar() [9/9]

scalar::scalar ( const scalar x)
inline

Makes a copy of a scalar.

◆ ~scalar()

scalar::~scalar ( )
inline

Member Function Documentation

◆ get_ap_scalar_t() [1/2]

const ap_scalar_t * scalar::get_ap_scalar_t ( ) const
inline

Returns a pointer to the internal APRON object stored in *this.

◆ get_ap_scalar_t() [2/2]

ap_scalar_t * scalar::get_ap_scalar_t ( )
inline

Returns a pointer to the internal APRON object stored in *this.

◆ get_discr()

ap_scalar_discr_t scalar::get_discr ( ) const
inline

Whether the object wraps a double or a MPQ.

Returns
Either AP_SCALAR_DOUBLE, AP_SCALAR_MPQ, or AP_SCALAR_MPFR.

◆ get_double() [1/2]

double & scalar::get_double ( )
inline

Returns a (modifiable) reference to the double contained in the scalar.

Exceptions
bad_discriminantwhen the scalar is not of double type.

◆ get_double() [2/2]

const double & scalar::get_double ( ) const
inline

Returns a reference to the double contained in the scalar.

Exceptions
bad_discriminantwhen the scalar is not of double type.

◆ get_mpq() [1/2]

mpq_class & scalar::get_mpq ( )
inline

Returns a (modifiable) reference to the MPQ contained in the scalar.

Exceptions
bad_discriminantwhen the scalar is not of MPQ type.

◆ get_mpq() [2/2]

const mpq_class & scalar::get_mpq ( ) const
inline

Return a reference to the MPQ contained in the scalar.

Exceptions
bad_discriminantwhen the scalar is not of MPQ type.

◆ hash()

long scalar::hash ( ) const
inline

Returns a hash code.

◆ inv()

void scalar::inv ( )
inline

Inverses *this. Not exact for double type.

◆ is_infty()

scalar::order scalar::is_infty ( ) const
inline

Returns LESS if -oo, GREATER if +oo, EQUAL if finite.

◆ neg()

void scalar::neg ( )
inline

Negates *this.

◆ operator double()

scalar::operator double ( ) const
inline

Returns a double containing the (possibly converted) value of the scalar. Rounding to nearest.

◆ operator mpq_class()

scalar::operator mpq_class ( ) const
inline

Returns a new MPQ containing the (possibly converted) value of the scalar. No rounding.

◆ operator-()

scalar scalar::operator- ( ) const
inline

Returns the opposite of *this.

◆ operator=() [1/8]

scalar & scalar::operator= ( int  x)
inline

Assigns a native integer to *this, setting its type to MPQ.

◆ operator=() [2/8]

scalar & scalar::operator= ( long  x)
inline

Assigns a native integer to *this, setting its type to MPQ.

◆ operator=() [3/8]

scalar & scalar::operator= ( double  x)
inline

Assigns a double to *this, setting its type to double.

◆ operator=() [4/8]

scalar & scalar::operator= ( const frac x)
inline

Assigns a fraction to *this, setting its type to MPQ.

◆ operator=() [5/8]

scalar & scalar::operator= ( infty  x)
inline

Assigns +oo or -oo to *this, no change in scalar type.

◆ operator=() [6/8]

scalar & scalar::operator= ( const mpq_class &  x)
inline

Assigns a MPQ to *this (copied), setting its type to MPQ.

◆ operator=() [7/8]

scalar & scalar::operator= ( mpfr_t  x)
inline

Assigns a MPFR to *this (copied), setting its type to MPFR.

◆ operator=() [8/8]

scalar & scalar::operator= ( const scalar x)
inline

Sets the type and value of *this to that of x.

◆ operator~()

scalar scalar::operator~ ( ) const
inline

Returns the inverse of *this. Not exact for double type.

◆ print()

void scalar::print ( FILE *  stream = stdout) const
inline

Prints to a C stream.

◆ sgn()

scalar::order scalar::sgn ( ) const
inline

Returns LESS if negative, GREATER if positive, EQUAL if null.

◆ to_double()

double scalar::to_double ( mp_rnd_t  round,
order conv 
) const
inline

Returns a double containing the (possibly converted) value of the scalar.

  • round: rounding direction, may be GMP_RNDN, GMP_RNDZ, GMP_RNDU, GMP_RNDD, or GMP_RND_MAX.
  • conv is set to either LESS, EQUAL, or GREATER, depending on whether the result is less than, equal to or greater than the value of *this.

◆ to_mpfr()

void scalar::to_mpfr ( mpfr_t  x,
mp_rnd_t  round,
order conv 
) const
inline

Copies the (possibly converted) value of the scalar into the MPFR.

  • round: rounding direction, may be GMP_RNDN, GMP_RNDZ, GMP_RNDU, GMP_RNDD, or GMP_RND_MAX.
  • conv is set to either LESS, EQUAL, or GREATER, depending on whether the result is less than, equal to or greater than the value of *this.

◆ to_mpq()

mpq_class scalar::to_mpq ( mp_rnd_t  round,
order conv 
) const
inline

Returns a new MPQ containing the (possibly converted) value of the scalar.

  • round: rounding direction, may be GMP_RNDN, GMP_RNDZ, GMP_RNDU, GMP_RNDD, or GMP_RND_MAX.
  • conv is set to either LESS, EQUAL, or GREATER, depending on whether the result is less than, equal to or greater than the value of *this.
    Note
    Currently round is ignored and the conversion is always exact.

Friends And Related Function Documentation

◆ cmp [1/3]

order cmp ( const scalar a,
const scalar b 
)
friend

Returns LESS if a<b, GREATER if a>b, EQUAL if a=b (total order).

◆ cmp [2/3]

order cmp ( const scalar a,
int  b 
)
friend

◆ cmp [3/3]

order cmp ( int  a,
const scalar b 
)
friend

◆ operator!= [1/3]

bool operator!= ( const scalar a,
const scalar b 
)
friend

◆ operator!= [2/3]

bool operator!= ( const scalar a,
int  b 
)
friend

◆ operator!= [3/3]

bool operator!= ( int  a,
const scalar b 
)
friend

◆ operator< [1/3]

bool operator< ( const scalar a,
const scalar b 
)
friend

◆ operator< [2/3]

bool operator< ( const scalar a,
int  b 
)
friend

◆ operator< [3/3]

bool operator< ( int  a,
const scalar b 
)
friend

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const scalar s 
)
friend

Printing.

◆ operator<= [1/3]

bool operator<= ( const scalar a,
const scalar b 
)
friend

◆ operator<= [2/3]

bool operator<= ( const scalar a,
int  b 
)
friend

◆ operator<= [3/3]

bool operator<= ( int  a,
const scalar b 
)
friend

◆ operator== [1/3]

bool operator== ( const scalar a,
const scalar b 
)
friend

◆ operator== [2/3]

bool operator== ( const scalar a,
int  b 
)
friend

◆ operator== [3/3]

bool operator== ( int  a,
const scalar b 
)
friend

◆ operator> [1/3]

bool operator> ( const scalar a,
const scalar b 
)
friend

◆ operator> [2/3]

bool operator> ( const scalar a,
int  b 
)
friend

◆ operator> [3/3]

bool operator> ( int  a,
const scalar b 
)
friend

◆ operator>= [1/3]

bool operator>= ( const scalar a,
const scalar b 
)
friend

◆ operator>= [2/3]

bool operator>= ( const scalar a,
int  b 
)
friend

◆ operator>= [3/3]

bool operator>= ( int  a,
const scalar b 
)
friend

◆ swap

void swap ( scalar a,
scalar b 
)
friend

Swaps the contents (type and value) of two scalars.

Member Data Documentation

◆ c

ap_scalar_t apron::scalar::c
protected

Structure managed by APRON.


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