UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
math.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

long long gcd (long long a, long long b)
 
bool is_power_of_two (unsigned long long x)
 
long long lcm (long long a, long long b)
 
unsigned long long next_power_of_two (unsigned long long x)
 

Detailed Description

Author
Martin Pulec marti.nosp@m.n.pu.nosp@m.lec@c.nosp@m.esne.nosp@m.t.cz

Definition in file math.h.

Function Documentation

◆ gcd()

long long gcd ( long long a,
long long b )

Definition at line 42 of file math.c.

43{
44 // Everything divides 0
45 if (a == 0) {
46 return b;
47 }
48 if (b == 0) {
49 return a;
50 }
51
52 // base case
53 if (a == b) {
54 return a;
55 }
56
57 // a is greater
58 if (a > b) {
59 return gcd(a-b, b);
60 }
61 return gcd(a, b-a);
62}
long long gcd(long long a, long long b)
Definition math.c:42

References gcd().

Referenced by gcd(), and lcm().

Here is the call graph for this function:

◆ is_power_of_two()

bool is_power_of_two ( unsigned long long x)

Definition at line 69 of file math.c.

70{
71 return x != 0 && (x & (x - 1)) == 0;
72}

Referenced by device_state::init().

◆ lcm()

long long lcm ( long long a,
long long b )

Definition at line 64 of file math.c.

64 {
65 return a * b / gcd(a, b);
66}

References gcd().

Referenced by get_audio().

Here is the call graph for this function:

◆ next_power_of_two()

unsigned long long next_power_of_two ( unsigned long long x)
Returns
nearest power of two greater or equal than given number x
Return values
0on overflow (next power of two is ULLONG_MAX + 1)

Definition at line 79 of file math.c.

80{
81 if (x <= 1) {
82 return 1;
83 }
84 const int pos = __builtin_clzll(x - 1);
85 return pos > 0 ? 1ULL << (sizeof(unsigned long long) * CHAR_BIT - pos)
86 : 0;
87}

Referenced by display_decklink_get_property().