TSDuck v3.40-4120
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
tsIntegerUtils.h File Reference

Some utilities on integers. More...

Classes

struct  ts::int_max< INT >
 The meta-type ts::int_max selects the integer type with largest width and same signedness as another integer type. More...
 
struct  ts::make_signed< T >
 The meta-type ts::make_signed is a generalization of std::make_signed which works on floating point-types as well. More...
 
struct  ts::smaller_unsigned< BITS >
 Define the smaller unsigned integer type with at least a given number of bits. More...
 
struct  ts::static_power10< INT, POW >
 Static values of power of 10. More...
 
struct  ts::underlying_type< T >
 The meta-type ts::underlying_type is a generalization of std::underlying_type which works on integral or floating-point types as well. More...
 

Namespaces

namespace  ts
 TSDuck namespace, containing all TSDuck classes and functions.
 

Concepts

concept  ts::int_enum
 A C++20 concept which requires a type to be an integer or an enumeration type.
 

Typedefs

template<typename INT >
using ts::int_max_t = typename int_max< INT >::type
 Helper type for ts::int_max.
 
template<typename T >
using ts::make_signed_t = typename make_signed< T >::type
 Helper type for ts::make_signed.
 
template<typename T >
using ts::underlying_type_t = typename underlying_type< T >::type
 Helper type for ts::underlying_type.
 

Functions

template<typename INT >
requires std::integral<INT>
constexpr INT ts::abs (INT a)
 Absolute value of integer types, also working on unsigned types.
 
template<typename INT >
requires std::integral<INT>
bool ts::add_overflow (INT a, INT b) platform_specific
 Check if an integer addition generates an overflow.
 
template<typename INT >
requires std::integral<INT>
constexpr bool ts::add_overflow (INT a, INT b, INT res)
 Check if an integer addition generates an overflow.
 
template<typename INT >
requires std::integral<INT>
size_t ts::BitSize (INT x)
 Get the size in bits of an integer value.
 
template<typename INT1 , typename INT2 >
requires std::integral<INT1> && std::integral<INT2>
constexpr bool ts::bound_check (INT2 x)
 Integer cross-type bound check.
 
template<typename INT >
requires std::integral<INT>
INT ts::bounded_add (INT a, INT b)
 Perform a bounded addition without overflow.
 
template<typename INT1 , typename INT2 >
requires std::integral<INT1> && std::integral<INT2>
constexpr INT1 ts::bounded_cast (INT2 x)
 Bounded integer cast.
 
template<typename INT >
requires std::integral<INT>
INT ts::bounded_sub (INT a, INT b)
 Perform a bounded subtraction without overflow.
 
template<typename INT >
requires std::integral<INT>
void ts::debug_thow_neg_overflow (INT a)
 In debug mode, throw an exception if the negation (opposite sign) of an integer generates an overflow.
 
template<typename INT >
requires std::integral<INT>
void ts::debug_throw_add_overflow (INT a, INT b, INT res)
 In debug mode, throw an exception if an integer addition generates an overflow.
 
template<typename INT1 , typename INT2 >
requires std::integral<INT1> && std::integral<INT2>
void ts::debug_throw_bound_check (INT2 x)
 In debug mode, throw an exception if an integer value does not fall into the range of another integer type.
 
template<typename INT >
requires std::integral<INT>
void ts::debug_throw_div_zero (INT den)
 In debug mode, throw an exception if the denominator of an integer division is zero.
 
template<typename INT >
requires std::integral<INT>
void ts::debug_throw_mul_overflow (INT a, INT b, INT res)
 In debug mode, throw an exception if an integer multiplication generates an overflow.
 
template<typename INT >
requires std::integral<INT>
void ts::debug_throw_sub_overflow (INT a, INT b, INT res)
 In debug mode, throw an exception if an integer substraction generates an overflow.
 
template<typename INT >
requires std::integral<INT>
INT ts::GCD (INT x, INT y)
 Compute a greatest common denominator (GCD).
 
template<typename T >
requires int_enum<T>
constexpr bool ts::is_negative (T x)
 Statically check if a integral or enum value is negative.
 
template<typename INT >
requires std::integral<INT>
INT ts::LSBMask (size_t bits)
 Get the mask to select a given number of least significant bits in an integer value.
 
size_t ts::MaxDecimalWidth (size_t typeSize, size_t digitSeparatorSize=0)
 Compute the maximum width of the decimal representation of an integer type.
 
size_t ts::MaxHexaWidth (size_t typeSize, size_t digitSeparatorSize=0)
 Compute the maximum width of the hexadecimal representation of an integer type.
 
template<typename INT >
requires std::integral<INT>
bool ts::mul_overflow (INT a, INT b) platform_specific
 Check if an integer multiplication generates an overflow.
 
template<typename INT >
requires std::integral<INT>
constexpr bool ts::mul_overflow (INT a, INT b, INT res)
 Check if an integer multiplication generates an overflow.
 
template<typename INT >
requires std::integral<INT>
bool ts::neg_overflow (INT a)
 Check if the negation (opposite sign) of an integer generates an overflow.
 
uint64_t ts::Power10 (size_t pow)
 Get a power of 10 using a fast lookup table.
 
template<typename INT >
requires std::integral<INT>
INT ts::round_down (INT x, INT f)
 Round x down to previous multiple of a factor f.
 
template<typename INT >
requires std::integral<INT>
INT ts::round_up (INT x, INT f)
 Round x up to next multiple of a factor f.
 
template<typename INT >
requires std::integral<INT>
constexpr INT ts::rounded_div (INT a, INT b)
 Integer division with rounding to closest value (instead of truncating).
 
template<typename INT >
requires std::integral<INT>
constexpr void ts::sign_reduce (INT &num, INT &den)
 Reduce the sign of an integer fraction.
 
template<typename INT >
requires std::integral<INT>
constexpr const UCharts::SignedDescription ()
 Get the signed/unsigned qualifier of an integer type as a string.
 
template<typename INT >
requires std::signed_integral<INT>
INT ts::SignExtend (INT x, size_t bits)
 Perform a sign extension on any subset of a signed integer.
 
template<typename INT >
requires std::integral<INT>
bool ts::sub_overflow (INT a, INT b) platform_specific
 Check if an integer substraction generates an overflow.
 
template<typename INT >
requires std::integral<INT>
bool ts::sub_overflow (INT a, INT b, INT res)
 Check if an integer substraction generates an overflow.
 
template<typename INT >
requires std::integral<INT>
void ts::thow_neg_overflow (INT a)
 Throw an exception if the negation (opposite sign) of an integer generates an overflow.
 
template<typename INT >
requires std::integral<INT>
void ts::throw_add_overflow (INT a, INT b, INT res)
 Throw an exception if an integer addition generates an overflow.
 
template<typename INT1 , typename INT2 >
requires std::integral<INT1> && std::integral<INT2>
void ts::throw_bound_check (INT2 x)
 Throw an exception if an integer value does not fall into the range of another integer type.
 
template<typename INT >
requires std::integral<INT>
void ts::throw_div_zero (INT den)
 Throw an exception if the denominator of an integer division is zero.
 
template<typename INT >
requires std::integral<INT>
void ts::throw_mul_overflow (INT a, INT b, INT res)
 Throw an exception if an integer multiplication generates an overflow.
 
template<typename INT >
requires std::integral<INT>
void ts::throw_sub_overflow (INT a, INT b, INT res)
 Throw an exception if an integer substraction generates an overflow.
 

Variables

constexpr size_t ts::MAX_POWER_10 = 19
 Largest representable power of 10 in integer types.
 

Detailed Description

Some utilities on integers.