rvm  1.11
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Functions
rmath.h File Reference
#include <string>
#include <float.h>
#include "asserts.h"
#include "types.h"
#include "estring.h"
Include dependency graph for rmath.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  safe_num< T >
 Safely manipulate numbers without worryiung about over/underflow error. More...
 

Functions

template<typename T >
static const T max_limit ()
 A small set of numeric limits routines, since gcc prior to 3.x doesn't have numeric_limits. More...
 
template<typename T >
static const T min_limit ()
 Find the maximum limit for a type, equivalent to std::numeric_limits<T>.min() for systems that don't have the limits c++ header file. More...
 
template<>
const float max_limit< float > ()
 Return the largest possible number that a float may hold. More...
 
template<>
const float min_limit< float > ()
 Return the smallest positive number that a float may hold. More...
 
template<>
const double max_limit< double > ()
 Return the largest possible number that a double may hold. More...
 
template<>
const double min_limit< double > ()
 Return the smallest positive number that a double may hold. More...
 
template<typename T >
static const T max_limit (const T &a_arg)
 Return the max_limit of a variable. More...
 
template<typename T >
static const T min_limit (const T &a_arg)
 Return the min_limit of a variable. More...
 
template<typename T >
static const T highest_value (void)
 Return the maximum possible value a type may hold. More...
 
template<typename T >
static const T highest_value (const T &a_arg)
 Return the maximum possible value of a variable. More...
 
template<typename T >
static const T lowest_value (void)
 Return 0 for unsigned types, or the maximum negative value that the type may hold. More...
 
template<typename T >
static const T lowest_value (const T &a_arg)
 Return 0 for unsigned types, or the maximum negative value that a variable may hold. More...
 
template<typename T >
absolute (const T &a_num)
 Return the absolute value of a numeric type. More...
 
template<typename T >
safe_num< T > operator+ (safe_num< T > a_class1, safe_num< T > a_class2)
 Arithmetic operator. More...
 
template<typename T >
safe_num< T > operator- (safe_num< T > a_class1, safe_num< T > a_class2)
 Arithmetic operator. More...
 
template<typename T >
safe_num< T > operator* (safe_num< T > a_class1, safe_num< T > a_class2)
 Arithmetic operator. More...
 
template<typename T >
safe_num< T > operator/ (safe_num< T > a_class1, safe_num< T > a_class2)
 Arithmetic operator. More...
 
template<typename T >
safe_num< T > operator% (safe_num< T > a_class1, safe_num< T > a_class2)
 Arithmetic operator. More...
 
template<typename T >
safe_num< T > & operator++ (safe_num< T > &a_class)
 Arithmetic operator. More...
 
template<typename T >
safe_num< T > operator++ (safe_num< T > &a_class, int)
 Arithmetic operator. More...
 
template<typename T >
safe_num< T > & operator-- (safe_num< T > &a_class)
 Arithmetic operator. More...
 
template<typename T >
safe_num< T > operator-- (safe_num< T > &a_class, int)
 Arithmetic operator. More...
 
template<typename T >
std::ostream & operator<< (std::ostream &a_out, safe_num< T > a_class)
 Arithmetic operator. More...
 
template<typename T >
std::istream & operator>> (std::istream &a_in, safe_num< T > &a_class)
 Arithmetic operator. More...
 

Function Documentation

template<typename T >
T absolute ( const T &  a_num)

Return the absolute value of a numeric type.

Caveat: For some types, the maximum negative value is one larger than the maximum positive value: specifically char. Depending on the type and value, it may be impossible to return the absolute value. For such types under such circumstances an exception is thrown.

Definition at line 240 of file rmath.h.

References ERROR, INTERNAL_ERROR, is_char(), and TRY_nomem.

Referenced by safe_num< T >::add(), safe_num< T >::subtract(), and test7().

Here is the call graph for this function:

template<typename T >
static const T highest_value ( void  )
static

Return the maximum possible value a type may hold.

This is just a convenience function to match lowest_value<T>(). All it does is return the value of max_limit<T>().

Definition at line 182 of file rmath.h.

template<typename T >
static const T highest_value ( const T &  a_arg)
static

Return the maximum possible value of a variable.

Definition at line 193 of file rmath.h.

template<typename T >
static const T lowest_value ( void  )
static

Return 0 for unsigned types, or the maximum negative value that the type may hold.

Definition at line 206 of file rmath.h.

template<typename T >
static const T lowest_value ( const T &  a_arg)
static

Return 0 for unsigned types, or the maximum negative value that a variable may hold.

Definition at line 221 of file rmath.h.

template<typename T >
static const T max_limit ( )
static

A small set of numeric limits routines, since gcc prior to 3.x doesn't have numeric_limits.

Find the maximum limit for a type, equivalent to std::numeric_limits<T>.max() for systems that don't have the limits c++ header file.

Definition at line 20 of file rmath.h.

Referenced by test3(), and vault_manager::usage().

template<typename T >
static const T max_limit ( const T &  a_arg)
static

Return the max_limit of a variable.

This is handy to have because it means that the author may change the type of a variable without having to track down all uses of max_limit or min_limit to change the type they measure.

Definition at line 149 of file rmath.h.

template<>
const double max_limit< double > ( )

Return the largest possible number that a double may hold.

Definition at line 116 of file rmath.h.

Referenced by test4().

template<>
const float max_limit< float > ( )

Return the largest possible number that a float may hold.

Definition at line 86 of file rmath.h.

Referenced by test4().

template<typename T >
static const T min_limit ( )
static

Find the maximum limit for a type, equivalent to std::numeric_limits<T>.min() for systems that don't have the limits c++ header file.

Definition at line 48 of file rmath.h.

template<typename T >
static const T min_limit ( const T &  a_arg)
static

Return the min_limit of a variable.

This is handy to have because it means that the author may change the type of a variable without having to track down all uses of max_limit or min_limit to change the type they measure.

Definition at line 165 of file rmath.h.

template<>
const double min_limit< double > ( )

Return the smallest positive number that a double may hold.

Caveat: This is in contrast to other types, where min_limit<T>() will return either 0 or the largest possible negative number that the type may hold. If you are looking for the largest possible negative number for any given type, use lowest_value<T>() instead.

Definition at line 134 of file rmath.h.

Referenced by test4().

template<>
const float min_limit< float > ( )

Return the smallest positive number that a float may hold.

Caveat: This is in contrast to other types, where min_limit<T>() will return either 0 or the largest possible negative number that the type may hold. If you are looking for the largest possible negative number for any given type, use lowest_value<T>() instead.

Definition at line 104 of file rmath.h.

Referenced by test4().

template<typename T >
safe_num<T> operator% ( safe_num< T >  a_class1,
safe_num< T >  a_class2 
)

Arithmetic operator.

Definition at line 745 of file rmath.h.

References safe_num< T >::assign(), and safe_num< T >::value().

Here is the call graph for this function:

template<typename T >
safe_num<T> operator* ( safe_num< T >  a_class1,
safe_num< T >  a_class2 
)

Arithmetic operator.

Definition at line 721 of file rmath.h.

References safe_num< T >::assign(), and safe_num< T >::multiply().

Here is the call graph for this function:

template<typename T >
safe_num<T> operator+ ( safe_num< T >  a_class1,
safe_num< T >  a_class2 
)

Arithmetic operator.

Definition at line 697 of file rmath.h.

References safe_num< T >::add(), and safe_num< T >::assign().

Here is the call graph for this function:

template<typename T >
safe_num<T>& operator++ ( safe_num< T > &  a_class)

Arithmetic operator.

Definition at line 756 of file rmath.h.

References safe_num< T >::add().

Here is the call graph for this function:

template<typename T >
safe_num<T> operator++ ( safe_num< T > &  a_class,
int   
)

Arithmetic operator.

Definition at line 765 of file rmath.h.

References safe_num< T >::add(), and safe_num< T >::assign().

Here is the call graph for this function:

template<typename T >
safe_num<T> operator- ( safe_num< T >  a_class1,
safe_num< T >  a_class2 
)

Arithmetic operator.

Definition at line 709 of file rmath.h.

References safe_num< T >::assign(), and safe_num< T >::subtract().

Here is the call graph for this function:

template<typename T >
safe_num<T>& operator-- ( safe_num< T > &  a_class)

Arithmetic operator.

Definition at line 777 of file rmath.h.

References safe_num< T >::subtract().

Here is the call graph for this function:

template<typename T >
safe_num<T> operator-- ( safe_num< T > &  a_class,
int   
)

Arithmetic operator.

Definition at line 786 of file rmath.h.

References safe_num< T >::assign(), and safe_num< T >::subtract().

Here is the call graph for this function:

template<typename T >
safe_num<T> operator/ ( safe_num< T >  a_class1,
safe_num< T >  a_class2 
)

Arithmetic operator.

Definition at line 733 of file rmath.h.

References safe_num< T >::assign(), and safe_num< T >::divide().

Here is the call graph for this function:

template<typename T >
std::ostream& operator<< ( std::ostream &  a_out,
safe_num< T >  a_class 
)

Arithmetic operator.

Definition at line 798 of file rmath.h.

template<typename T >
std::istream& operator>> ( std::istream &  a_in,
safe_num< T > &  a_class 
)

Arithmetic operator.

Definition at line 807 of file rmath.h.