1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<HTML>
3<HEAD>
4<META http-equiv="Content-Type" content="text/html; charset=windows-1252">
5<META name="GENERATOR" content="IBM WebSphere Studio Homepage Builder Version 8.0.0.0 for Windows">
6<META http-equiv="Content-Style-Type" content="text/css">
7<TITLE>MATH Utility Functions Group</TITLE>
8<LINK rel="stylesheet" href="../css/nitro.css" type="text/css">
9</HEAD>
10<BODY>
11<H1 align="left">MATH Utility Functions<img src="../image/NTR.gif"align="middle"><img src="../image/TWL.gif" align="middle"></H1>
12<H2>Syntax</H2>
13<DL>
14  <DD>
15  <PRE><CODE>#include &lt;nitro/math.h&gt;</CODE></PRE>
16  <PRE><CODE>static inline int MATH_IAbs( int a );
17static inline int MATH_IMin( int a , int b );
18static inline int MATH_IMax( int a , int b );
19MATH_ABS(         a );
20MATH_MIN(         a , b );
21MATH_MAX(         a , b );
22MATH_CLAMP(       x , low , high );
23MATH_ROUNDUP(     x , base );
24MATH_ROUNDDOWN(   x , base );
25MATH_ROUNDUP32(   x );
26MATH_ROUNDDOWN32( x );
27
28  </CODE></PRE>
29</DL>
30<H2>Description</H2>
31<P>This is the group of utility functions.</P>
32<TABLE border="1">
33  <TBODY>
34    <TR>
35      <TD><B><I>MATH_IAbs</I></B></TD>
36      <TD>Inline function that returns an int-type argument's absolute value.</TD>
37    </TR>
38    <TR>
39      <TD><B><I>MATH_IMin</I></B></TD>
40      <TD>Inline function that compares two int-type arguments and returns the smaller.</TD>
41    </TR>
42    <TR>
43      <TD><B><I>MATH_IMax</I></B></TD>
44      <TD>Inline function that compares two int-type arguments and returns the larger.</TD>
45    </TR>
46    <TR>
47      <TD><B><I>MATH_ABS</I></B></TD>
48      <TD>Function macro that returns argument's absolute value.<br />
49      Arguments are sometimes evaluated twice, so expressions with side effects must not be placed in arguments.</TD>
50    </TR>
51    <TR>
52      <TD><B><I>MATH_MIN</I></B></TD>
53      <TD>Function macro that compares two arguments and returns the smaller.<br />
54      Arguments are sometimes evaluated twice, so expressions with side effects must not be placed in arguments.</TD>
55    </TR>
56    <TR>
57      <TD><B><I>MATH_MAX</I></B></TD>
58      <TD>Function macro that compares two arguments and returns the larger.<br />
59      Arguments are sometimes evaluated twice, so expressions with side effects must not be placed in arguments.</TD>
60    </TR>
61    <TR>
62      <TD><B><I>MATH_CLAMP</I></B></TD>
63      <TD>Function macro that returns value holding range from low to high in argument.<br />
64      Arguments are sometimes evaluated twice, so expressions with side effects must not be placed in arguments.</TD>
65    </TR>
66    <TR>
67      <TD><B><I>MATH_ROUNDUP</I></B></TD>
68      <TD>Function macro that returns the value of the 1st argument, <CODE>x</CODE>, rounded up to a multiple of the 2nd argument, <CODE>base</CODE>. In other words, it returns the smallest multiple of base that is greater or equal to x. base must be a multiple of 2.</TD>
69    </TR>
70    <TR>
71      <TD><B><I>MATH_ROUNDDOWN</I></B></TD>
72      <TD>Function macro that returns the value of the 1st argument, <CODE>x</CODE>, rounded down to a multiple of the 2nd argument, <CODE>base</CODE>. In other words, it returns the largest multiple of <CODE>base</CODE> that is less than or equal to <CODE>x</CODE>. base must be a multiple of 2.</TD>
73    </TR>
74    <TR>
75      <TD><B><I>MATH_ROUNDUP32</I></B></TD>
76      <TD>Function macro that returns value of argument rounded up to a multiple of 32. The same as executing <nobr><code>MATH_ROUNDUP(x, 32)</code></nobr>.</TD>
77    </TR>
78    <TR>
79      <TD><B><I>MATH_ROUNDDOWN32</I></B></TD>
80      <TD>Function macro that returns value of argument rounded down to a multiple of 32. The same as executing <nobr><code>MATH_ROUNDDOWN(x, 32)</code></nobr>.</TD>
81    </TR>
82  </TBODY>
83</TABLE>
84<PRE>
85
86
87#define MATH_ABS(a)   (((a) &lt; 0 ) ? (-(a)) : (a))
88#define MATH_MIN(a,b) (((a) &lt;= (b)) ? (a) : (b))
89#define MATH_MAX(a,b) (((a) &gt;= (b)) ? (a) : (b))
90#define MATH_CLAMP(x, low, high) ( ( (x) &gt; (high) ) ? (high) : ( ( (x) &lt; (low) ) ? (low) : (x) ) )
91#define MATH_ROUNDUP(x, base)   (((x) + ((base)-1)) &amp; ~((base)-1))
92#define MATH_ROUNDDOWN(x, base) ((x) &amp; ~((base)-1))
93#define MATH_ROUNDUP32(x)   MATH_ROUNDUP(x, 32)
94#define MATH_ROUNDDOWN32(x) MATH_ROUNDDOWN(x, 32)
95
96</PRE>
97<H2>See Also</H2>
98<P><CODE>None.</CODE></P>
99<H2>Revision History</H2>
100<P>
1012005/06/02 Changed &amp; to &amp;.<BR>2004/12/14 Initial version.
102</P>
103<hr><p>CONFIDENTIAL</p></body>
104</HTML>
105