Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Numerics Namespace Reference

Functions

double AbsoluteValue (double a)
 Returns the absolute value of the value a. More...
 
double ___safe_fpt_division (const double f1, const double f2)
 Performs a safe floating point division f1/f2. More...
 
bool fpointequals (const double a, const double b, double TOL=1e-9)
 Checks if two floating numbers are "nearly" equal. More...
 

Function Documentation

double Numerics::___safe_fpt_division ( const double  f1,
const double  f2 
)
inline

Performs a safe floating point division f1/f2.

Parameters
f1numerator
f2denominator
Returns
f1/f2
Precondition
f1 >= 0
f2 >= 0
Postcondition
0 <= f1/f2 <= std::numeric_limits<double>::max( )

Definition at line 37 of file FloatingPointComparisson.hpp.

References max(), and min().

Referenced by fpointequals().

38  {
39  #ifdef ASSERT_ON
40  assert( f1 >= static_cast< double >( 0 ) );
41  assert( f2 >= static_cast< double >( 0 ) );
42  #endif
43 
44  /* Avoid overflow */
45  if( f2 < static_cast< double >( 1 ) && f1 > f2*std::numeric_limits< double >::max( ) )
47 
48 
49  /* Avoid underflow */
50  if( f1 == static_cast< double >( 0 ) ||
51  f2 > static_cast< double >( 1 ) && f1 < f2*std::numeric_limits< double >::min( ) )
52  return static_cast< double >( 0 );
53 
54  return( f1/f2 );
55  }
Vector_n max(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:354
Vector_n min(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:346

Here is the call graph for this function:

Here is the caller graph for this function:

double Numerics::AbsoluteValue ( double  a)
inline

Returns the absolute value of the value a.

Parameters
athe value whose absolute value is queried
Returns
abs the absolute value of a abs( a ).
Postcondition
abs > 0

Definition at line 23 of file FloatingPointComparisson.hpp.

Referenced by fpointequals().

24  {
25  return( ( ( a < static_cast< double >( 0 ) )? -a : a ) );
26  }

Here is the caller graph for this function:

bool Numerics::fpointequals ( const double  a,
const double  b,
double  TOL = 1e-9 
)
inline

Checks if two floating numbers are "nearly" equal.

Parameters
afirst floating number to check
bsecond floating number to check
Returns
s true if a =~ b, else false.
Note
This implementation is based on Knuth, The Art of Computer Programming (vol II).

Definition at line 64 of file FloatingPointComparisson.hpp.

References ___safe_fpt_division(), AbsoluteValue(), and GeoPrim::TOL.

Referenced by BoundingBox::hasPoint().

65  {
66  double diff = a-b;
67  double adiff = AbsoluteValue( diff );
68  double d1 = ___safe_fpt_division( adiff, AbsoluteValue( a ) );
69  double d2 = ___safe_fpt_division( adiff, AbsoluteValue( b ) );
70  bool predicate1 = (d1 <= TOL);
71  bool predicate2 = (d2 <= TOL);
72 
73  if( (predicate1 || predicate2) )
74  return true;
75  return false;
76  }
const double TOL
Definition: GeoPrimitives.H:17
double AbsoluteValue(double a)
Returns the absolute value of the value a.
double ___safe_fpt_division(const double f1, const double f2)
Performs a safe floating point division f1/f2.

Here is the call graph for this function:

Here is the caller graph for this function: