1321936Shselasky/*
2321936Shselasky * Copyright (c) 2004, 2005 Voltaire, Inc. All rights reserved.
3321936Shselasky * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
4321936Shselasky * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
5321936Shselasky *
6321936Shselasky * This software is available to you under a choice of one of two
7321936Shselasky * licenses.  You may choose to be licensed under the terms of the GNU
8321936Shselasky * General Public License (GPL) Version 2, available from the file
9321936Shselasky * COPYING in the main directory of this source tree, or the
10321936Shselasky * OpenIB.org BSD license below:
11321936Shselasky *
12321936Shselasky *     Redistribution and use in source and binary forms, with or
13321936Shselasky *     without modification, are permitted provided that the following
14321936Shselasky *     conditions are met:
15321936Shselasky *
16321936Shselasky *      - Redistributions of source code must retain the above
17321936Shselasky *        copyright notice, this list of conditions and the following
18321936Shselasky *        disclaimer.
19321936Shselasky *
20321936Shselasky *      - Redistributions in binary form must reproduce the above
21321936Shselasky *        copyright notice, this list of conditions and the following
22321936Shselasky *        disclaimer in the documentation and/or other materials
23321936Shselasky *        provided with the distribution.
24321936Shselasky *
25321936Shselasky * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26321936Shselasky * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27321936Shselasky * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28321936Shselasky * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29321936Shselasky * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30321936Shselasky * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31321936Shselasky * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32321936Shselasky * SOFTWARE.
33321936Shselasky *
34321936Shselasky */
35321936Shselasky
36321936Shselasky/*
37321936Shselasky * Abstract:
38321936Shselasky *	Defines standard math related macros and functions.
39321936Shselasky */
40321936Shselasky
41321936Shselasky#ifndef _CL_MATH_H_
42321936Shselasky#define _CL_MATH_H_
43321936Shselasky
44321936Shselasky#include <complib/cl_types.h>
45321936Shselasky
46321936Shselasky#ifdef __cplusplus
47321936Shselasky#  define BEGIN_C_DECLS extern "C" {
48321936Shselasky#  define END_C_DECLS   }
49321936Shselasky#else				/* !__cplusplus */
50321936Shselasky#  define BEGIN_C_DECLS
51321936Shselasky#  define END_C_DECLS
52321936Shselasky#endif				/* __cplusplus */
53321936Shselasky
54321936ShselaskyBEGIN_C_DECLS
55321936Shselasky/****d* Component Library: Math/MAX
56321936Shselasky* NAME
57321936Shselasky*	MAX
58321936Shselasky*
59321936Shselasky* DESCRIPTION
60321936Shselasky*	The MAX macro returns the greater of two values.
61321936Shselasky*
62321936Shselasky* SYNOPSIS
63321936Shselasky*	MAX( x, y );
64321936Shselasky*
65321936Shselasky* PARAMETERS
66321936Shselasky*	x
67321936Shselasky*		[in] First of two values to compare.
68321936Shselasky*
69321936Shselasky*	y
70321936Shselasky*		[in] Second of two values to compare.
71321936Shselasky*
72321936Shselasky* RETURN VALUE
73321936Shselasky*	Returns the greater of the x and y parameters.
74321936Shselasky*
75321936Shselasky* SEE ALSO
76321936Shselasky*	MIN, ROUNDUP
77321936Shselasky*********/
78321936Shselasky#ifndef MAX
79321936Shselasky#define MAX(x,y)	((x) > (y) ? (x) : (y))
80321936Shselasky#endif
81321936Shselasky/****d* Component Library: Math/MIN
82321936Shselasky* NAME
83321936Shselasky*	MIN
84321936Shselasky*
85321936Shselasky* DESCRIPTION
86321936Shselasky*	The MIN macro returns the greater of two values.
87321936Shselasky*
88321936Shselasky* SYNOPSIS
89321936Shselasky*	MIN( x, y );
90321936Shselasky*
91321936Shselasky* PARAMETERS
92321936Shselasky*	x
93321936Shselasky*		[in] First of two values to compare.
94321936Shselasky*
95321936Shselasky*	y
96321936Shselasky*		[in] Second of two values to compare.
97321936Shselasky*
98321936Shselasky* RETURN VALUE
99321936Shselasky*	Returns the lesser of the x and y parameters.
100321936Shselasky*
101321936Shselasky* SEE ALSO
102321936Shselasky*	MAX, ROUNDUP
103321936Shselasky*********/
104321936Shselasky#ifndef MIN
105321936Shselasky#define MIN(x,y)	((x) < (y) ? (x) : (y))
106321936Shselasky#endif
107321936Shselasky/****d* Component Library: Math/ROUNDUP
108321936Shselasky* NAME
109321936Shselasky*	ROUNDUP
110321936Shselasky*
111321936Shselasky* DESCRIPTION
112321936Shselasky*	The ROUNDUP macro rounds a value up to a given multiple.
113321936Shselasky*
114321936Shselasky* SYNOPSIS
115321936Shselasky*	ROUNDUP( val, align );
116321936Shselasky*
117321936Shselasky* PARAMETERS
118321936Shselasky*	val
119321936Shselasky*		[in] Value that is to be rounded up. The type of the value is
120321936Shselasky*		indeterminate, but must be at most the size of a natural integer
121321936Shselasky*		for the platform.
122321936Shselasky*
123321936Shselasky*	align
124321936Shselasky*		[in] Multiple to which the val parameter must be rounded up.
125321936Shselasky*
126321936Shselasky* RETURN VALUE
127321936Shselasky*	Returns a value that is the input value specified by val rounded up to
128321936Shselasky*	the nearest multiple of align.
129321936Shselasky*
130321936Shselasky* NOTES
131321936Shselasky*	The value provided must be of a type at most the size of a natural integer.
132321936Shselasky*********/
133321936Shselasky#ifndef ROUNDUP
134321936Shselasky#define ROUNDUP(val, align)	\
135321936Shselasky	((((val) / (align))*(align)) + (((val) % (align)) ? (align) : 0))
136321936Shselasky#endif
137321936ShselaskyEND_C_DECLS
138321936Shselasky#endif				/* _CL_MATH_H_ */
139