Elm  1.0
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Integer Operations

Typedefs

typedef int8_t elm::t::int8
 
typedef uint8_t elm::t::uint8
 
typedef int16_t elm::t::int16
 
typedef uint16_t elm::t::uint16
 
typedef int32_t elm::t::int32
 
typedef uint32_t elm::t::uint32
 
typedef int64_t elm::t::int64
 
typedef uint64_t elm::t::uint64
 
typedef uint32 elm::t::size
 
typedef uint32 elm::t::offset
 
typedef uint32 elm::t::uint
 
typedef uint32 elm::t::intptr
 

Functions

int elm::msb (t::uint32 i)
 
int elm::msb (t::uint64 i)
 
int elm::ones (t::uint8 i)
 
t::uint32 elm::leastUpperPowerOf2 (t::uint32 v)
 
t::uint64 elm::leastUpperPowerOf2 (t::uint64 v)
 
t::uint32 elm::mult (t::uint32 a, t::uint32, bool &over)
 
t::uint64 elm::mult (t::uint64 a, t::uint64, bool &over)
 
t::uint32 elm::roundup (t::uint32 v, t::uint32 m)
 
t::uint32 elm::rounddown (t::uint32 v, t::uint32 m)
 
int elm::ones (t::uint16 i)
 
int elm::ones (t::uint64 i)
 

Detailed Description

This module provides several facilities to work with integers. To use, one has to include <elm/int.h>.

This module provides reliable and OS-independent types to represent integers together with a list of efficiently-implemented functions to process them. These types are stored in the elm::t sub-namespace and, if you are using the elm namespace, are quickly accessed by syntax t::type .

#include <elm/int.h>
using namespace elm;
...
t::uint32 my_variable;

Typedef Documentation

Signed 16-bit integer type.

Signed 32-bit integer type.

Signed 64-bit integer type.

Signed 8-bit integer type.

Integer sufficiently big to store a pointer (according to the system configuration).

Integer type to represent memory offset (according to the system configuration).

Integer type to represent memory size (according to the system configuration).

Default size unsigned integer type.

Unsigned 16-bit integer type.

Unsigned 32-bit integer type.

Unsigned 64-bit integer type.

Unsigned 8-bit integer type.

Function Documentation

t::uint32 elm::leastUpperPowerOf2 ( t::uint32  v)

Get the least upper power of 2 for the given value. If the value is a power of two, return it else compute the least greater power.

Parameters
vValue to process.
Returns
Least upper power of two.

References elm::msb().

Referenced by elm::stree::Builder< K, T, C >::allocate().

t::uint64 elm::leastUpperPowerOf2 ( t::uint64  v)

Get the least upper power of 2 for the given value. If the value is a power of two, return it else compute the least greater power.

Parameters
vValue to process.
Returns
Least upper power of two.

References elm::msb().

int elm::msb ( t::uint32  i)

Compute the position of the left-most bit to one.

Parameters
iInteger to test.
Returns
Position of left-most bit to one or -1 if the integer is 0.

Referenced by elm::leastUpperPowerOf2(), and elm::msb().

int elm::msb ( t::uint64  i)

Compute the position of the left-most bit to one.

Parameters
iInteger to test.
Returns
Position of left-most bit to one or -1 if the integer is 0.

References elm::msb().

t::uint32 elm::mult ( t::uint32  a,
t::uint32  b,
bool &  over 
)

Perform multiplication on unsigned integer 32-bits.

Parameters
aFirst number to multiply.
bSecond number to multiply.
overSet to true if overflow occurs.
Returns
Result of multiplication (only valide if over is false).
t::uint64 elm::mult ( t::uint64  a,
t::uint64  b,
bool &  over 
)

Perform multiplication on unsigned integer 64-bits.

Parameters
aFirst number to multiply.
bSecond number to multiply.
overSet to true if overflow occurs.
Returns
Result of multiplication (only valide if over is false).
int elm::ones ( t::uint8  i)

Count the number of ones in the given byte.

Parameters
iByte to count ones in.
Returns
Number of ones in the byte.

Referenced by elm::WAHVector::countOnes(), elm::BitVector::countOnes(), and elm::ones().

int elm::ones ( t::uint16  i)

Count the number of ones in the given half-word.

Parameters
iHalf-word to count ones in.
Returns
Number of ones in the half-word.

References elm::ones().

int elm::ones ( t::uint64  i)

Count the number of ones in the given double-word.

Parameters
iDouble-word to count ones in.
Returns
Number of ones in the double-word.

References elm::ones().

t::uint32 elm::rounddown ( t::uint32  v,
t::uint32  m 
)

Round upto upper multiple integer

Parameters
vValue to round.
mMultiple to round with.
Returns
Value round upto the upper multiple integer.
t::uint32 elm::roundup ( t::uint32  v,
t::uint32  m 
)

Round upto upper multiple integer

Parameters
vValue to round.
mMultiple to round with.
Returns
Value round upto the upper multiple integer.