The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Macros | Functions
math.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define fr_add(_out, _a, _b)   !__builtin_add_overflow(_a, _b, _out)
 Adds two integers. More...
 
#define fr_multiply(_out, _a, _b)   !__builtin_mul_overflow(_a, _b, _out)
 Multiplies two integers together. More...
 
#define fr_sub(_out, _a, _b)   !__builtin_sub_overflow(_a, _b, _out)
 Subtracts two integers. More...
 
#define ROUND_UP(_num, _mul)   (((((_num) + ((_mul) - 1))) / (_mul)) * (_mul))
 Round up - Works in all cases, but is slower. More...
 
#define ROUND_UP_DIV(_x, _y)   (1 + (((_x) - 1) / (_y)))
 Get the ceiling value of integer division. More...
 
#define ROUND_UP_POW2(_num, _mul)   (((_num) + ((_mul) - 1)) & ~((_mul) - 1))
 Round up - Only works if _mul is a power of 2 but avoids division. More...
 

Functions

static uint8_t fr_high_bit_pos (uint64_t num)
 Find the highest order high bit in an unsigned 64 bit integer. More...
 
static uint8_t fr_log10 (uint64_t num)
 Efficient calculation of log10 of a unsigned 64bit integer. More...
 
static uint8_t fr_low_bit_pos (uint64_t num)
 Find the lowest order high bit in an unsigned 64 bit integer. More...
 

Macro Definition Documentation

◆ fr_add

#define fr_add (   _out,
  _a,
  _b 
)    !__builtin_add_overflow(_a, _b, _out)

Adds two integers.

Parameters
[in]_outWhere to store the result.
[in]_afirst argument to add.
[in]_bsecond argument to add.
Returns
  • false on overflow.
  • true if there was no overflow.

Definition at line 129 of file math.h.

◆ fr_multiply

#define fr_multiply (   _out,
  _a,
  _b 
)    !__builtin_mul_overflow(_a, _b, _out)

Multiplies two integers together.

Parameters
[in]_outWhere to store the result.
[in]_afirst argument to multiply.
[in]_bsecond argument to multiply.
Returns
  • false on overflow.
  • true if there was no overflow.

Definition at line 118 of file math.h.

◆ fr_sub

#define fr_sub (   _out,
  _a,
  _b 
)    !__builtin_sub_overflow(_a, _b, _out)

Subtracts two integers.

Parameters
[in]_outWhere to store the result.
[in]_afirst argument to subtract.
[in]_bsecond argument to subtract.
Returns
  • false on overflow.
  • true if there was no overflow.

Definition at line 140 of file math.h.

◆ ROUND_UP

#define ROUND_UP (   _num,
  _mul 
)    (((((_num) + ((_mul) - 1))) / (_mul)) * (_mul))

Round up - Works in all cases, but is slower.

Definition at line 148 of file math.h.

◆ ROUND_UP_DIV

#define ROUND_UP_DIV (   _x,
  _y 
)    (1 + (((_x) - 1) / (_y)))

Get the ceiling value of integer division.

Definition at line 153 of file math.h.

◆ ROUND_UP_POW2

#define ROUND_UP_POW2 (   _num,
  _mul 
)    (((_num) + ((_mul) - 1)) & ~((_mul) - 1))

Round up - Only works if _mul is a power of 2 but avoids division.

Definition at line 144 of file math.h.

Function Documentation

◆ fr_high_bit_pos()

static uint8_t fr_high_bit_pos ( uint64_t  num)
inlinestatic

Find the highest order high bit in an unsigned 64 bit integer.

Returns
0-64 indicating the position of the highest bit, with 0 indicating no high bits, 1 indicating the 1st bit and 64 indicating the last bit.

Definition at line 36 of file math.h.

+ Here is the caller graph for this function:

◆ fr_log10()

static uint8_t fr_log10 ( uint64_t  num)
inlinestatic

Efficient calculation of log10 of a unsigned 64bit integer.

Parameters
[in]numto calculate log10 of.
Returns
log10 of the integer

Definition at line 78 of file math.h.

+ Here is the call graph for this function:

◆ fr_low_bit_pos()

static uint8_t fr_low_bit_pos ( uint64_t  num)
inlinestatic

Find the lowest order high bit in an unsigned 64 bit integer.

Returns
0-64 indicating the position of the lowest bit, with 0 indicating no high bits, 1 indicating the 1st bit and 64 indicating the last bit.

Definition at line 55 of file math.h.

+ Here is the caller graph for this function: