2 * Copyright (c) 2004, 2005 Voltaire, Inc. All rights reserved.
3 * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
4 * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenIB.org BSD license below:
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials
23 * provided with the distribution.
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38 * Defines standard math related macros and functions.
44 #include <complib/cl_types.h>
47 # define BEGIN_C_DECLS extern "C" {
48 # define END_C_DECLS }
49 #else /* !__cplusplus */
50 # define BEGIN_C_DECLS
52 #endif /* __cplusplus */
55 /****d* Component Library: Math/MAX
60 * The MAX macro returns the greater of two values.
67 * [in] First of two values to compare.
70 * [in] Second of two values to compare.
73 * Returns the greater of the x and y parameters.
79 #define MAX(x,y) ((x) > (y) ? (x) : (y))
81 /****d* Component Library: Math/MIN
86 * The MIN macro returns the greater of two values.
93 * [in] First of two values to compare.
96 * [in] Second of two values to compare.
99 * Returns the lesser of the x and y parameters.
105 #define MIN(x,y) ((x) < (y) ? (x) : (y))
107 /****d* Component Library: Math/ROUNDUP
112 * The ROUNDUP macro rounds a value up to a given multiple.
115 * ROUNDUP( val, align );
119 * [in] Value that is to be rounded up. The type of the value is
120 * indeterminate, but must be at most the size of a natural integer
124 * [in] Multiple to which the val parameter must be rounded up.
127 * Returns a value that is the input value specified by val rounded up to
128 * the nearest multiple of align.
131 * The value provided must be of a type at most the size of a natural integer.
134 #define ROUNDUP(val, align) \
135 ((((val) / (align))*(align)) + (((val) % (align)) ? (align) : 0))
138 #endif /* _CL_MATH_H_ */