Bond 0.9
C++ Bond Runtime Library API Documentation
Loading...
Searching...
No Matches
Math

Useful math functions. More...

Functions

template<typename T>
T Bond::AlignDown (T value, T align)
 Rounds an integer down to the nearest multiple of a specified power of two.
template<typename T>
T Bond::AlignUp (T value, T align)
 Rounds an integer up to the nearest multiple of a specified power of two.
template<typename T>
T Bond::AlignUpDelta (T value, T align)
 Returns the difference between an integer and the nearest larger multiple of a specified power of two.
template<typename T>
T * Bond::AlignPointerDown (T *ptr, size_t align)
 Rounds a pointer down to the nearest multiple of a specified power of two.
template<typename T>
T * Bond::AlignPointerUp (T *ptr, size_t align)
 Rounds a pointer up to the nearest multiple of a specified power of two.
template<typename T>
bool Bond::IsPowerOfTwo (T value)
 Returns whether an integer is a power of two. 0 is not a power of two.
template<typename T>
T Bond::RoundUpToPowerOfTwo32 (T value)
 Rounds a 32 bit integer up to the nearest power of two. Values that are already powers of two are returned unchanged and 0 is returned as 0. The result is only correct for values no greater than 2^31.
template<typename T>
T Bond::Abs (T value)
 Returns the absolute value of a number.
template<typename RangeType, typename ValueType>
bool Bond::IsInRange (ValueType value)
 Returns whether value is exactly representable by RangeType, i.e. whether converting it to RangeType and back is lossless. NaN and infinity are never representable.

Detailed Description

Useful math functions.

#include "bond/systems/math.h"

Function Documentation

◆ Abs()

template<typename T>
T Bond::Abs ( T value)
inline

Returns the absolute value of a number.

Parameters
valueThe number whose absolute value is evaluated.

◆ AlignDown()

template<typename T>
T Bond::AlignDown ( T value,
T align )
inline

Rounds an integer down to the nearest multiple of a specified power of two.

Parameters
valueThe value to be rounded.
alignThe power of two around which the value is rounded.

◆ AlignPointerDown()

template<typename T>
T * Bond::AlignPointerDown ( T * ptr,
size_t align )
inline

Rounds a pointer down to the nearest multiple of a specified power of two.

Parameters
ptrThe pointer to be rounded.
alignThe power of two around which the pointer is rounded.

◆ AlignPointerUp()

template<typename T>
T * Bond::AlignPointerUp ( T * ptr,
size_t align )
inline

Rounds a pointer up to the nearest multiple of a specified power of two.

Parameters
ptrThe pointer to be rounded.
alignThe power of two around which the pointer is rounded.

◆ AlignUp()

template<typename T>
T Bond::AlignUp ( T value,
T align )
inline

Rounds an integer up to the nearest multiple of a specified power of two.

Parameters
valueThe value to be rounded.
alignThe power of two around which the value is rounded.

◆ AlignUpDelta()

template<typename T>
T Bond::AlignUpDelta ( T value,
T align )
inline

Returns the difference between an integer and the nearest larger multiple of a specified power of two.

Parameters
valueThe value to be rounded.
alignThe power of two around which the value is rounded.

◆ IsInRange()

template<typename RangeType, typename ValueType>
bool Bond::IsInRange ( ValueType value)

Returns whether value is exactly representable by RangeType, i.e. whether converting it to RangeType and back is lossless. NaN and infinity are never representable.

◆ IsPowerOfTwo()

template<typename T>
bool Bond::IsPowerOfTwo ( T value)
inline

Returns whether an integer is a power of two. 0 is not a power of two.

Parameters
valueThe value to test.

◆ RoundUpToPowerOfTwo32()

template<typename T>
T Bond::RoundUpToPowerOfTwo32 ( T value)
inline

Rounds a 32 bit integer up to the nearest power of two. Values that are already powers of two are returned unchanged and 0 is returned as 0. The result is only correct for values no greater than 2^31.

Parameters
valueThe value to be rounded.