ACF $AcfVersion:0$
Public Types | Public Member Functions | Static Public Member Functions | List of all members
imath::CDouble Class Reference

Wrapper class for double precision floating-point values with rounding utilities. More...

#include <CDouble.h>

Inheritance diagram for imath::CDouble:
imath::TVector< 1 >

Public Types

typedef TVector< 1 > BaseClass
 
- Public Types inherited from imath::TVector< 1 >
typedef double ElementType
 
typedef double Elements[Size]
 

Public Member Functions

 CDouble (double value=0.0)
 
 CDouble (const BaseClass &value)
 
CDouble GetRounded (int precision=2) const
 Get rounded value.
 
bool IsRoundedEqual (const CDouble &value, int precision=2) const
 Check if two values are equal after rounding.
 
CDouble GetRoundedDown (int precision=2) const
 Get rounded down value with specified precision.
 
bool IsRoundedDownEqual (const CDouble &value, int precision=2) const
 Check if two values are equal after rounding down.
 
CDouble GetRoundedUp (int precision=2) const
 Get rounded down value with specified precision.
 
bool IsRoundedUpEqual (const CDouble &value, int precision=2) const
 Check if two values are equal after rounding down.
 
bool IsSimiliar (const CDouble &value, double tolerance=I_BIG_EPSILON) const
 Check if two values are similiar with specified tolerance.
 
 operator double () const
 
bool operator== (const CDouble &value) const
 
bool operator!= (const CDouble &value) const
 
bool operator< (const CDouble &value) const
 
bool operator> (const CDouble &value) const
 
bool operator<= (const CDouble &value) const
 
bool operator>= (const CDouble &value) const
 
CDouble operator+ (const CDouble &value) const
 
CDouble operator- (const CDouble &value) const
 
CDouble operator* (const CDouble &value) const
 
CDouble operator/ (const CDouble &value) const
 
const CDoubleoperator= (const CDouble &value)
 
const CDoubleoperator+= (const CDouble &value)
 
const CDoubleoperator-= (const CDouble &value)
 
const CDoubleoperator*= (const CDouble &value)
 
const CDoubleoperator/= (const CDouble &value)
 
- Public Member Functions inherited from imath::TVector< 1 >
 TVector ()
 Creates an uninitialized vector.
 
 TVector (const TVector< Size, double > &vector)
 Creates a copy of another vector.
 
 TVector (std::initializer_list< double > values)
 Creates a vector from an initializer list.
 
const double & GetElement (int i) const
 Gets the element at the specified index (read-only).
 
double & GetElementRef (int i)
 Gets a reference to the element at the specified index (read-write).
 
void SetElement (int i, const double &value)
 Sets the element at the specified index.
 
void SetAllElements (const double &value)
 Sets all elements to the same value.
 
void Reset ()
 Sets all coordinates to zero.
 
void Clear ()
 Sets all coordinates to zero.
 
const TVector< Size, double >::Elements & GetElements () const
 Get read-only access to internal element container.
 
TVector< Size, double >::Elements & GetElementsRef ()
 Get access to internal element container.
 
void Translate (const TVector< Size, double > &vector)
 Translates (adds) another vector to this vector.
 
TVector< Size, double > GetTranslated (const TVector< Size, double > &vector)
 Returns a new vector that is the translation of this vector.
 
void GetTranslated (const TVector< Size, double > &vector, TVector< Size, double > &result)
 Computes the translated vector and stores it in the result parameter.
 
void ScaledCumulate (const TVector< Size, double > &vector, double scale)
 Adds a scaled vector to this vector.
 
bool IsNull (double tolerance=I_BIG_EPSILON) const
 Checks if this vector is null (all elements approximately zero).
 
double GetDotProduct (const TVector< Size, double > &vector) const
 Calculates the dot product with another vector.
 
double GetLength2 () const
 Calculates the squared Euclidean length of the vector.
 
double GetLength () const
 Calculates the Euclidean length (magnitude) of the vector.
 
double GetDistance2 (const TVector< Size, double > &vector) const
 Calculates the squared distance to another vector.
 
double GetDistance (const TVector< Size, double > &vector) const
 Calculates the Euclidean distance to another vector.
 
double GetElementsSum () const
 Calculates the sum of all vector elements.
 
bool Normalize (double length=1.0)
 Normalizes the vector to a specified length.
 
bool GetNormalized (TVector< Size, double > &result, double length=1.0) const
 Returns a normalized copy of this vector with specified length.
 
void GetMinimal (const TVector< Size, double > &vector, TVector< Size, double > &result) const
 Get vector with minimal elements values.
 
void GetMaximal (const TVector< Size, double > &vector, TVector< Size, double > &result) const
 Get vector with maximal elements values.
 
bool Serialize (iser::IArchive &archive)
 Serialize this vector to specified archive.
 
bool operator== (const TVector< Size, double > &vector) const
 
bool operator!= (const TVector< Size, double > &vector) const
 
bool operator< (const TVector< Size, double > &vector) const
 
bool operator> (const TVector< Size, double > &vector) const
 
bool operator<= (const TVector< Size, double > &vector) const
 
bool operator>= (const TVector< Size, double > &vector) const
 
TVector< Size, double > & operator= (const TVector< Size, double > &vector)=default
 
TVector< Size, double > operator- () const
 
TVector< Size, double > operator- (const TVector< Size, double > &vector) const
 
TVector< Size, double > operator+ (const TVector< Size, double > &vector) const
 
TVector< Size, double > operator* (double scalar) const
 
TVector< Size, double > operator/ (double scalar) const
 
TVector< Size, double > & operator+= (const TVector< Size, double > &vector)
 
TVector< Size, double > & operator-= (const TVector< Size, double > &vector)
 
TVector< Size, double > & operator*= (double scalar)
 
TVector< Size, double > & operator/= (double scalar)
 
const double & operator[] (int i) const
 
double & operator[] (int i)
 

Static Public Member Functions

static double GetRounded (double value, int precision=2)
 
static bool IsRoundedEqual (double value1, double value2, int precision=2)
 
static double GetRoundedDown (double value, int precision=2)
 
static bool IsRoundedDownEqual (double value1, double value2, int precision=2)
 
static double GetRoundedUp (double value, int precision=2)
 
static bool IsRoundedUpEqual (double value1, double value2, int precision=2)
 
static bool IsSimiliar (double value1, double value2, double tolerance=I_BIG_EPSILON)
 
- Static Public Member Functions inherited from imath::TVector< 1 >
static int GetElementsCount ()
 Get number of elements.
 
static bool SetElementsCount (int count)
 Set number of elements.
 
static const TVector< Size, double > & GetZero ()
 Get vector with all coordinates set to 0.
 

Additional Inherited Members

- Protected Attributes inherited from imath::TVector< 1 >
Elements m_elements
 

Detailed Description

Wrapper class for double precision floating-point values with rounding utilities.

Purpose

CDouble provides a convenient wrapper around double precision floating-point values, offering arithmetic operators and specialized rounding/comparison methods. Built on top of TVector<1>, it combines the benefits of vector operations with double-specific functionality for numerical computations requiring controlled precision.

Key Features

Usage Examples

// Basic construction and arithmetic
imath::CDouble value1(3.14159);
imath::CDouble value2(2.71828);
imath::CDouble sum = value1 + value2; // 5.85987
// Rounding to specified precision
imath::CDouble pi(3.14159265359);
imath::CDouble rounded = pi.GetRounded(2); // 3.14
imath::CDouble roundedDown = pi.GetRoundedDown(3); // 3.141
imath::CDouble roundedUp = pi.GetRoundedUp(3); // 3.142
// Comparison with rounding
imath::CDouble val1(3.14159);
imath::CDouble val2(3.14151);
if (val1.IsRoundedEqual(val2, 2)) {
// true - both round to 3.14
}
// Tolerance-based comparison (for floating-point equality)
imath::CDouble a(1.0000001);
imath::CDouble b(1.0000002);
if (a.IsSimiliar(b, 1e-6)) {
// true - difference is within tolerance
}
// Using static methods
double d1 = 2.718281828;
double rounded = imath::CDouble::GetRounded(d1, 4); // 2.7183
bool similar = imath::CDouble::IsSimiliar(2.0, 2.0000001, 1e-6); // true
// Implicit conversion
imath::CDouble value(5.5);
double d = value; // Implicit conversion to double
value = 7.2; // Implicit conversion from double
Wrapper class for double precision floating-point values with rounding utilities.
Definition CDouble.h:96
CDouble GetRoundedUp(int precision=2) const
Get rounded down value with specified precision.
Definition CDouble.h:215
CDouble GetRounded(int precision=2) const
Get rounded value.
Definition CDouble.h:191
CDouble GetRoundedDown(int precision=2) const
Get rounded down value with specified precision.
Definition CDouble.h:203
bool IsSimiliar(const CDouble &value, double tolerance=I_BIG_EPSILON) const
Check if two values are similiar with specified tolerance.
Definition CDouble.h:227

When to Use

Use CDouble when:

Use raw double when:

Precision Notes

See also
imath::TVector, imath::CDoubleManip, imath::CFixedPointManip

Definition at line 95 of file CDouble.h.

Member Typedef Documentation

◆ BaseClass

Definition at line 98 of file CDouble.h.

Constructor & Destructor Documentation

◆ CDouble() [1/2]

imath::CDouble::CDouble ( double  value = 0.0)
inline

Definition at line 173 of file CDouble.h.

References imath::TVector< 1 >::SetElement().

◆ CDouble() [2/2]

imath::CDouble::CDouble ( const BaseClass value)
inline

Definition at line 179 of file CDouble.h.

Member Function Documentation

◆ GetRounded() [1/2]

double imath::CDouble::GetRounded ( double  value,
int  precision = 2 
)
inlinestatic

Definition at line 335 of file CDouble.h.

◆ GetRounded() [2/2]

CDouble imath::CDouble::GetRounded ( int  precision = 2) const
inline

Get rounded value.

Definition at line 191 of file CDouble.h.

References imath::TVector< 1 >::GetElement(), and GetRounded().

Referenced by GetRounded().

◆ GetRoundedDown() [1/2]

double imath::CDouble::GetRoundedDown ( double  value,
int  precision = 2 
)
inlinestatic

Definition at line 351 of file CDouble.h.

◆ GetRoundedDown() [2/2]

CDouble imath::CDouble::GetRoundedDown ( int  precision = 2) const
inline

Get rounded down value with specified precision.

Definition at line 203 of file CDouble.h.

References GetRoundedDown().

Referenced by GetRoundedDown().

◆ GetRoundedUp() [1/2]

double imath::CDouble::GetRoundedUp ( double  value,
int  precision = 2 
)
inlinestatic

Definition at line 367 of file CDouble.h.

◆ GetRoundedUp() [2/2]

CDouble imath::CDouble::GetRoundedUp ( int  precision = 2) const
inline

Get rounded down value with specified precision.

Definition at line 215 of file CDouble.h.

References GetRoundedUp().

Referenced by GetRoundedUp().

◆ IsRoundedDownEqual() [1/2]

bool imath::CDouble::IsRoundedDownEqual ( const CDouble value,
int  precision = 2 
) const
inline

Check if two values are equal after rounding down.

Definition at line 209 of file CDouble.h.

References IsRoundedDownEqual().

Referenced by IsRoundedDownEqual().

◆ IsRoundedDownEqual() [2/2]

bool imath::CDouble::IsRoundedDownEqual ( double  value1,
double  value2,
int  precision = 2 
)
inlinestatic

Definition at line 359 of file CDouble.h.

◆ IsRoundedEqual() [1/2]

bool imath::CDouble::IsRoundedEqual ( const CDouble value,
int  precision = 2 
) const
inline

Check if two values are equal after rounding.

Definition at line 197 of file CDouble.h.

References IsRoundedEqual().

Referenced by IsRoundedEqual().

◆ IsRoundedEqual() [2/2]

bool imath::CDouble::IsRoundedEqual ( double  value1,
double  value2,
int  precision = 2 
)
inlinestatic

Definition at line 343 of file CDouble.h.

◆ IsRoundedUpEqual() [1/2]

bool imath::CDouble::IsRoundedUpEqual ( const CDouble value,
int  precision = 2 
) const
inline

Check if two values are equal after rounding down.

Definition at line 221 of file CDouble.h.

References IsRoundedUpEqual().

Referenced by IsRoundedUpEqual().

◆ IsRoundedUpEqual() [2/2]

bool imath::CDouble::IsRoundedUpEqual ( double  value1,
double  value2,
int  precision = 2 
)
inlinestatic

Definition at line 375 of file CDouble.h.

◆ IsSimiliar() [1/2]

bool imath::CDouble::IsSimiliar ( const CDouble value,
double  tolerance = I_BIG_EPSILON 
) const
inline

Check if two values are similiar with specified tolerance.

Definition at line 227 of file CDouble.h.

References IsSimiliar().

Referenced by IsSimiliar().

◆ IsSimiliar() [2/2]

bool imath::CDouble::IsSimiliar ( double  value1,
double  value2,
double  tolerance = I_BIG_EPSILON 
)
inlinestatic

Definition at line 383 of file CDouble.h.

◆ operator double()

imath::CDouble::operator double ( ) const
inline

Definition at line 185 of file CDouble.h.

◆ operator!=()

bool imath::CDouble::operator!= ( const CDouble value) const
inline

◆ operator*()

CDouble imath::CDouble::operator* ( const CDouble value) const
inline

◆ operator*=()

const CDouble & imath::CDouble::operator*= ( const CDouble value)
inline

◆ operator+()

CDouble imath::CDouble::operator+ ( const CDouble value) const
inline

◆ operator+=()

const CDouble & imath::CDouble::operator+= ( const CDouble value)
inline

◆ operator-()

CDouble imath::CDouble::operator- ( const CDouble value) const
inline

◆ operator-=()

const CDouble & imath::CDouble::operator-= ( const CDouble value)
inline

◆ operator/()

CDouble imath::CDouble::operator/ ( const CDouble value) const
inline

◆ operator/=()

const CDouble & imath::CDouble::operator/= ( const CDouble value)
inline

◆ operator<()

bool imath::CDouble::operator< ( const CDouble value) const
inline

◆ operator<=()

bool imath::CDouble::operator<= ( const CDouble value) const
inline

◆ operator=()

const CDouble & imath::CDouble::operator= ( const CDouble value)
inline

◆ operator==()

bool imath::CDouble::operator== ( const CDouble value) const
inline

◆ operator>()

bool imath::CDouble::operator> ( const CDouble value) const
inline

◆ operator>=()

bool imath::CDouble::operator>= ( const CDouble value) const
inline

The documentation for this class was generated from the following file: