XenevaOS
Loading...
Searching...
No Matches
Macros | Functions
math.h File Reference
#include <linux/types.h>
#include <asm/div64.h>
#include <uapi/linux/kernel.h>
Include dependency graph for math.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define __round_mask(x, y)   ((__typeof__(x))((y)-1))
 
#define round_up(x, y)   ((((x)-1) | __round_mask(x, y))+1)
 
#define round_down(x, y)   ((x) & ~__round_mask(x, y))
 
#define DIV_ROUND_UP_POW2(n, d)    ((n) / (d) + !!((n) & ((d) - 1)))
 
#define DIV_ROUND_UP   __KERNEL_DIV_ROUND_UP
 
#define DIV_ROUND_DOWN_ULL(ll, d)    ({ unsigned long long _tmp = (ll); do_div(_tmp, d); _tmp; })
 
#define DIV_ROUND_UP_ULL(ll, d)    DIV_ROUND_DOWN_ULL((unsigned long long)(ll) + (d) - 1, (d))
 
#define DIV_ROUND_UP_SECTOR_T(ll, d)   DIV_ROUND_UP(ll,d)
 
#define roundup(x, y)
 
#define rounddown(x, y)
 
#define DIV_ROUND_CLOSEST   __KERNEL_DIV_ROUND_CLOSEST
 
#define DIV_ROUND_CLOSEST_ULL(x, divisor)
 
#define __STRUCT_FRACT(type)
 
#define mult_frac(x, n, d)
 
#define sector_div(a, b)   do_div(a, b)
 
#define abs(x)
 
#define __abs_choose_expr(x, type, other)
 
#define abs_diff(a, b)
 

Functions

u64 int_pow (u64 base, unsigned int exp)
 
unsigned long int_sqrt (unsigned long)
 
u32 int_sqrt64 (u64 x)
 

Macro Definition Documentation

◆ __abs_choose_expr

#define __abs_choose_expr (   x,
  type,
  other 
)
Value:
__builtin_choose_expr( \
__builtin_types_compatible_p(typeof(x), signed type) || \
__builtin_types_compatible_p(typeof(x), unsigned type), \
({ signed type __x = (x); __x < 0 ? -__x : __x; }), other)
int x
Definition layout.c:118

◆ __round_mask

#define __round_mask (   x,
  y 
)    ((__typeof__(x))((y)-1))

◆ __STRUCT_FRACT

#define __STRUCT_FRACT (   type)
Value:
struct type##_fract { \
__##type numerator; \
__##type denominator; \
};

◆ abs

#define abs (   x)
Value:
__abs_choose_expr(x, long long, \
__abs_choose_expr(x, long, \
__abs_choose_expr(x, short, \
__abs_choose_expr(x, char, \
__builtin_choose_expr( \
__builtin_types_compatible_p(typeof(x), char), \
(char)({ signed char __x = (x); __x<0?-__x:__x; }), \
((void)0)))))))
#define __abs_choose_expr(x, type, other)
Definition math.h:156

abs - return absolute value of an argument @x: the value.

If it is unsigned type, @x is converted to signed type first. char is treated as if it was signed (regardless of whether it really is) but the macro's return type is preserved as char.

NOTE, for signed type if @x is the minimum, the returned result is undefined as there is not enough bits to represent it as a positive number.

Return: an absolute value of @x.

◆ abs_diff

#define abs_diff (   a,
  b 
)
Value:
({ \
typeof(a) __a = (a); \
typeof(b) __b = (b); \
(void)(&__a == &__b); \
__a > __b ? (__a - __b) : (__b - __a); \
})
size_t a
Definition main.cpp:156
size_t b
Definition main.cpp:156

abs_diff - return absolute value of the difference between the arguments : the first argument : the second argument

and have to be of the same type. With this restriction we compare signed to signed and unsigned to unsigned. The result is the subtraction the smaller of the two from the bigger, hence result is always a positive value.

Return: an absolute value of the difference between the and .

◆ DIV_ROUND_CLOSEST

#define DIV_ROUND_CLOSEST   __KERNEL_DIV_ROUND_CLOSEST

◆ DIV_ROUND_CLOSEST_ULL

#define DIV_ROUND_CLOSEST_ULL (   x,
  divisor 
)
Value:
( \
{ \
typeof(divisor) __d = divisor; \
unsigned long long _tmp = (x) + (__d) / 2; \
do_div(_tmp, __d); \
_tmp; \
} \
)

◆ DIV_ROUND_DOWN_ULL

#define DIV_ROUND_DOWN_ULL (   ll,
  d 
)     ({ unsigned long long _tmp = (ll); do_div(_tmp, d); _tmp; })

◆ DIV_ROUND_UP

#define DIV_ROUND_UP   __KERNEL_DIV_ROUND_UP

◆ DIV_ROUND_UP_POW2

#define DIV_ROUND_UP_POW2 (   n,
  d 
)     ((n) / (d) + !!((n) & ((d) - 1)))

DIV_ROUND_UP_POW2 - divide and round up
: numerator @d: denominator (must be a power of 2)

Divides
by @d and rounds up to next multiple of @d (which must be a power of 2). Avoids integer overflows that may occur with __KERNEL_DIV_ROUND_UP(). Performance is roughly equivalent to __KERNEL_DIV_ROUND_UP().

◆ DIV_ROUND_UP_SECTOR_T

#define DIV_ROUND_UP_SECTOR_T (   ll,
  d 
)    DIV_ROUND_UP(ll,d)

◆ DIV_ROUND_UP_ULL

#define DIV_ROUND_UP_ULL (   ll,
  d 
)     DIV_ROUND_DOWN_ULL((unsigned long long)(ll) + (d) - 1, (d))

◆ mult_frac

#define mult_frac (   x,
  n,
  d 
)
Value:
({ \
typeof(x) x_ = (x); \
typeof(n) n_ = (n); \
typeof(d) d_ = (d); \
\
typeof(x_) q = x_ / d_; \
typeof(x_) r = x_ % d_; \
q * n_ + r * n_ / d_; \
})
int x_
Definition main.cpp:360
#define d
Definition libunicode.c:1833

◆ round_down

#define round_down (   x,
  y 
)    ((x) & ~__round_mask(x, y))

round_down - round down to next specified power of 2 @x: the value to round @y: multiple to round down to (must be a power of 2)

Rounds @x down to next multiple of @y (which must be a power of 2). To perform arbitrary rounding down, use rounddown() below.

◆ round_up

#define round_up (   x,
  y 
)    ((((x)-1) | __round_mask(x, y))+1)

round_up - round up to next specified power of 2 @x: the value to round @y: multiple to round up to (must be a power of 2)

Rounds @x up to next multiple of @y (which must be a power of 2). To perform arbitrary rounding up, use roundup() below.

◆ rounddown

#define rounddown (   x,
  y 
)
Value:
( \
{ \
typeof(x) __x = (x); \
__x - (__x % (y)); \
} \
)
int y
Definition layout.c:118

rounddown - round down to next specified multiple @x: the value to round @y: multiple to round down to

Rounds @x down to next multiple of @y. If @y will always be a power of 2, consider using the faster round_down().

◆ roundup

#define roundup (   x,
  y 
)
Value:
( \
{ \
typeof(y) __y = y; \
(((x) + (__y - 1)) / __y) * __y; \
} \
)

roundup - round up to the next specified multiple @x: the value to up @y: multiple to round up to

Rounds @x up to next multiple of @y. If @y will always be a power of 2, consider using the faster round_up().

◆ sector_div

#define sector_div (   a,
  b 
)    do_div(a, b)

Function Documentation

◆ int_pow()

u64 int_pow ( u64  base,
unsigned int  exp 
)

◆ int_sqrt()

unsigned long int_sqrt ( unsigned long  )

◆ int_sqrt64()

u32 int_sqrt64 ( u64  x)