Evo C++ Library v0.5.1
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
FloatT< T > Struct Template Reference

#include <evo/type.h>

Inheritance diagram for FloatT< T >:
Inheritance graph
[legend]

Detailed Description

template<class T>
struct evo::FloatT< T >

Nullable basic floating-point base type.

Template Parameters
TFloating-point type

Floating point types:

Examples – using Float type (and float type) here, other supported floating point types work the same:

Public Types

typedef void EvoNullableType
 Identify as nullable type. More...
 
typedef FloatT< T > This
 This non-POD type More...
 
typedef T Type
 Wrapped POD type. More...
 

Public Member Functions

 FloatT ()
 Constructor. More...
 
 FloatT (const FloatT< T > &val)
 Copy constructor. More...
 
 FloatT (T val)
 Constructor. More...
 
int compare (const Nullable< T > &val) const
 Comparison. More...
 
int compare (T val) const
 Comparison. More...
 
T & denull ()
 Clears null flag and returns value reference. More...
 
bool eq1 (const Nullable< T > &val)
 Get whether approximately equal to given value. More...
 
bool eq1 (T val)
 Get whether approximately equal to given value. More...
 
bool null () const
 Get whether null. More...
 
 operator SafeBoolType () const
 Safe (explicit) evaluation as bool type. More...
 
bool operator! () const
 Negation operator returns whether null or 0. More...
 
bool operator!= (const Nullable< T > &val) const
 Inequality operator. More...
 
bool operator!= (T val) const
 Inequality operator. More...
 
const T & operator* () const
 Dereference for explicit conversion to underlying type (const). More...
 
T & operator* ()
 Dereference for explicit conversion to underlying type. More...
 
bool operator< (const Nullable< T > &val) const
 Less than operator. More...
 
bool operator< (T val) const
 Less than operator. More...
 
bool operator<= (const Nullable< T > &val) const
 Less than or equal operator. More...
 
bool operator<= (T val) const
 Less than or equal operator. More...
 
FloatT< T > & operator= (const FloatT< T > &val)
 Assignment operator. More...
 
FloatT< T > & operator= (T val)
 Assignment operator. More...
 
FloatT< T > & operator= (ValNull)
 Assignment operator to set as null. More...
 
bool operator== (const Nullable< T > &val) const
 Equality operator. More...
 
bool operator== (T val) const
 Equality operator. More...
 
bool operator> (const Nullable< T > &val) const
 Greater than operator. More...
 
bool operator> (T val) const
 Greater than operator. More...
 
bool operator>= (const Nullable< T > &val) const
 Greater than or equal operator. More...
 
bool operator>= (T val) const
 Greater than or equal operator. More...
 
Nullable< T > & set ()
 Set as null. More...
 
Nullable< T > & set (const Nullable< T > &src)
 Set as copy of given value. More...
 
Nullable< T > & set (T src)
 Set as given value. More...
 
bool valid () const
 Get whether valid (not null). More...
 
const T & value () const
 Get underlying value (const). More...
 
T & value ()
 Get underlying value. More...
 
value (T defval) const
 Get underlying value or given default if null. More...
 

Static Public Member Functions

static T eps ()
 Get machine epsilon. More...
 
static bool eq (T val1, T val2)
 Get whether values are approximately equal. More...
 
static bool eq (T val1, T val2, T eps)
 Get whether values are approximately equal using given epsilon value. More...
 
static T exp10 (T num, int exp)
 Multiply number by 10 raised to exponent. More...
 
static T fexp10 (int &exp, T num)
 Extract normalized base 10 mantissa and exponent from number. More...
 
static T inf ()
 Get infinity value. More...
 
static bool inf (T num)
 Check whether value is infinite. More...
 
static T max ()
 Get maximum normalized value. More...
 
static int maxdigits_prec (int exp, int precision)
 Get max formatting digits with given exponent and precision, including sign and any additional chars (used internally). More...
 
static int maxexp ()
 Get maximum allowed exponent. More...
 
static T min ()
 Get minimum normalized value. More...
 
static int minexp ()
 Get minimum allowed exponent. More...
 
static bool nan (T num)
 Get whether value is Not-A-Number (NaN). More...
 
static T nan ()
 Get Not-A-Number (NaN) value. More...
 
static T precision ()
 Get best precision value. More...
 

Static Public Attributes

static const int BYTES = sizeof(T)
 Type size in bytes. More...
 
static const bool IS = IsFloat<T>::value
 Whether type is really a floating point type. More...
 
static const int MAXDIGITS = std::numeric_limits<T>::digits10
 Maximum significant digits without precision loss. More...
 
static const int MAXDIGITS_AUTO = MAXDIGITS + 15
 Max formatting digits with auto precision (used internally) More...
 
static const bool NANOK = std::numeric_limits<T>::has_quiet_NaN
 Whether Not-A-Number (NaN) is supported. More...
 
static const bool SIGN = true
 Whether type is signed. More...
 

Member Typedef Documentation

◆ EvoNullableType

typedef void EvoNullableType
inherited

Identify as nullable type.

◆ This

typedef FloatT<T> This

This non-POD type

◆ Type

typedef T Type

Wrapped POD type.

Constructor & Destructor Documentation

◆ FloatT() [1/3]

FloatT ( )
inline

Constructor.

◆ FloatT() [2/3]

FloatT ( const FloatT< T > &  val)
inline

Copy constructor.

Parameters
valValue to copy

◆ FloatT() [3/3]

FloatT ( val)
inline

Constructor.

Parameters
valValue to set

Member Function Documentation

◆ compare() [1/2]

int compare ( const Nullable< T > &  val) const
inlineinherited

Comparison.

Parameters
valValue to compare to
Returns
Result (<0 if this is less, 0 if equal, >0 if this is greater)

◆ compare() [2/2]

int compare ( val) const
inlineinherited

Comparison.

  • If null, the result is always -1 as null compares as less than any non-null value
Parameters
valValue to compare to
Returns
Result (<0 if this is less, 0 if equal, >0 if this is greater)

◆ denull()

T& denull ( )
inlineinherited

Clears null flag and returns value reference.

  • Value is unchanged, POD types default to 0 when null
  • Useful for updating the underlying value by reference
  • Note: Nullable<bool> template specialization returns by value instead of reference
Returns
Whether valid

◆ eps()

static T eps ( )
inlinestatic

Get machine epsilon.

This is the difference between 1 and the least value greater than 1 that is representable.

Returns
Epsilon value

◆ eq() [1/2]

static bool eq ( val1,
val2 
)
inlinestatic

Get whether values are approximately equal.

  • This uses the system epsilon value for current type to determine whether the values are close enough to be considered equal
  • For better accuracy use eq(T,T,T) with a more relevant epsilon value
Parameters
val1First value to compare
val2Second value to compare
Returns
Whether approximately equal

◆ eq() [2/2]

static bool eq ( val1,
val2,
eps 
)
inlinestatic

Get whether values are approximately equal using given epsilon value.

Parameters
val1First value to compare
val2Second value to compare
epsEpsilon value to use for comparison – values are approximately equal if difference <= eps
Returns
Whether approximately equal

◆ eq1() [1/2]

bool eq1 ( const Nullable< T > &  val)
inline

Get whether approximately equal to given value.

  • This uses the system epsilon value for current type to determine whether the values are close enough to be considered equal
Parameters
valValue to compare to
Returns
Whether approximately equal

◆ eq1() [2/2]

bool eq1 ( val)
inline

Get whether approximately equal to given value.

  • This uses the system epsilon value for current type to determine whether the values are close enough to be considered equal
Parameters
valValue to compare to
Returns
Whether approximately equal

◆ exp10()

static T exp10 ( num,
int  exp 
)
inlinestatic

Multiply number by 10 raised to exponent.

Parameters
numNumber to multiply
expExponent to use
Returns
Result

◆ fexp10()

static T fexp10 ( int &  exp,
num 
)
inlinestatic

Extract normalized base 10 mantissa and exponent from number.

Parameters
expStores exponent value [out]
numNumber to use
Returns
Mantissa value

◆ inf() [1/2]

static T inf ( )
inlinestatic

Get infinity value.

Returns
Value

◆ inf() [2/2]

static bool inf ( num)
inlinestatic

Check whether value is infinite.

Returns
Value

◆ max()

static T max ( )
inlinestatic

Get maximum normalized value.

Returns
Value

◆ maxdigits_prec()

static int maxdigits_prec ( int  exp,
int  precision 
)
inlinestatic

Get max formatting digits with given exponent and precision, including sign and any additional chars (used internally).

Returns
Max formatting digits

◆ maxexp()

static int maxexp ( )
inlinestatic

Get maximum allowed exponent.

Returns
Value

◆ min()

static T min ( )
inlinestatic

Get minimum normalized value.

Returns
Value

◆ minexp()

static int minexp ( )
inlinestatic

Get minimum allowed exponent.

Returns
Value

◆ nan() [1/2]

static bool nan ( num)
inlinestatic

Get whether value is Not-A-Number (NaN).

Returns
Whether NaN, always false if NaN not supported

◆ nan() [2/2]

static T nan ( )
inlinestatic

Get Not-A-Number (NaN) value.

  • This value doesn't work for comparison. Use nan(T) instead
Returns
NaN value, 0.0 if not supported

◆ null()

bool null ( ) const
inlineinherited

Get whether null.

Returns
Whether null

◆ operator SafeBoolType()

operator SafeBoolType ( ) const
inlineinherited

Safe (explicit) evaluation as bool type.

  • This is called when object is directly evaluated as a bool, and is equivalent to: !operator!()
  • See SafeBool

◆ operator!()

bool operator! ( ) const
inlineinherited

Negation operator returns whether null or 0.

Returns
Whether null or 0

◆ operator!=() [1/2]

bool operator!= ( const Nullable< T > &  val) const
inlineinherited

Inequality operator.

Parameters
valValue to compare to
Returns
Whether inequal

◆ operator!=() [2/2]

bool operator!= ( val) const
inlineinherited

Inequality operator.

  • If null, the result is always true as null is not equal to any non-null value
Parameters
valValue to compare to
Returns
Whether inequal, true if null

◆ operator*() [1/2]

const T& operator* ( ) const
inlineinherited

Dereference for explicit conversion to underlying type (const).

Alternative to value().

Returns
Underlying type value

◆ operator*() [2/2]

T& operator* ( )
inlineinherited

Dereference for explicit conversion to underlying type.

Alternative to value().

Returns
Underlying type value

◆ operator<() [1/2]

bool operator< ( const Nullable< T > &  val) const
inlineinherited

Less than operator.

  • If null, null is less than any non-null value
Parameters
valValue to compare to
Returns
Whether less than val

◆ operator<() [2/2]

bool operator< ( val) const
inlineinherited

Less than operator.

  • If null, null is less than any non-null value
Parameters
valValue to compare to
Returns
Whether less than val

◆ operator<=() [1/2]

bool operator<= ( const Nullable< T > &  val) const
inlineinherited

Less than or equal operator.

  • If null, null is less than or equal to any value
Parameters
valValue to compare to
Returns
Whether less than or equal to val, true if null

◆ operator<=() [2/2]

bool operator<= ( val) const
inlineinherited

Less than or equal operator.

  • If null, null is less than or equal to any value
Parameters
valValue to compare to
Returns
Whether less than or equal to val, true if null

◆ operator=() [1/3]

FloatT<T>& operator= ( const FloatT< T > &  val)
inline

Assignment operator.

Parameters
valValue to copy
Returns
This

◆ operator=() [2/3]

FloatT<T>& operator= ( val)
inline

Assignment operator.

Parameters
valValue to set
Returns
This

◆ operator=() [3/3]

FloatT<T>& operator= ( ValNull  )
inline

Assignment operator to set as null.

Returns
This

◆ operator==() [1/2]

bool operator== ( const Nullable< T > &  val) const
inlineinherited

Equality operator.

Parameters
valValue to compare to
Returns
Whether equal

◆ operator==() [2/2]

bool operator== ( val) const
inlineinherited

Equality operator.

  • If null, the result is always false as null is not equal to any non-null value
Parameters
valValue to compare to
Returns
Whether equal, false if null

◆ operator>() [1/2]

bool operator> ( const Nullable< T > &  val) const
inlineinherited

Greater than operator.

  • If null, null is not greater than any non-null value
Parameters
valValue to compare to
Returns
Whether greater than val, false if null

◆ operator>() [2/2]

bool operator> ( val) const
inlineinherited

Greater than operator.

  • If null, null is not greater than any non-null value
Parameters
valValue to compare to
Returns
Whether greater than val, false if null

◆ operator>=() [1/2]

bool operator>= ( const Nullable< T > &  val) const
inlineinherited

Greater than or equal operator.

  • If null, null is not greater than any non-null value
Parameters
valValue to compare to
Returns
Whether greater than or equal to val

◆ operator>=() [2/2]

bool operator>= ( val) const
inlineinherited

Greater than or equal operator.

  • If null, null is not greater than any non-null value
Parameters
valValue to compare to
Returns
Whether greater than or equal to val

◆ precision()

static T precision ( )
inlinestatic

Get best precision value.

Returns
Value

◆ set() [1/3]

Nullable<T>& set ( )
inlineinherited

Set as null.

Returns
This

◆ set() [2/3]

Nullable<T>& set ( const Nullable< T > &  src)
inlineinherited

Set as copy of given value.

Parameters
srcSource to copy
Returns
This

◆ set() [3/3]

Nullable<T>& set ( src)
inlineinherited

Set as given value.

Parameters
srcSource to set
Returns
This

◆ valid()

bool valid ( ) const
inlineinherited

Get whether valid (not null).

Returns
Whether valid

◆ value() [1/3]

const T& value ( ) const
inlineinherited

Get underlying value (const).

Alternative to operator*().

Returns
Whether valid

◆ value() [2/3]

T& value ( )
inlineinherited

Get underlying value.

Alternative to operator*().

Returns
Whether valid

◆ value() [3/3]

T value ( defval) const
inline

Get underlying value or given default if null.

Parameters
defvalDefault value to use if null
Returns
Result value, or defval if null

Member Data Documentation

◆ BYTES

const int BYTES = sizeof(T)
static

Type size in bytes.

◆ IS

const bool IS = IsFloat<T>::value
static

Whether type is really a floating point type.

◆ MAXDIGITS

const int MAXDIGITS = std::numeric_limits<T>::digits10
static

Maximum significant digits without precision loss.

◆ MAXDIGITS_AUTO

const int MAXDIGITS_AUTO = MAXDIGITS + 15
static

Max formatting digits with auto precision (used internally)

◆ NANOK

const bool NANOK = std::numeric_limits<T>::has_quiet_NaN
static

Whether Not-A-Number (NaN) is supported.

◆ SIGN

const bool SIGN = true
static

Whether type is signed.


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