Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

guar::rational::rational_rep Struct Reference

#include <guar_exact.h>

List of all members.

Public Methods

 rational_rep ()
 rational_rep (int sign, int na, unsigned long *a)
 rational_rep (int sign, unsigned long a)
 rational_rep (int sign, int na, int nb)
 ~rational_rep ()
template<class T> void dump (T &num, T &den)
void calc_bounds (void)
void negative (void)
void reciprocal (void)

Public Attributes

unsigned int m_na
unsigned long * m_a
unsigned int m_nb
unsigned long * m_b
size_t m_size_a
size_t m_size_b
int m_refcount
Interval m_i
int m_sign: 2
unsigned int m_bounds: 1


Constructor & Destructor Documentation

guar::rational::rational_rep::rational_rep   [inline]
 

Definition at line 166 of file guar_exact.h.

References m_a, m_b, m_bounds, m_na, m_nb, m_refcount, m_sign, m_size_a, and m_size_b.

00167     {
00168       m_refcount = 1;
00169       m_sign = 0;
00170       m_bounds = m_na = m_nb = 0;
00171       m_size_a = m_size_b = 0;
00172       m_a = m_b = NULL;
00173     }

guar::rational::rational_rep::rational_rep int    sign,
int    na,
unsigned long *    a
[inline]
 

Definition at line 175 of file guar_exact.h.

References m_a, m_b, m_bounds, m_na, m_nb, m_refcount, m_sign, m_size_a, m_size_b, and gust::PoolAlloc().

00176     {
00177       size_t bsize;
00178 
00179       m_refcount = 1;
00180       m_sign = 0;
00181       m_bounds = m_na = m_nb = 0;
00182       m_size_b = m_size_a = 0; 
00183       m_a = m_b = 0;
00184 
00185       if( na == 0 ) return;
00186       
00187       m_a = (unsigned long *)gust::PoolAlloc( na*sizeof(unsigned long), &bsize );
00188       if( m_a == NULL ) throw gul::PoolAllocError();
00189       for( int i=0; i<na; i++ ) m_a[i] = a[i];
00190 
00191       m_sign = sign;
00192       m_na = na;
00193       m_size_a = bsize;
00194     }

guar::rational::rational_rep::rational_rep int    sign,
unsigned long    a
[inline]
 

Definition at line 196 of file guar_exact.h.

References m_a, m_b, m_bounds, m_na, m_nb, m_refcount, m_sign, m_size_a, m_size_b, and gust::PoolAlloc().

00197     {
00198       size_t bsize;
00199 
00200       m_refcount = 1;
00201       m_sign = 0;
00202       m_bounds = m_na = m_nb = 0;
00203       m_size_a = m_size_b = 0;
00204       m_a = m_b = NULL;
00205       if( a == 0 ) return; 
00206      
00207       m_a = (unsigned long *)gust::PoolAlloc( sizeof(unsigned long), &bsize );
00208       if( m_a == NULL ) throw gul::PoolAllocError();
00209       m_a[0] = a;
00210 
00211       m_sign = sign;
00212       m_na = 1;
00213       m_size_a = bsize;
00214     }

guar::rational::rational_rep::rational_rep int    sign,
int    na,
int    nb
[inline]
 

Definition at line 217 of file guar_exact.h.

References m_a, m_b, m_bounds, m_na, m_nb, m_refcount, m_sign, m_size_a, m_size_b, and gust::PoolAlloc().

00218     {
00219       size_t bsize;
00220 
00221       m_refcount = 1;
00222       m_sign = 0;
00223       m_bounds = m_na = m_nb = 0;
00224       m_size_a = m_size_b = 0; 
00225       m_a = m_b = NULL;
00226 
00227       if( na != 0 )       
00228       {
00229         m_sign = sign;
00230         m_a = (unsigned long *)gust::PoolAlloc( na*sizeof(unsigned long),&bsize);
00231         if( m_a == NULL ) throw gul::PoolAllocError();
00232         m_size_a = bsize;
00233         m_na = na;
00234       }
00235       if( nb != 0 )       
00236       {     
00237         m_b = (unsigned long *)gust::PoolAlloc( nb*sizeof(unsigned long),&bsize);
00238         if( m_b == NULL ) throw gul::PoolAllocError();
00239         m_size_b = bsize;
00240         m_nb = nb;
00241       }
00242     }

guar::rational::rational_rep::~rational_rep   [inline]
 

Definition at line 244 of file guar_exact.h.

References m_a, m_b, m_size_a, m_size_b, and gust::PoolFree().

Referenced by guar::rational::operator=(), and guar::rational::~rational().

00245     {
00246       if( (m_size_a != 0) && (m_a != NULL) ) gust::PoolFree( m_a, m_size_a );      
00247       if( (m_size_b != 0) && (m_b != NULL) ) gust::PoolFree( m_b, m_size_b );
00248     }


Member Function Documentation

void guar::rational::rational_rep::calc_bounds void    [inline]
 

Definition at line 267 of file guar_exact.h.

References dump(), and m_bounds.

Referenced by guar::rational::calc_bounds(), and guar::rational::get_bounds().

00268     { 
00269       Interval inum,iden;
00270       double num,den;
00271 
00272       dump( num, den );
00273       if( num != 0.0 )
00274       {
00275         inum.m_low = num - DBL_EPSILON*fabs(num);
00276         inum.m_high = num + DBL_EPSILON*fabs(num);
00277       }
00278       else
00279       {
00280         inum.m_low = inum.m_high = 0.0;
00281       }
00282       
00283       if( den != 1.0 )
00284       {
00285         iden.m_low = den - DBL_EPSILON*fabs(den);
00286         iden.m_high = den + DBL_EPSILON*fabs(den);
00287       }
00288       else
00289       {
00290         iden.m_low = iden.m_high = 1.0;
00291       }
00292 
00293       m_i = inum/iden;
00294 
00295       m_bounds = 1;
00296     }

template<class T>
void guar::rational::rational_rep::dump T &    num,
T &    den
[inline]
 

Definition at line 251 of file guar_exact.h.

References m_a, m_b, m_na, and m_nb.

Referenced by calc_bounds(), and guar::rational::dump().

00252     { 
00253       if( m_na == 0 )
00254       {  num = (T)0.0; den = (T)1.0; return; }
00255       else
00256         IntTo<T>( m_na, m_a, num );
00257 
00258       if( m_sign ) 
00259         num = -num;
00260 
00261       if( m_nb == 0 )
00262         den = (T)1.0;
00263       else
00264         IntTo<T>( m_nb, m_b, den );  
00265     }

void guar::rational::rational_rep::negative void    [inline]
 

Definition at line 298 of file guar_exact.h.

References m_na, and m_sign.

00299     {      
00300       if( m_na != 0 )
00301         m_sign ^= -1;
00302     }

void guar::rational::rational_rep::reciprocal void    [inline]
 

Definition at line 304 of file guar_exact.h.

References m_a, m_b, m_na, m_nb, m_size_a, m_size_b, gust::PoolAlloc(), and gust::PoolFree().

00305     {
00306       size_t bsize;
00307       unsigned long *p;
00308       int i;
00309       
00310       if( m_na == 0 ) throw gul::Error();
00311       
00312       if( (m_na == 1) && (m_a[0] == 1) )
00313       {
00314         gust::PoolFree( m_a, m_size_a );
00315         m_na = 0;
00316         m_size_a = 0;
00317         m_a = NULL;
00318       }
00319       
00320       if( m_size_b == 0 )
00321       {
00322         m_b = (unsigned long *)gust::PoolAlloc( sizeof(unsigned long), &bsize );
00323         if( m_b == NULL ) throw gul::PoolAllocError();
00324         m_nb = 1;
00325         m_b[0] = 1;
00326         m_size_b = bsize;
00327       }
00328 
00329       i = m_na; m_na = m_nb; m_nb = i;
00330       bsize = m_size_a; m_size_a = m_size_b; m_size_b = bsize;
00331       p = m_a; m_a = m_b; m_b = p;
00332     }


Member Data Documentation

unsigned long* guar::rational::rational_rep::m_a
 

Definition at line 151 of file guar_exact.h.

Referenced by guar::rational::div_mod(), dump(), guar::rational::get_copy(), rational_rep(), reciprocal(), and ~rational_rep().

unsigned long* guar::rational::rational_rep::m_b
 

Definition at line 154 of file guar_exact.h.

Referenced by guar::rational::div_mod(), dump(), guar::rational::get_copy(), rational_rep(), reciprocal(), and ~rational_rep().

unsigned int guar::rational::rational_rep::m_bounds
 

Definition at line 164 of file guar_exact.h.

Referenced by calc_bounds(), guar::rational::get_bounds(), and rational_rep().

Interval guar::rational::rational_rep::m_i
 

Definition at line 161 of file guar_exact.h.

Referenced by guar::rational::get_bounds().

unsigned int guar::rational::rational_rep::m_na
 

Definition at line 150 of file guar_exact.h.

Referenced by guar::rational::div_mod(), dump(), guar::rational::get_copy(), negative(), rational_rep(), and reciprocal().

unsigned int guar::rational::rational_rep::m_nb
 

Definition at line 153 of file guar_exact.h.

Referenced by guar::rational::div_mod(), dump(), guar::rational::get_copy(), rational_rep(), and reciprocal().

int guar::rational::rational_rep::m_refcount
 

Definition at line 159 of file guar_exact.h.

Referenced by guar::rational::operator=(), rational_rep(), and guar::rational::~rational().

int guar::rational::rational_rep::m_sign
 

Definition at line 163 of file guar_exact.h.

Referenced by guar::rational::div_mod(), guar::rational::get_copy(), negative(), and rational_rep().

size_t guar::rational::rational_rep::m_size_a
 

Definition at line 156 of file guar_exact.h.

Referenced by rational_rep(), reciprocal(), and ~rational_rep().

size_t guar::rational::rational_rep::m_size_b
 

Definition at line 157 of file guar_exact.h.

Referenced by rational_rep(), reciprocal(), and ~rational_rep().


The documentation for this struct was generated from the following file:
Generated on Mon Jan 21 04:17:48 2002 for GUL 0.6 - Geometry Utility Library by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001