OpenCores
URL https://opencores.org/ocsvn/c0or1k/c0or1k/trunk

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [include/] [l4/] [lib/] [math.h] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
#ifndef __LIB_MATH_H__
2
#define __LIB_MATH_H__
3
 
4
/* Take the power */
5
static inline int pow(int val, int exp)
6
{
7
        int res = 1;
8
 
9
        for (int i = 0; i < exp; i++)
10
                res *= val;
11
        return res;
12
}
13
 
14
static inline int min(int x, int y)
15
{
16
        return x < y ? x : y;
17
}
18
 
19
static inline int max(int x, int y)
20
{
21
        return x > y ? x : y;
22
}
23
 
24
/* Tests if ranges a-b intersect with range c-d */
25
static inline int set_intersection(unsigned long a, unsigned long b,
26
                                   unsigned long c, unsigned long d)
27
{
28
        /*
29
         * Below is the complement set (') of the intersection
30
         * of 2 ranges, much simpler ;-)
31
         */
32
        if (b <= c || a >= d)
33
                return 0;
34
 
35
        /* The rest is always intersecting */
36
        return 1;
37
}
38
 
39
#endif /* __LIB_MATH_H__ */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.