Chaste  Release::2018.1
MathsCustomFunctions.hpp File Reference
#include <cfloat>
+ Include dependency graph for MathsCustomFunctions.hpp:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  CompareDoubles
 

Functions

double SmallPow (double x, unsigned exponent)
 
unsigned SmallPow (unsigned x, unsigned exponent)
 
bool Divides (double smallerNumber, double largerNumber)
 
unsigned CeilDivide (unsigned numerator, unsigned denominator)
 
double Signum (double value)
 
double SafeDivide (double numerator, double divisor)
 

Detailed Description

This file contains some utility functions and a small class for dealing with floating point numbers.

Definition in file MathsCustomFunctions.hpp.

Function Documentation

unsigned CeilDivide ( unsigned  numerator,
unsigned  denominator 
)
Returns
the result of dividing (unsigned) numerator by denominator, rounded up (away from 0), and overflow-safe for large integers up to UINT_MAX.
Parameters
numeratorthe numerator
denominatorthe denominator

Definition at line 137 of file MathsCustomFunctions.cpp.

Referenced by Hdf5DataWriter::CalculateChunkDims(), and Hdf5DataWriter::CalculateNumberOfChunks().

bool Divides ( double  smallerNumber,
double  largerNumber 
)
Returns
true if the smaller number divides the larger (to machine precision) Uses fmod to determine if smallerNumber divides the largerNumber. We expect smallerNumber/largerNumber <= 1 and therefore fmod(largerNumber,smallerNumber) should be close to zero or close to smallerNumber.
Parameters
smallerNumberthe smaller
largerNumberthe larger

Definition at line 114 of file MathsCustomFunctions.cpp.

Referenced by HeartConfig::CheckTimeSteps(), SingleTraceOutputModifier::ProcessSolutionAtTimeStep(), and TimeStepper::TimeStepper().

double SafeDivide ( double  numerator,
double  divisor 
)
Returns
the results of dividing two non-negative floating point numbers, avoiding overflow and underflow.
Parameters
numeratorthe number to be divided
divisorthe number to divide by

Definition at line 160 of file MathsCustomFunctions.cpp.

Referenced by CompareDoubles::Difference(), and CompareDoubles::WithinRelativeTolerance().

double Signum ( double  value)
Returns
the sign of the argument, i.e. -1 if value<0, 0 if value=0, or +1 if value>0.
Parameters
valuethe argument value

Definition at line 150 of file MathsCustomFunctions.cpp.

unsigned SmallPow ( unsigned  x,
unsigned  exponent 
)

Replacement "pow" function for unsigned integer values

Parameters
xnumber to be raised to a small power
exponentsmall integer exponent
Returns
x^exponent a.k.a x**exponent.

Definition at line 77 of file MathsCustomFunctions.cpp.

References SmallPow().