Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Infinite< Type > Class Template Reference

#include <Infinite.h>

List of all members.


Detailed Description

template<class Type>
class Infinite< Type >

Infinite is a class that allows for values to be stored as negative or positive infinity in addition to standard integer/floating point values.

This class is needed because there is currently no standard method of handling math operations when one or both operands of a math operator (such as +,-,*,/) is either negative infinity or positive infinity. This class attempts to handle most of the basic math and comparion operators. One notable exception: If both of the operands are valid non-infinite numbers and you attempt to do a math operation which would result in overflow, this class does NOT currently catch the condition and set the appropriate infinity value!

So, how do you use this class? Currently, this class will handle only ints, floats, doubles, and long doubles. You declare a new Infinite instance by passing in the type to the template. For example, if you want to use "standard" double math, but want to be able to keep track of infinity conditions, you would do:

Infinite<double> a;

The default constructor would set the value of a to be 0.0. You can then do many of the typical math operations as if it was a simple double type. Also, this class has adapters to automatically promote base types to Infinite types and to demote Infinite types to base types. This allows you to combine base types and Infinite types with the standard math/comparison operators.

There are two class (static) member constants to represent positive infinity (I_INF) and negative infinity (I_NEGINF). So if you wanted to create a couple of new Infinite instances with positive and negative infinity values, you would do something like this:

Infinite<double> my_infinity(Infinite<double>::I_INF); Infinite<double> my_negative_infinity(Infinite<double>::I_NEGINF);

Notice that you need to actually declare the type when referencing I_INF and I_NEGINF. This is so that the interal constants can be set to the largest available number depending on the type.

Some of the various operations on one or two infinite valued arguments are not well defined. In the chart below, you will find the results of the various math and comparion operators. NOTICE that I have redefined the bitwise operator (^) to act as a power function. You can still do a.pow(b), and you can also do a^b. Cool!


+I = positive infinity -I = negative infinity 0 = the value zero x = a value that is neither infinite nor zero # = results that should probably be 'undefined' - maybe change later?

Mathematical Operations a b -a e^a a+b a-b a*b a/b a^b --- --- --- --- --- ------ ----------- ----------- ---------------------- +I +I -I +I +I a+(-b) +I 0 +I +I -I 0# -I 0 0 -I -I +I 0 -I +I 0 0 -I +I 0# -I 0 +I# 0 +I 0 1 +I 0 0 0 0 -I -I 0 0 0 +I 0 +I 0 +I# 1 -I 0 -I 0 -I# 1 x +I -x e^x +I (x>0)?+I:-I 0 +I x -I -I (x>0)?-I:+I 0 0 +I x +I (x>0)?+I:-I (x>0)?+I:-I (x<0)?0:+I -I x -I (x>0)?-I:+I (x>0)?-I:+I (x<0)?0:(odd(b)?-I:+I)

Logical Operations a b a <= b a >= b a < b a > b --- --- ------ ------ ------- ------- +I +I T T !(a>=b) !(a<=b) +I -I F T -I -I T T -I +I T F 0 +I T F 0 -I F T +I 0 F T -I 0 T F x +I T F x -I F T +I x F T -I x T F

Note:
Currently, this class does NOT handle overflow conditions when you do a valid math operation on two non-infinite values but would end up with a value that is out of range of the underlying datatype.

Todo:
Check for overflow on +,-,*,/ when the two values are not I_INF or I_NEGINF (ie. would use a "standard" math operator).

Definition at line 122 of file Infinite.h.

Function Methods @{

Infinite fabs () const
 Returns the absolute value of the object.

Infinite operator- () const
 Unary negation.

Infinite exp () const
 Returns e to the power of the Infinite object.

Infinite sqrt () const
 Returns the square root of the Infinite object.

Infinite pow (const Infinite &x) const
 Power function for Infinite types, returns object^x.

Infinite pow (const Type &x) const
 Power function for basic types, returns object^x.

Infinite min (const Type &x, const Type &y)
 Minimum of two basic types.

Infinite max (const Type &x, const Type &y)
 Maximum of two basic types.


Public Member Functions

Constructors @{
 Infinite (Type x=0)
 Default constructor.

Interrogation @{
Type val () const
 Returns the value of the object as a basic type (eg. int, double).

bool isInfinite () const
 Returns true if the value is I_INF (positive infinity).

bool isPositiveInfinite () const
 Returns true if the value is I_INF (positive infinity).

bool isNegativeInfinite () const
 Returns true if the value is I_NEGINF (negative infinity).

bool hasInfiniteValue () const
 Returns true if the value is either I_INF or I_NEGINF.

 operator Type () const
 A type conversion operator.

Mathematical Operators @{
Infiniteoperator+= (const Infinite &x)
 Addition/assignment operator for Infinite types.

Infiniteoperator+= (const Type &x)
 Addition/assignment operator for basic types.

Infiniteoperator-= (const Infinite &x)
 Subtraction/assignment operator for Infinite types.

Infiniteoperator-= (const Type &x)
 Subtraction/assignment operator for basic types.

Infiniteoperator *= (const Infinite &x)
 Multiplication/assignment operator for Infinite types.

Infiniteoperator *= (const Type &x)
 Multiplication/assignment operator for basic types.

Infiniteoperator/= (const Infinite &x)
 Division/assignment operator for Infinite types.

Infiniteoperator/= (const Type &x)
 Division/assignment operator for basic types.

Infiniteoperator^= (const Infinite &x)
 Power/assignment operator for Infinite types.

Infiniteoperator^= (const Type &x)
 Power/assignment operator for basic types.


Static Public Attributes

const Type I_INF
 The class constant for positive infinity.

const Type I_NEGINF = (-Infinite<Type>::I_INF)
 The class constant for negative infinity.


Private Attributes

Type _val
 The value of the number.


Constructor & Destructor Documentation

template<class Type>
Infinite< Type >::Infinite Type  x = 0  ) 
 

Default constructor.

Definition at line 503 of file Infinite.h.

References Infinite< Type >::_val.

Referenced by Infinite< Type >::exp(), and Infinite< Type >::operator-().


Member Function Documentation

template<class Type>
Infinite< Type > Infinite< Type >::exp  )  const
 

Returns e to the power of the Infinite object.

Definition at line 570 of file Infinite.h.

References Infinite< Type >::_val, Infinite< Type >::Infinite(), Infinite< Type >::isInfinite(), and Infinite< Type >::isNegativeInfinite().

template<class Type>
Infinite< Type > Infinite< Type >::fabs  )  const
 

Returns the absolute value of the object.

Definition at line 556 of file Infinite.h.

References Infinite< Type >::_val.

template<class Type>
bool Infinite< Type >::hasInfiniteValue  )  const
 

Returns true if the value is either I_INF or I_NEGINF.

Definition at line 542 of file Infinite.h.

References Infinite< Type >::isInfinite(), and Infinite< Type >::isNegativeInfinite().

Referenced by Infinite< Type >::operator *=(), Infinite< Type >::operator/=(), and operator>=().

template<class Type>
bool Infinite< Type >::isInfinite  )  const
 

Returns true if the value is I_INF (positive infinity).

Definition at line 521 of file Infinite.h.

References Infinite< Type >::_val, and Infinite< Type >::I_INF.

Referenced by Infinite< Type >::exp(), Infinite< Type >::hasInfiniteValue(), Infinite< Type >::isPositiveInfinite(), Infinite< Type >::operator *=(), Infinite< Type >::operator+=(), Infinite< Type >::operator/=(), operator>=(), Infinite< Type >::operator^=(), and Infinite< Type >::sqrt().

template<class Type>
bool Infinite< Type >::isNegativeInfinite  )  const
 

Returns true if the value is I_NEGINF (negative infinity).

Definition at line 535 of file Infinite.h.

References Infinite< Type >::_val, and Infinite< Type >::I_NEGINF.

Referenced by Infinite< Type >::exp(), Infinite< Type >::hasInfiniteValue(), Infinite< Type >::operator *=(), Infinite< Type >::operator+=(), Infinite< Type >::operator/=(), operator>=(), Infinite< Type >::operator^=(), and Infinite< Type >::sqrt().

template<class Type>
bool Infinite< Type >::isPositiveInfinite  )  const
 

Returns true if the value is I_INF (positive infinity).

Definition at line 528 of file Infinite.h.

References Infinite< Type >::isInfinite().

template<class Type>
Infinite< Type > Infinite< Type >::max const Type &  x,
const Type &  y
[static]
 

Maximum of two basic types.

Definition at line 623 of file Infinite.h.

Referenced by Box< Float >::lengthSquared().

template<class Type>
Infinite< Type > Infinite< Type >::min const Type &  x,
const Type &  y
[static]
 

Minimum of two basic types.

Definition at line 616 of file Infinite.h.

Referenced by Box< Float >::lengthSquared().

template<class Type>
Infinite< Type > & Infinite< Type >::operator *= const Type &  x  ) 
 

Multiplication/assignment operator for basic types.

Definition at line 695 of file Infinite.h.

template<class Type>
Infinite< Type > & Infinite< Type >::operator *= const Infinite< Type > &  x  ) 
 

Multiplication/assignment operator for Infinite types.

Definition at line 667 of file Infinite.h.

References Infinite< Type >::_val, Infinite< Type >::hasInfiniteValue(), Infinite< Type >::I_INF, Infinite< Type >::I_NEGINF, Infinite< Type >::isInfinite(), Infinite< Type >::isNegativeInfinite(), and Infinite< Type >::val().

template<class Type>
Infinite< Type >::operator Type  )  const
 

A type conversion operator.

Definition at line 549 of file Infinite.h.

References Infinite< Type >::_val.

template<class Type>
Infinite< Type > & Infinite< Type >::operator+= const Type &  x  ) 
 

Addition/assignment operator for basic types.

Definition at line 646 of file Infinite.h.

template<class Type>
Infinite< Type > & Infinite< Type >::operator+= const Infinite< Type > &  x  ) 
 

Addition/assignment operator for Infinite types.

Definition at line 630 of file Infinite.h.

References Infinite< Type >::_val, Infinite< Type >::I_INF, Infinite< Type >::I_NEGINF, Infinite< Type >::isInfinite(), and Infinite< Type >::isNegativeInfinite().

template<class Type>
Infinite< Type > Infinite< Type >::operator-  )  const
 

Unary negation.

Definition at line 563 of file Infinite.h.

References Infinite< Type >::_val, and Infinite< Type >::Infinite().

template<class Type>
Infinite< Type > & Infinite< Type >::operator-= const Type &  x  ) 
 

Subtraction/assignment operator for basic types.

Definition at line 660 of file Infinite.h.

template<class Type>
Infinite< Type > & Infinite< Type >::operator-= const Infinite< Type > &  x  ) 
 

Subtraction/assignment operator for Infinite types.

Definition at line 653 of file Infinite.h.

template<class Type>
Infinite< Type > & Infinite< Type >::operator/= const Type &  x  ) 
 

Division/assignment operator for basic types.

Definition at line 719 of file Infinite.h.

template<class Type>
Infinite< Type > & Infinite< Type >::operator/= const Infinite< Type > &  x  ) 
 

Division/assignment operator for Infinite types.

Definition at line 702 of file Infinite.h.

References Infinite< Type >::_val, Infinite< Type >::hasInfiniteValue(), Infinite< Type >::I_INF, Infinite< Type >::I_NEGINF, Infinite< Type >::isInfinite(), Infinite< Type >::isNegativeInfinite(), and Infinite< Type >::val().

template<class Type>
Infinite< Type > & Infinite< Type >::operator^= const Type &  x  ) 
 

Power/assignment operator for basic types.

Definition at line 751 of file Infinite.h.

template<class Type>
Infinite< Type > & Infinite< Type >::operator^= const Infinite< Type > &  x  ) 
 

Power/assignment operator for Infinite types.

Definition at line 726 of file Infinite.h.

References Infinite< Type >::_val, Infinite< Type >::I_INF, Infinite< Type >::I_NEGINF, Infinite< Type >::isInfinite(), Infinite< Type >::isNegativeInfinite(), and Infinite< Type >::val().

template<class Type>
Infinite< Type > Infinite< Type >::pow const Type &  x  )  const
 

Power function for basic types, returns object^x.

Definition at line 608 of file Infinite.h.

template<class Type>
Infinite< Type > Infinite< Type >::pow const Infinite< Type > &  x  )  const
 

Power function for Infinite types, returns object^x.

Definition at line 600 of file Infinite.h.

Referenced by Box< Float >::lengthSquared().

template<class Type>
Infinite< Type > Infinite< Type >::sqrt  )  const
 

Returns the square root of the Infinite object.

Bug:
Should raise an error flag when called on -INF, but currently returns 0.

Definition at line 588 of file Infinite.h.

References Infinite< Type >::_val, Infinite< Type >::isInfinite(), and Infinite< Type >::isNegativeInfinite().

template<class Type>
Type Infinite< Type >::val  )  const
 

Returns the value of the object as a basic type (eg. int, double).

Definition at line 514 of file Infinite.h.

References Infinite< Type >::_val.

Referenced by Infinite< Type >::operator *=(), Infinite< Type >::operator/=(), operator==(), operator>=(), and Infinite< Type >::operator^=().


Member Data Documentation

template<class Type>
Type Infinite< Type >::_val [private]
 

The value of the number.

Definition at line 125 of file Infinite.h.

Referenced by Infinite< Type >::exp(), Infinite< Type >::fabs(), Infinite< Type >::Infinite(), Infinite< Type >::isInfinite(), Infinite< Type >::isNegativeInfinite(), Infinite< Type >::operator *=(), Infinite< Type >::operator Type(), Infinite< Type >::operator+=(), Infinite< Type >::operator-(), Infinite< Type >::operator/=(), Infinite< Type >::operator^=(), Infinite< Type >::sqrt(), and Infinite< Type >::val().

template<class Type>
const Type Infinite< Type >::I_INF [static]
 

Initial value:

 (((Type)0.5 == 0.5) ? 
      ((sizeof(Type) == sizeof(float)) ? FLT_MAX : DBL_MAX) : INT_MAX)
The class constant for positive infinity.

Definition at line 175 of file Infinite.h.

Referenced by Infinite< Type >::isInfinite(), Infinite< Type >::operator *=(), Infinite< Type >::operator+=(), Infinite< Type >::operator/=(), and Infinite< Type >::operator^=().

template<class Type>
const Type Infinite< Type >::I_NEGINF = (-Infinite<Type>::I_INF) [static]
 

The class constant for negative infinity.

Definition at line 180 of file Infinite.h.

Referenced by Infinite< Type >::isNegativeInfinite(), Infinite< Type >::operator *=(), Infinite< Type >::operator+=(), Infinite< Type >::operator/=(), and Infinite< Type >::operator^=().


The documentation for this class was generated from the following file:
Generated on Fri Sep 1 04:11:01 2006 for The WickBert Particle and Surface Library by doxygen 1.3.6