#include <Infinite.h>
Collaboration diagram for Infinite< Type >:

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
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 @{ | |
| Infinite & | operator+= (const Infinite &x) |
| Addition/assignment operator for Infinite types. | |
| Infinite & | operator+= (const Type &x) |
| Addition/assignment operator for basic types. | |
| Infinite & | operator-= (const Infinite &x) |
| Subtraction/assignment operator for Infinite types. | |
| Infinite & | operator-= (const Type &x) |
| Subtraction/assignment operator for basic types. | |
| Infinite & | operator *= (const Infinite &x) |
| Multiplication/assignment operator for Infinite types. | |
| Infinite & | operator *= (const Type &x) |
| Multiplication/assignment operator for basic types. | |
| Infinite & | operator/= (const Infinite &x) |
| Division/assignment operator for Infinite types. | |
| Infinite & | operator/= (const Type &x) |
| Division/assignment operator for basic types. | |
| Infinite & | operator^= (const Infinite &x) |
| Power/assignment operator for Infinite types. | |
| Infinite & | operator^= (const Type &x) |
| Power/assignment operator for basic types. | |
Static Public Attributes | |
Class Constants @{ | |
| const Type | I_INF |
| Class-wide constant for positive infinity. | |
| const Type | I_NEGINF = (-Infinite<Type>::I_INF) |
| Class-wide constant for negative infinity. | |
Private Attributes | |
| Type | _val |
| The value of the number. | |
|
||||||||||
|
Default constructor.
Definition at line 11 of file Infinite.cpp. References Infinite< Type >::_val. Referenced by Infinite< Type >::exp(), and Infinite< Type >::operator-(). |
|
|||||||||
|
Returns e to the power of the Infinite object.
Definition at line 78 of file Infinite.cpp. References Infinite< Type >::_val, Infinite< Type >::Infinite(), Infinite< Type >::isInfinite(), and Infinite< Type >::isNegativeInfinite(). |
|
|||||||||
|
Returns the absolute value of the object.
Definition at line 64 of file Infinite.cpp. References Infinite< Type >::_val. |
|
|||||||||
|
Returns true if the value is either I_INF or I_NEGINF.
Definition at line 50 of file Infinite.cpp. References Infinite< Type >::isInfinite(), and Infinite< Type >::isNegativeInfinite(). Referenced by Infinite< Type >::operator *=(), Infinite< Type >::operator/=(), and operator>=(). |
|
|||||||||
|
Returns true if the value is I_INF (positive infinity).
Definition at line 29 of file Infinite.cpp. 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(). |
|
|||||||||
|
Returns true if the value is I_NEGINF (negative infinity).
Definition at line 43 of file Infinite.cpp. 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(). |
|
|||||||||
|
Returns true if the value is I_INF (positive infinity).
Definition at line 36 of file Infinite.cpp. References Infinite< Type >::isInfinite(). |
|
||||||||||||||||
|
Maximum of two basic types.
Definition at line 131 of file Infinite.cpp. Referenced by Box< Float >::lengthSquared(), and Interval< Type >::pow(). |
|
||||||||||||||||
|
Minimum of two basic types.
Definition at line 124 of file Infinite.cpp. Referenced by Box< Float >::lengthSquared(). |
|
||||||||||
|
Multiplication/assignment operator for basic types.
Definition at line 203 of file Infinite.cpp. |
|
||||||||||
|
Multiplication/assignment operator for Infinite types.
Definition at line 175 of file Infinite.cpp. 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(). |
|
|||||||||
|
A type conversion operator.
Definition at line 57 of file Infinite.cpp. References Infinite< Type >::_val. |
|
||||||||||
|
Addition/assignment operator for basic types.
Definition at line 154 of file Infinite.cpp. |
|
||||||||||
|
Addition/assignment operator for Infinite types.
Definition at line 138 of file Infinite.cpp. References Infinite< Type >::_val, Infinite< Type >::I_INF, Infinite< Type >::I_NEGINF, Infinite< Type >::isInfinite(), and Infinite< Type >::isNegativeInfinite(). |
|
|||||||||
|
Unary negation.
Definition at line 71 of file Infinite.cpp. References Infinite< Type >::_val, and Infinite< Type >::Infinite(). |
|
||||||||||
|
Subtraction/assignment operator for basic types.
Definition at line 168 of file Infinite.cpp. |
|
||||||||||
|
Subtraction/assignment operator for Infinite types.
Definition at line 161 of file Infinite.cpp. |
|
||||||||||
|
Division/assignment operator for basic types.
Definition at line 227 of file Infinite.cpp. |
|
||||||||||
|
Division/assignment operator for Infinite types.
Definition at line 210 of file Infinite.cpp. 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(). |
|
||||||||||
|
Power/assignment operator for basic types.
Definition at line 259 of file Infinite.cpp. |
|
||||||||||
|
Power/assignment operator for Infinite types.
Definition at line 234 of file Infinite.cpp. References Infinite< Type >::_val, Infinite< Type >::I_INF, Infinite< Type >::I_NEGINF, Infinite< Type >::isInfinite(), Infinite< Type >::isNegativeInfinite(), and Infinite< Type >::val(). |
|
||||||||||
|
Power function for basic types, returns object^x.
Definition at line 116 of file Infinite.cpp. |
|
||||||||||
|
Power function for Infinite types, returns object^x.
Definition at line 108 of file Infinite.cpp. Referenced by Box< Float >::lengthSquared(). |
|
|||||||||
|
Returns the square root of the Infinite object.
Definition at line 96 of file Infinite.cpp. References Infinite< Type >::_val, Infinite< Type >::isInfinite(), and Infinite< Type >::isNegativeInfinite(). |
|
|||||||||
|
Returns the value of the object as a basic type (eg. int, double).
Definition at line 22 of file Infinite.cpp. References Infinite< Type >::_val. Referenced by Infinite< Type >::operator *=(), Infinite< Type >::operator/=(), operator==(), operator>=(), and Infinite< Type >::operator^=(). |
|
|||||
|
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(). |
|
|||||
|
Initial value: (((Type)0.5 == 0.5) ?
((sizeof(Type) == sizeof(float)) ? FLT_MAX : DBL_MAX) : INT_MAX)
Definition at line 179 of file Infinite.h. Referenced by Infinite< Type >::isInfinite(), Infinite< Type >::operator *=(), Infinite< Type >::operator+=(), Infinite< Type >::operator/=(), and Infinite< Type >::operator^=(). |
|
|||||
|
Class-wide constant for negative infinity.
Definition at line 184 of file Infinite.h. Referenced by Infinite< Type >::isNegativeInfinite(), Infinite< Type >::operator *=(), Infinite< Type >::operator+=(), Infinite< Type >::operator/=(), and Infinite< Type >::operator^=(). |
1.3.4