Alchemy  1.0
A framework to robustly process network messages and structured data
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
List of all members
tmp::math::pow< T, var, exp > Struct Template Reference

Static calculation of power function. More...

#include <meta_math.h>

Detailed Description

template<typename T, T var, unsigned char exp>
struct tmp::math::pow< T, var, exp >

Static calculation of power function.

This is a collection of functions that provides that ability to calculate the value of a number raised to an exponent. The calculation is performed at compile-time, and the result can be used in further static calculations and as template parameters.

T[typename] The type to use as the result value.
var[T] A value of type T to act as the base of the value.
exp[unsigned char] The value of the exponent. The max exponent can be number
T must be an integral type otherwise the static const initialization becomes illegal.
Supplying a exponent that is <= to the number of bits in T will truncate the result.


// Calculate 10^3:
// Use the pow<> type to create a bit-mask constant:
// Use the pow<> type to create a bit-mask constant.
// The BitField Mask can be described with this formula:
// Mask = (2 ^ (number of bits))-1
// << shifted to the left by offset bits.
static const
size_t k_size = 3; ///< 3-bits in the mask
static const
size_t k_offset = 5; ///< Offset the mask 5-bits
static const
T k_mask = T(((tmp::math::pow<T, 2, k_size>::value)-1) << k_offset);
// k_mask is now equal to: 0xE0
// binary equivalent: 11100000

Definition at line 62 of file meta_math.h.

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