You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2017 lines
61 KiB

25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
  1. <HTML>
  2. <HEAD>
  3. <!-- Created by texi2html 1.56k from cln.texi on 2 June 2000 -->
  4. <TITLE>CLN, a Class Library for Numbers - 4. Functions on numbers</TITLE>
  5. </HEAD>
  6. <BODY>
  7. Go to the <A HREF="cln_1.html">first</A>, <A HREF="cln_3.html">previous</A>, <A HREF="cln_5.html">next</A>, <A HREF="cln_13.html">last</A> section, <A HREF="cln_toc.html">table of contents</A>.
  8. <P><HR><P>
  9. <H1><A NAME="SEC16" HREF="cln_toc.html#TOC16">4. Functions on numbers</A></H1>
  10. <P>
  11. Each of the number classes declares its mathematical operations in the
  12. corresponding include file. For example, if your code operates with
  13. objects of type <CODE>cl_I</CODE>, it should <CODE>#include &#60;cl_integer.h&#62;</CODE>.
  14. <H2><A NAME="SEC17" HREF="cln_toc.html#TOC17">4.1 Constructing numbers</A></H2>
  15. <P>
  16. Here is how to create number objects "from nothing".
  17. <H3><A NAME="SEC18" HREF="cln_toc.html#TOC18">4.1.1 Constructing integers</A></H3>
  18. <P>
  19. <CODE>cl_I</CODE> objects are most easily constructed from C integers and from
  20. strings. See section <A HREF="cln_3.html#SEC15">3.4 Conversions</A>.
  21. <H3><A NAME="SEC19" HREF="cln_toc.html#TOC19">4.1.2 Constructing rational numbers</A></H3>
  22. <P>
  23. <CODE>cl_RA</CODE> objects can be constructed from strings. The syntax
  24. for rational numbers is described in section <A HREF="cln_5.html#SEC45">5.1 Internal and printed representation</A>.
  25. Another standard way to produce a rational number is through application
  26. of <SAMP>`operator /'</SAMP> or <SAMP>`recip'</SAMP> on integers.
  27. <H3><A NAME="SEC20" HREF="cln_toc.html#TOC20">4.1.3 Constructing floating-point numbers</A></H3>
  28. <P>
  29. <CODE>cl_F</CODE> objects with low precision are most easily constructed from
  30. C <SAMP>`float'</SAMP> and <SAMP>`double'</SAMP>. See section <A HREF="cln_3.html#SEC15">3.4 Conversions</A>.
  31. <P>
  32. To construct a <CODE>cl_F</CODE> with high precision, you can use the conversion
  33. from <SAMP>`const char *'</SAMP>, but you have to specify the desired precision
  34. within the string. (See section <A HREF="cln_5.html#SEC45">5.1 Internal and printed representation</A>.)
  35. Example:
  36. <PRE>
  37. cl_F e = "0.271828182845904523536028747135266249775724709369996e+1_40";
  38. </PRE>
  39. <P>
  40. will set <SAMP>`e'</SAMP> to the given value, with a precision of 40 decimal digits.
  41. <P>
  42. The programmatic way to construct a <CODE>cl_F</CODE> with high precision is
  43. through the <CODE>cl_float</CODE> conversion function, see
  44. section <A HREF="cln_4.html#SEC40">4.11.1 Conversion to floating-point numbers</A>. For example, to compute
  45. <CODE>e</CODE> to 40 decimal places, first construct 1.0 to 40 decimal places
  46. and then apply the exponential function:
  47. <PRE>
  48. cl_float_format_t precision = cl_float_format(40);
  49. cl_F e = exp(cl_float(1,precision));
  50. </PRE>
  51. <H3><A NAME="SEC21" HREF="cln_toc.html#TOC21">4.1.4 Constructing complex numbers</A></H3>
  52. <P>
  53. Non-real <CODE>cl_N</CODE> objects are normally constructed through the function
  54. <PRE>
  55. cl_N complex (const cl_R&#38; realpart, const cl_R&#38; imagpart)
  56. </PRE>
  57. <P>
  58. See section <A HREF="cln_4.html#SEC24">4.4 Elementary complex functions</A>.
  59. <H2><A NAME="SEC22" HREF="cln_toc.html#TOC22">4.2 Elementary functions</A></H2>
  60. <P>
  61. Each of the classes <CODE>cl_N</CODE>, <CODE>cl_R</CODE>, <CODE>cl_RA</CODE>, <CODE>cl_I</CODE>,
  62. <CODE>cl_F</CODE>, <CODE>cl_SF</CODE>, <CODE>cl_FF</CODE>, <CODE>cl_DF</CODE>, <CODE>cl_LF</CODE>
  63. defines the following operations:
  64. <DL COMPACT>
  65. <DT><CODE><VAR>type</VAR> operator + (const <VAR>type</VAR>&#38;, const <VAR>type</VAR>&#38;)</CODE>
  66. <DD>
  67. <A NAME="IDX36"></A>
  68. Addition.
  69. <DT><CODE><VAR>type</VAR> operator - (const <VAR>type</VAR>&#38;, const <VAR>type</VAR>&#38;)</CODE>
  70. <DD>
  71. <A NAME="IDX37"></A>
  72. Subtraction.
  73. <DT><CODE><VAR>type</VAR> operator - (const <VAR>type</VAR>&#38;)</CODE>
  74. <DD>
  75. Returns the negative of the argument.
  76. <DT><CODE><VAR>type</VAR> plus1 (const <VAR>type</VAR>&#38; x)</CODE>
  77. <DD>
  78. <A NAME="IDX38"></A>
  79. Returns <CODE>x + 1</CODE>.
  80. <DT><CODE><VAR>type</VAR> minus1 (const <VAR>type</VAR>&#38; x)</CODE>
  81. <DD>
  82. <A NAME="IDX39"></A>
  83. Returns <CODE>x - 1</CODE>.
  84. <DT><CODE><VAR>type</VAR> operator * (const <VAR>type</VAR>&#38;, const <VAR>type</VAR>&#38;)</CODE>
  85. <DD>
  86. <A NAME="IDX40"></A>
  87. Multiplication.
  88. <DT><CODE><VAR>type</VAR> square (const <VAR>type</VAR>&#38; x)</CODE>
  89. <DD>
  90. <A NAME="IDX41"></A>
  91. Returns <CODE>x * x</CODE>.
  92. </DL>
  93. <P>
  94. Each of the classes <CODE>cl_N</CODE>, <CODE>cl_R</CODE>, <CODE>cl_RA</CODE>,
  95. <CODE>cl_F</CODE>, <CODE>cl_SF</CODE>, <CODE>cl_FF</CODE>, <CODE>cl_DF</CODE>, <CODE>cl_LF</CODE>
  96. defines the following operations:
  97. <DL COMPACT>
  98. <DT><CODE><VAR>type</VAR> operator / (const <VAR>type</VAR>&#38;, const <VAR>type</VAR>&#38;)</CODE>
  99. <DD>
  100. <A NAME="IDX42"></A>
  101. Division.
  102. <DT><CODE><VAR>type</VAR> recip (const <VAR>type</VAR>&#38;)</CODE>
  103. <DD>
  104. <A NAME="IDX43"></A>
  105. Returns the reciprocal of the argument.
  106. </DL>
  107. <P>
  108. The class <CODE>cl_I</CODE> doesn't define a <SAMP>`/'</SAMP> operation because
  109. in the C/C++ language this operator, applied to integral types,
  110. denotes the <SAMP>`floor'</SAMP> or <SAMP>`truncate'</SAMP> operation (which one of these,
  111. is implementation dependent). (See section <A HREF="cln_4.html#SEC26">4.6 Rounding functions</A>.)
  112. Instead, <CODE>cl_I</CODE> defines an "exact quotient" function:
  113. <DL COMPACT>
  114. <DT><CODE>cl_I exquo (const cl_I&#38; x, const cl_I&#38; y)</CODE>
  115. <DD>
  116. <A NAME="IDX44"></A>
  117. Checks that <CODE>y</CODE> divides <CODE>x</CODE>, and returns the quotient <CODE>x</CODE>/<CODE>y</CODE>.
  118. </DL>
  119. <P>
  120. The following exponentiation functions are defined:
  121. <DL COMPACT>
  122. <DT><CODE>cl_I expt_pos (const cl_I&#38; x, const cl_I&#38; y)</CODE>
  123. <DD>
  124. <A NAME="IDX45"></A>
  125. <DT><CODE>cl_RA expt_pos (const cl_RA&#38; x, const cl_I&#38; y)</CODE>
  126. <DD>
  127. <CODE>y</CODE> must be &#62; 0. Returns <CODE>x^y</CODE>.
  128. <DT><CODE>cl_RA expt (const cl_RA&#38; x, const cl_I&#38; y)</CODE>
  129. <DD>
  130. <A NAME="IDX46"></A>
  131. <DT><CODE>cl_R expt (const cl_R&#38; x, const cl_I&#38; y)</CODE>
  132. <DD>
  133. <DT><CODE>cl_N expt (const cl_N&#38; x, const cl_I&#38; y)</CODE>
  134. <DD>
  135. Returns <CODE>x^y</CODE>.
  136. </DL>
  137. <P>
  138. Each of the classes <CODE>cl_R</CODE>, <CODE>cl_RA</CODE>, <CODE>cl_I</CODE>,
  139. <CODE>cl_F</CODE>, <CODE>cl_SF</CODE>, <CODE>cl_FF</CODE>, <CODE>cl_DF</CODE>, <CODE>cl_LF</CODE>
  140. defines the following operation:
  141. <DL COMPACT>
  142. <DT><CODE><VAR>type</VAR> abs (const <VAR>type</VAR>&#38; x)</CODE>
  143. <DD>
  144. <A NAME="IDX47"></A>
  145. Returns the absolute value of <CODE>x</CODE>.
  146. This is <CODE>x</CODE> if <CODE>x &#62;= 0</CODE>, and <CODE>-x</CODE> if <CODE>x &#60;= 0</CODE>.
  147. </DL>
  148. <P>
  149. The class <CODE>cl_N</CODE> implements this as follows:
  150. <DL COMPACT>
  151. <DT><CODE>cl_R abs (const cl_N x)</CODE>
  152. <DD>
  153. Returns the absolute value of <CODE>x</CODE>.
  154. </DL>
  155. <P>
  156. Each of the classes <CODE>cl_N</CODE>, <CODE>cl_R</CODE>, <CODE>cl_RA</CODE>, <CODE>cl_I</CODE>,
  157. <CODE>cl_F</CODE>, <CODE>cl_SF</CODE>, <CODE>cl_FF</CODE>, <CODE>cl_DF</CODE>, <CODE>cl_LF</CODE>
  158. defines the following operation:
  159. <DL COMPACT>
  160. <DT><CODE><VAR>type</VAR> signum (const <VAR>type</VAR>&#38; x)</CODE>
  161. <DD>
  162. <A NAME="IDX48"></A>
  163. Returns the sign of <CODE>x</CODE>, in the same number format as <CODE>x</CODE>.
  164. This is defined as <CODE>x / abs(x)</CODE> if <CODE>x</CODE> is non-zero, and
  165. <CODE>x</CODE> if <CODE>x</CODE> is zero. If <CODE>x</CODE> is real, the value is either
  166. 0 or 1 or -1.
  167. </DL>
  168. <H2><A NAME="SEC23" HREF="cln_toc.html#TOC23">4.3 Elementary rational functions</A></H2>
  169. <P>
  170. Each of the classes <CODE>cl_RA</CODE>, <CODE>cl_I</CODE> defines the following operations:
  171. <DL COMPACT>
  172. <DT><CODE>cl_I numerator (const <VAR>type</VAR>&#38; x)</CODE>
  173. <DD>
  174. <A NAME="IDX49"></A>
  175. Returns the numerator of <CODE>x</CODE>.
  176. <DT><CODE>cl_I denominator (const <VAR>type</VAR>&#38; x)</CODE>
  177. <DD>
  178. <A NAME="IDX50"></A>
  179. Returns the denominator of <CODE>x</CODE>.
  180. </DL>
  181. <P>
  182. The numerator and denominator of a rational number are normalized in such
  183. a way that they have no factor in common and the denominator is positive.
  184. <H2><A NAME="SEC24" HREF="cln_toc.html#TOC24">4.4 Elementary complex functions</A></H2>
  185. <P>
  186. The class <CODE>cl_N</CODE> defines the following operation:
  187. <DL COMPACT>
  188. <DT><CODE>cl_N complex (const cl_R&#38; a, const cl_R&#38; b)</CODE>
  189. <DD>
  190. <A NAME="IDX51"></A>
  191. Returns the complex number <CODE>a+bi</CODE>, that is, the complex number with
  192. real part <CODE>a</CODE> and imaginary part <CODE>b</CODE>.
  193. </DL>
  194. <P>
  195. Each of the classes <CODE>cl_N</CODE>, <CODE>cl_R</CODE> defines the following operations:
  196. <DL COMPACT>
  197. <DT><CODE>cl_R realpart (const <VAR>type</VAR>&#38; x)</CODE>
  198. <DD>
  199. <A NAME="IDX52"></A>
  200. Returns the real part of <CODE>x</CODE>.
  201. <DT><CODE>cl_R imagpart (const <VAR>type</VAR>&#38; x)</CODE>
  202. <DD>
  203. <A NAME="IDX53"></A>
  204. Returns the imaginary part of <CODE>x</CODE>.
  205. <DT><CODE><VAR>type</VAR> conjugate (const <VAR>type</VAR>&#38; x)</CODE>
  206. <DD>
  207. <A NAME="IDX54"></A>
  208. Returns the complex conjugate of <CODE>x</CODE>.
  209. </DL>
  210. <P>
  211. We have the relations
  212. <UL>
  213. <LI>
  214. <CODE>x = complex(realpart(x), imagpart(x))</CODE>
  215. <LI>
  216. <CODE>conjugate(x) = complex(realpart(x), -imagpart(x))</CODE>
  217. </UL>
  218. <H2><A NAME="SEC25" HREF="cln_toc.html#TOC25">4.5 Comparisons</A></H2>
  219. <P>
  220. <A NAME="IDX55"></A>
  221. <P>
  222. Each of the classes <CODE>cl_N</CODE>, <CODE>cl_R</CODE>, <CODE>cl_RA</CODE>, <CODE>cl_I</CODE>,
  223. <CODE>cl_F</CODE>, <CODE>cl_SF</CODE>, <CODE>cl_FF</CODE>, <CODE>cl_DF</CODE>, <CODE>cl_LF</CODE>
  224. defines the following operations:
  225. <DL COMPACT>
  226. <DT><CODE>bool operator == (const <VAR>type</VAR>&#38;, const <VAR>type</VAR>&#38;)</CODE>
  227. <DD>
  228. <A NAME="IDX56"></A>
  229. <DT><CODE>bool operator != (const <VAR>type</VAR>&#38;, const <VAR>type</VAR>&#38;)</CODE>
  230. <DD>
  231. <A NAME="IDX57"></A>
  232. Comparison, as in C and C++.
  233. <DT><CODE>uint32 cl_equal_hashcode (const <VAR>type</VAR>&#38;)</CODE>
  234. <DD>
  235. <A NAME="IDX58"></A>
  236. Returns a 32-bit hash code that is the same for any two numbers which are
  237. the same according to <CODE>==</CODE>. This hash code depends on the number's value,
  238. not its type or precision.
  239. <DT><CODE>cl_boolean zerop (const <VAR>type</VAR>&#38; x)</CODE>
  240. <DD>
  241. <A NAME="IDX59"></A>
  242. Compare against zero: <CODE>x == 0</CODE>
  243. </DL>
  244. <P>
  245. Each of the classes <CODE>cl_R</CODE>, <CODE>cl_RA</CODE>, <CODE>cl_I</CODE>,
  246. <CODE>cl_F</CODE>, <CODE>cl_SF</CODE>, <CODE>cl_FF</CODE>, <CODE>cl_DF</CODE>, <CODE>cl_LF</CODE>
  247. defines the following operations:
  248. <DL COMPACT>
  249. <DT><CODE>cl_signean cl_compare (const <VAR>type</VAR>&#38; x, const <VAR>type</VAR>&#38; y)</CODE>
  250. <DD>
  251. <A NAME="IDX60"></A>
  252. Compares <CODE>x</CODE> and <CODE>y</CODE>. Returns +1 if <CODE>x</CODE>&#62;<CODE>y</CODE>,
  253. -1 if <CODE>x</CODE>&#60;<CODE>y</CODE>, 0 if <CODE>x</CODE>=<CODE>y</CODE>.
  254. <DT><CODE>bool operator &#60;= (const <VAR>type</VAR>&#38;, const <VAR>type</VAR>&#38;)</CODE>
  255. <DD>
  256. <A NAME="IDX61"></A>
  257. <DT><CODE>bool operator &#60; (const <VAR>type</VAR>&#38;, const <VAR>type</VAR>&#38;)</CODE>
  258. <DD>
  259. <A NAME="IDX62"></A>
  260. <DT><CODE>bool operator &#62;= (const <VAR>type</VAR>&#38;, const <VAR>type</VAR>&#38;)</CODE>
  261. <DD>
  262. <A NAME="IDX63"></A>
  263. <DT><CODE>bool operator &#62; (const <VAR>type</VAR>&#38;, const <VAR>type</VAR>&#38;)</CODE>
  264. <DD>
  265. <A NAME="IDX64"></A>
  266. Comparison, as in C and C++.
  267. <DT><CODE>cl_boolean minusp (const <VAR>type</VAR>&#38; x)</CODE>
  268. <DD>
  269. <A NAME="IDX65"></A>
  270. Compare against zero: <CODE>x &#60; 0</CODE>
  271. <DT><CODE>cl_boolean plusp (const <VAR>type</VAR>&#38; x)</CODE>
  272. <DD>
  273. <A NAME="IDX66"></A>
  274. Compare against zero: <CODE>x &#62; 0</CODE>
  275. <DT><CODE><VAR>type</VAR> max (const <VAR>type</VAR>&#38; x, const <VAR>type</VAR>&#38; y)</CODE>
  276. <DD>
  277. <A NAME="IDX67"></A>
  278. Return the maximum of <CODE>x</CODE> and <CODE>y</CODE>.
  279. <DT><CODE><VAR>type</VAR> min (const <VAR>type</VAR>&#38; x, const <VAR>type</VAR>&#38; y)</CODE>
  280. <DD>
  281. <A NAME="IDX68"></A>
  282. Return the minimum of <CODE>x</CODE> and <CODE>y</CODE>.
  283. </DL>
  284. <P>
  285. When a floating point number and a rational number are compared, the float
  286. is first converted to a rational number using the function <CODE>rational</CODE>.
  287. Since a floating point number actually represents an interval of real numbers,
  288. the result might be surprising.
  289. For example, <CODE>(cl_F)(cl_R)"1/3" == (cl_R)"1/3"</CODE> returns false because
  290. there is no floating point number whose value is exactly <CODE>1/3</CODE>.
  291. <H2><A NAME="SEC26" HREF="cln_toc.html#TOC26">4.6 Rounding functions</A></H2>
  292. <P>
  293. <A NAME="IDX69"></A>
  294. <P>
  295. When a real number is to be converted to an integer, there is no "best"
  296. rounding. The desired rounding function depends on the application.
  297. The Common Lisp and ISO Lisp standards offer four rounding functions:
  298. <DL COMPACT>
  299. <DT><CODE>floor(x)</CODE>
  300. <DD>
  301. This is the largest integer &#60;=<CODE>x</CODE>.
  302. <DT><CODE>ceiling(x)</CODE>
  303. <DD>
  304. This is the smallest integer &#62;=<CODE>x</CODE>.
  305. <DT><CODE>truncate(x)</CODE>
  306. <DD>
  307. Among the integers between 0 and <CODE>x</CODE> (inclusive) the one nearest to <CODE>x</CODE>.
  308. <DT><CODE>round(x)</CODE>
  309. <DD>
  310. The integer nearest to <CODE>x</CODE>. If <CODE>x</CODE> is exactly halfway between two
  311. integers, choose the even one.
  312. </DL>
  313. <P>
  314. These functions have different advantages:
  315. <P>
  316. <CODE>floor</CODE> and <CODE>ceiling</CODE> are translation invariant:
  317. <CODE>floor(x+n) = floor(x) + n</CODE> and <CODE>ceiling(x+n) = ceiling(x) + n</CODE>
  318. for every <CODE>x</CODE> and every integer <CODE>n</CODE>.
  319. <P>
  320. On the other hand, <CODE>truncate</CODE> and <CODE>round</CODE> are symmetric:
  321. <CODE>truncate(-x) = -truncate(x)</CODE> and <CODE>round(-x) = -round(x)</CODE>,
  322. and furthermore <CODE>round</CODE> is unbiased: on the "average", it rounds
  323. down exactly as often as it rounds up.
  324. <P>
  325. The functions are related like this:
  326. <UL>
  327. <LI>
  328. <CODE>ceiling(m/n) = floor((m+n-1)/n) = floor((m-1)/n)+1</CODE>
  329. for rational numbers <CODE>m/n</CODE> (<CODE>m</CODE>, <CODE>n</CODE> integers, <CODE>n</CODE>&#62;0), and
  330. <LI>
  331. <CODE>truncate(x) = sign(x) * floor(abs(x))</CODE>
  332. </UL>
  333. <P>
  334. Each of the classes <CODE>cl_R</CODE>, <CODE>cl_RA</CODE>,
  335. <CODE>cl_F</CODE>, <CODE>cl_SF</CODE>, <CODE>cl_FF</CODE>, <CODE>cl_DF</CODE>, <CODE>cl_LF</CODE>
  336. defines the following operations:
  337. <DL COMPACT>
  338. <DT><CODE>cl_I floor1 (const <VAR>type</VAR>&#38; x)</CODE>
  339. <DD>
  340. <A NAME="IDX70"></A>
  341. Returns <CODE>floor(x)</CODE>.
  342. <DT><CODE>cl_I ceiling1 (const <VAR>type</VAR>&#38; x)</CODE>
  343. <DD>
  344. <A NAME="IDX71"></A>
  345. Returns <CODE>ceiling(x)</CODE>.
  346. <DT><CODE>cl_I truncate1 (const <VAR>type</VAR>&#38; x)</CODE>
  347. <DD>
  348. <A NAME="IDX72"></A>
  349. Returns <CODE>truncate(x)</CODE>.
  350. <DT><CODE>cl_I round1 (const <VAR>type</VAR>&#38; x)</CODE>
  351. <DD>
  352. <A NAME="IDX73"></A>
  353. Returns <CODE>round(x)</CODE>.
  354. </DL>
  355. <P>
  356. Each of the classes <CODE>cl_R</CODE>, <CODE>cl_RA</CODE>, <CODE>cl_I</CODE>,
  357. <CODE>cl_F</CODE>, <CODE>cl_SF</CODE>, <CODE>cl_FF</CODE>, <CODE>cl_DF</CODE>, <CODE>cl_LF</CODE>
  358. defines the following operations:
  359. <DL COMPACT>
  360. <DT><CODE>cl_I floor1 (const <VAR>type</VAR>&#38; x, const <VAR>type</VAR>&#38; y)</CODE>
  361. <DD>
  362. Returns <CODE>floor(x/y)</CODE>.
  363. <DT><CODE>cl_I ceiling1 (const <VAR>type</VAR>&#38; x, const <VAR>type</VAR>&#38; y)</CODE>
  364. <DD>
  365. Returns <CODE>ceiling(x/y)</CODE>.
  366. <DT><CODE>cl_I truncate1 (const <VAR>type</VAR>&#38; x, const <VAR>type</VAR>&#38; y)</CODE>
  367. <DD>
  368. Returns <CODE>truncate(x/y)</CODE>.
  369. <DT><CODE>cl_I round1 (const <VAR>type</VAR>&#38; x, const <VAR>type</VAR>&#38; y)</CODE>
  370. <DD>
  371. Returns <CODE>round(x/y)</CODE>.
  372. </DL>
  373. <P>
  374. These functions are called <SAMP>`floor1'</SAMP>, ... here instead of
  375. <SAMP>`floor'</SAMP>, ..., because on some systems, system dependent include
  376. files define <SAMP>`floor'</SAMP> and <SAMP>`ceiling'</SAMP> as macros.
  377. <P>
  378. In many cases, one needs both the quotient and the remainder of a division.
  379. It is more efficient to compute both at the same time than to perform
  380. two divisions, one for quotient and the next one for the remainder.
  381. The following functions therefore return a structure containing both
  382. the quotient and the remainder. The suffix <SAMP>`2'</SAMP> indicates the number
  383. of "return values". The remainder is defined as follows:
  384. <UL>
  385. <LI>
  386. for the computation of <CODE>quotient = floor(x)</CODE>,
  387. <CODE>remainder = x - quotient</CODE>,
  388. <LI>
  389. for the computation of <CODE>quotient = floor(x,y)</CODE>,
  390. <CODE>remainder = x - quotient*y</CODE>,
  391. </UL>
  392. <P>
  393. and similarly for the other three operations.
  394. <P>
  395. Each of the classes <CODE>cl_R</CODE>, <CODE>cl_RA</CODE>,
  396. <CODE>cl_F</CODE>, <CODE>cl_SF</CODE>, <CODE>cl_FF</CODE>, <CODE>cl_DF</CODE>, <CODE>cl_LF</CODE>
  397. defines the following operations:
  398. <DL COMPACT>
  399. <DT><CODE>struct <VAR>type</VAR>_div_t { cl_I quotient; <VAR>type</VAR> remainder; };</CODE>
  400. <DD>
  401. <DT><CODE><VAR>type</VAR>_div_t floor2 (const <VAR>type</VAR>&#38; x)</CODE>
  402. <DD>
  403. <DT><CODE><VAR>type</VAR>_div_t ceiling2 (const <VAR>type</VAR>&#38; x)</CODE>
  404. <DD>
  405. <DT><CODE><VAR>type</VAR>_div_t truncate2 (const <VAR>type</VAR>&#38; x)</CODE>
  406. <DD>
  407. <DT><CODE><VAR>type</VAR>_div_t round2 (const <VAR>type</VAR>&#38; x)</CODE>
  408. <DD>
  409. </DL>
  410. <P>
  411. Each of the classes <CODE>cl_R</CODE>, <CODE>cl_RA</CODE>, <CODE>cl_I</CODE>,
  412. <CODE>cl_F</CODE>, <CODE>cl_SF</CODE>, <CODE>cl_FF</CODE>, <CODE>cl_DF</CODE>, <CODE>cl_LF</CODE>
  413. defines the following operations:
  414. <DL COMPACT>
  415. <DT><CODE>struct <VAR>type</VAR>_div_t { cl_I quotient; <VAR>type</VAR> remainder; };</CODE>
  416. <DD>
  417. <DT><CODE><VAR>type</VAR>_div_t floor2 (const <VAR>type</VAR>&#38; x, const <VAR>type</VAR>&#38; y)</CODE>
  418. <DD>
  419. <A NAME="IDX74"></A>
  420. <DT><CODE><VAR>type</VAR>_div_t ceiling2 (const <VAR>type</VAR>&#38; x, const <VAR>type</VAR>&#38; y)</CODE>
  421. <DD>
  422. <A NAME="IDX75"></A>
  423. <DT><CODE><VAR>type</VAR>_div_t truncate2 (const <VAR>type</VAR>&#38; x, const <VAR>type</VAR>&#38; y)</CODE>
  424. <DD>
  425. <A NAME="IDX76"></A>
  426. <DT><CODE><VAR>type</VAR>_div_t round2 (const <VAR>type</VAR>&#38; x, const <VAR>type</VAR>&#38; y)</CODE>
  427. <DD>
  428. <A NAME="IDX77"></A>
  429. </DL>
  430. <P>
  431. Sometimes, one wants the quotient as a floating-point number (of the
  432. same format as the argument, if the argument is a float) instead of as
  433. an integer. The prefix <SAMP>`f'</SAMP> indicates this.
  434. <P>
  435. Each of the classes
  436. <CODE>cl_F</CODE>, <CODE>cl_SF</CODE>, <CODE>cl_FF</CODE>, <CODE>cl_DF</CODE>, <CODE>cl_LF</CODE>
  437. defines the following operations:
  438. <DL COMPACT>
  439. <DT><CODE><VAR>type</VAR> ffloor (const <VAR>type</VAR>&#38; x)</CODE>
  440. <DD>
  441. <A NAME="IDX78"></A>
  442. <DT><CODE><VAR>type</VAR> fceiling (const <VAR>type</VAR>&#38; x)</CODE>
  443. <DD>
  444. <A NAME="IDX79"></A>
  445. <DT><CODE><VAR>type</VAR> ftruncate (const <VAR>type</VAR>&#38; x)</CODE>
  446. <DD>
  447. <A NAME="IDX80"></A>
  448. <DT><CODE><VAR>type</VAR> fround (const <VAR>type</VAR>&#38; x)</CODE>
  449. <DD>
  450. <A NAME="IDX81"></A>
  451. </DL>
  452. <P>
  453. and similarly for class <CODE>cl_R</CODE>, but with return type <CODE>cl_F</CODE>.
  454. <P>
  455. The class <CODE>cl_R</CODE> defines the following operations:
  456. <DL COMPACT>
  457. <DT><CODE>cl_F ffloor (const <VAR>type</VAR>&#38; x, const <VAR>type</VAR>&#38; y)</CODE>
  458. <DD>
  459. <DT><CODE>cl_F fceiling (const <VAR>type</VAR>&#38; x, const <VAR>type</VAR>&#38; y)</CODE>
  460. <DD>
  461. <DT><CODE>cl_F ftruncate (const <VAR>type</VAR>&#38; x, const <VAR>type</VAR>&#38; y)</CODE>
  462. <DD>
  463. <DT><CODE>cl_F fround (const <VAR>type</VAR>&#38; x, const <VAR>type</VAR>&#38; y)</CODE>
  464. <DD>
  465. </DL>
  466. <P>
  467. These functions also exist in versions which return both the quotient
  468. and the remainder. The suffix <SAMP>`2'</SAMP> indicates this.
  469. <P>
  470. Each of the classes
  471. <CODE>cl_F</CODE>, <CODE>cl_SF</CODE>, <CODE>cl_FF</CODE>, <CODE>cl_DF</CODE>, <CODE>cl_LF</CODE>
  472. defines the following operations:
  473. <A NAME="IDX82"></A>
  474. <A NAME="IDX83"></A>
  475. <A NAME="IDX84"></A>
  476. <A NAME="IDX85"></A>
  477. <A NAME="IDX86"></A>
  478. <DL COMPACT>
  479. <DT><CODE>struct <VAR>type</VAR>_fdiv_t { <VAR>type</VAR> quotient; <VAR>type</VAR> remainder; };</CODE>
  480. <DD>
  481. <DT><CODE><VAR>type</VAR>_fdiv_t ffloor2 (const <VAR>type</VAR>&#38; x)</CODE>
  482. <DD>
  483. <A NAME="IDX87"></A>
  484. <DT><CODE><VAR>type</VAR>_fdiv_t fceiling2 (const <VAR>type</VAR>&#38; x)</CODE>
  485. <DD>
  486. <A NAME="IDX88"></A>
  487. <DT><CODE><VAR>type</VAR>_fdiv_t ftruncate2 (const <VAR>type</VAR>&#38; x)</CODE>
  488. <DD>
  489. <A NAME="IDX89"></A>
  490. <DT><CODE><VAR>type</VAR>_fdiv_t fround2 (const <VAR>type</VAR>&#38; x)</CODE>
  491. <DD>
  492. <A NAME="IDX90"></A>
  493. </DL>
  494. <P>
  495. and similarly for class <CODE>cl_R</CODE>, but with quotient type <CODE>cl_F</CODE>.
  496. <A NAME="IDX91"></A>
  497. <P>
  498. The class <CODE>cl_R</CODE> defines the following operations:
  499. <DL COMPACT>
  500. <DT><CODE>struct <VAR>type</VAR>_fdiv_t { cl_F quotient; cl_R remainder; };</CODE>
  501. <DD>
  502. <DT><CODE><VAR>type</VAR>_fdiv_t ffloor2 (const <VAR>type</VAR>&#38; x, const <VAR>type</VAR>&#38; y)</CODE>
  503. <DD>
  504. <DT><CODE><VAR>type</VAR>_fdiv_t fceiling2 (const <VAR>type</VAR>&#38; x, const <VAR>type</VAR>&#38; y)</CODE>
  505. <DD>
  506. <DT><CODE><VAR>type</VAR>_fdiv_t ftruncate2 (const <VAR>type</VAR>&#38; x, const <VAR>type</VAR>&#38; y)</CODE>
  507. <DD>
  508. <DT><CODE><VAR>type</VAR>_fdiv_t fround2 (const <VAR>type</VAR>&#38; x, const <VAR>type</VAR>&#38; y)</CODE>
  509. <DD>
  510. </DL>
  511. <P>
  512. Other applications need only the remainder of a division.
  513. The remainder of <SAMP>`floor'</SAMP> and <SAMP>`ffloor'</SAMP> is called <SAMP>`mod'</SAMP>
  514. (abbreviation of "modulo"). The remainder <SAMP>`truncate'</SAMP> and
  515. <SAMP>`ftruncate'</SAMP> is called <SAMP>`rem'</SAMP> (abbreviation of "remainder").
  516. <UL>
  517. <LI>
  518. <CODE>mod(x,y) = floor2(x,y).remainder = x - floor(x/y)*y</CODE>
  519. <LI>
  520. <CODE>rem(x,y) = truncate2(x,y).remainder = x - truncate(x/y)*y</CODE>
  521. </UL>
  522. <P>
  523. If <CODE>x</CODE> and <CODE>y</CODE> are both &#62;= 0, <CODE>mod(x,y) = rem(x,y) &#62;= 0</CODE>.
  524. In general, <CODE>mod(x,y)</CODE> has the sign of <CODE>y</CODE> or is zero,
  525. and <CODE>rem(x,y)</CODE> has the sign of <CODE>x</CODE> or is zero.
  526. <P>
  527. The classes <CODE>cl_R</CODE>, <CODE>cl_I</CODE> define the following operations:
  528. <DL COMPACT>
  529. <DT><CODE><VAR>type</VAR> mod (const <VAR>type</VAR>&#38; x, const <VAR>type</VAR>&#38; y)</CODE>
  530. <DD>
  531. <A NAME="IDX92"></A>
  532. <DT><CODE><VAR>type</VAR> rem (const <VAR>type</VAR>&#38; x, const <VAR>type</VAR>&#38; y)</CODE>
  533. <DD>
  534. <A NAME="IDX93"></A>
  535. </DL>
  536. <H2><A NAME="SEC27" HREF="cln_toc.html#TOC27">4.7 Roots</A></H2>
  537. <P>
  538. Each of the classes <CODE>cl_R</CODE>,
  539. <CODE>cl_F</CODE>, <CODE>cl_SF</CODE>, <CODE>cl_FF</CODE>, <CODE>cl_DF</CODE>, <CODE>cl_LF</CODE>
  540. defines the following operation:
  541. <DL COMPACT>
  542. <DT><CODE><VAR>type</VAR> sqrt (const <VAR>type</VAR>&#38; x)</CODE>
  543. <DD>
  544. <A NAME="IDX94"></A>
  545. <CODE>x</CODE> must be &#62;= 0. This function returns the square root of <CODE>x</CODE>,
  546. normalized to be &#62;= 0. If <CODE>x</CODE> is the square of a rational number,
  547. <CODE>sqrt(x)</CODE> will be a rational number, else it will return a
  548. floating-point approximation.
  549. </DL>
  550. <P>
  551. The classes <CODE>cl_RA</CODE>, <CODE>cl_I</CODE> define the following operation:
  552. <DL COMPACT>
  553. <DT><CODE>cl_boolean sqrtp (const <VAR>type</VAR>&#38; x, <VAR>type</VAR>* root)</CODE>
  554. <DD>
  555. <A NAME="IDX95"></A>
  556. This tests whether <CODE>x</CODE> is a perfect square. If so, it returns true
  557. and the exact square root in <CODE>*root</CODE>, else it returns false.
  558. </DL>
  559. <P>
  560. Furthermore, for integers, similarly:
  561. <DL COMPACT>
  562. <DT><CODE>cl_boolean isqrt (const <VAR>type</VAR>&#38; x, <VAR>type</VAR>* root)</CODE>
  563. <DD>
  564. <A NAME="IDX96"></A>
  565. <CODE>x</CODE> should be &#62;= 0. This function sets <CODE>*root</CODE> to
  566. <CODE>floor(sqrt(x))</CODE> and returns the same value as <CODE>sqrtp</CODE>:
  567. the boolean value <CODE>(expt(*root,2) == x)</CODE>.
  568. </DL>
  569. <P>
  570. For <CODE>n</CODE>th roots, the classes <CODE>cl_RA</CODE>, <CODE>cl_I</CODE>
  571. define the following operation:
  572. <DL COMPACT>
  573. <DT><CODE>cl_boolean rootp (const <VAR>type</VAR>&#38; x, const cl_I&#38; n, <VAR>type</VAR>* root)</CODE>
  574. <DD>
  575. <A NAME="IDX97"></A>
  576. <CODE>x</CODE> must be &#62;= 0. <CODE>n</CODE> must be &#62; 0.
  577. This tests whether <CODE>x</CODE> is an <CODE>n</CODE>th power of a rational number.
  578. If so, it returns true and the exact root in <CODE>*root</CODE>, else it returns
  579. false.
  580. </DL>
  581. <P>
  582. The only square root function which accepts negative numbers is the one
  583. for class <CODE>cl_N</CODE>:
  584. <DL COMPACT>
  585. <DT><CODE>cl_N sqrt (const cl_N&#38; z)</CODE>
  586. <DD>
  587. <A NAME="IDX98"></A>
  588. Returns the square root of <CODE>z</CODE>, as defined by the formula
  589. <CODE>sqrt(z) = exp(log(z)/2)</CODE>. Conversion to a floating-point type
  590. or to a complex number are done if necessary. The range of the result is the
  591. right half plane <CODE>realpart(sqrt(z)) &#62;= 0</CODE>
  592. including the positive imaginary axis and 0, but excluding
  593. the negative imaginary axis.
  594. The result is an exact number only if <CODE>z</CODE> is an exact number.
  595. </DL>
  596. <H2><A NAME="SEC28" HREF="cln_toc.html#TOC28">4.8 Transcendental functions</A></H2>
  597. <P>
  598. <A NAME="IDX99"></A>
  599. <P>
  600. The transcendental functions return an exact result if the argument
  601. is exact and the result is exact as well. Otherwise they must return
  602. inexact numbers even if the argument is exact.
  603. For example, <CODE>cos(0) = 1</CODE> returns the rational number <CODE>1</CODE>.
  604. <H3><A NAME="SEC29" HREF="cln_toc.html#TOC29">4.8.1 Exponential and logarithmic functions</A></H3>
  605. <DL COMPACT>
  606. <DT><CODE>cl_R exp (const cl_R&#38; x)</CODE>
  607. <DD>
  608. <A NAME="IDX100"></A>
  609. <DT><CODE>cl_N exp (const cl_N&#38; x)</CODE>
  610. <DD>
  611. Returns the exponential function of <CODE>x</CODE>. This is <CODE>e^x</CODE> where
  612. <CODE>e</CODE> is the base of the natural logarithms. The range of the result
  613. is the entire complex plane excluding 0.
  614. <DT><CODE>cl_R ln (const cl_R&#38; x)</CODE>
  615. <DD>
  616. <A NAME="IDX101"></A>
  617. <CODE>x</CODE> must be &#62; 0. Returns the (natural) logarithm of x.
  618. <DT><CODE>cl_N log (const cl_N&#38; x)</CODE>
  619. <DD>
  620. <A NAME="IDX102"></A>
  621. Returns the (natural) logarithm of x. If <CODE>x</CODE> is real and positive,
  622. this is <CODE>ln(x)</CODE>. In general, <CODE>log(x) = log(abs(x)) + i*phase(x)</CODE>.
  623. The range of the result is the strip in the complex plane
  624. <CODE>-pi &#60; imagpart(log(x)) &#60;= pi</CODE>.
  625. <DT><CODE>cl_R phase (const cl_N&#38; x)</CODE>
  626. <DD>
  627. <A NAME="IDX103"></A>
  628. Returns the angle part of <CODE>x</CODE> in its polar representation as a
  629. complex number. That is, <CODE>phase(x) = atan(realpart(x),imagpart(x))</CODE>.
  630. This is also the imaginary part of <CODE>log(x)</CODE>.
  631. The range of the result is the interval <CODE>-pi &#60; phase(x) &#60;= pi</CODE>.
  632. The result will be an exact number only if <CODE>zerop(x)</CODE> or
  633. if <CODE>x</CODE> is real and positive.
  634. <DT><CODE>cl_R log (const cl_R&#38; a, const cl_R&#38; b)</CODE>
  635. <DD>
  636. <CODE>a</CODE> and <CODE>b</CODE> must be &#62; 0. Returns the logarithm of <CODE>a</CODE> with
  637. respect to base <CODE>b</CODE>. <CODE>log(a,b) = ln(a)/ln(b)</CODE>.
  638. The result can be exact only if <CODE>a = 1</CODE> or if <CODE>a</CODE> and <CODE>b</CODE>
  639. are both rational.
  640. <DT><CODE>cl_N log (const cl_N&#38; a, const cl_N&#38; b)</CODE>
  641. <DD>
  642. Returns the logarithm of <CODE>a</CODE> with respect to base <CODE>b</CODE>.
  643. <CODE>log(a,b) = log(a)/log(b)</CODE>.
  644. <DT><CODE>cl_N expt (const cl_N&#38; x, const cl_N&#38; y)</CODE>
  645. <DD>
  646. <A NAME="IDX104"></A>
  647. Exponentiation: Returns <CODE>x^y = exp(y*log(x))</CODE>.
  648. </DL>
  649. <P>
  650. The constant e = exp(1) = 2.71828... is returned by the following functions:
  651. <DL COMPACT>
  652. <DT><CODE>cl_F cl_exp1 (cl_float_format_t f)</CODE>
  653. <DD>
  654. <A NAME="IDX105"></A>
  655. Returns e as a float of format <CODE>f</CODE>.
  656. <DT><CODE>cl_F cl_exp1 (const cl_F&#38; y)</CODE>
  657. <DD>
  658. Returns e in the float format of <CODE>y</CODE>.
  659. <DT><CODE>cl_F cl_exp1 (void)</CODE>
  660. <DD>
  661. Returns e as a float of format <CODE>cl_default_float_format</CODE>.
  662. </DL>
  663. <H3><A NAME="SEC30" HREF="cln_toc.html#TOC30">4.8.2 Trigonometric functions</A></H3>
  664. <DL COMPACT>
  665. <DT><CODE>cl_R sin (const cl_R&#38; x)</CODE>
  666. <DD>
  667. <A NAME="IDX106"></A>
  668. Returns <CODE>sin(x)</CODE>. The range of the result is the interval
  669. <CODE>-1 &#60;= sin(x) &#60;= 1</CODE>.
  670. <DT><CODE>cl_N sin (const cl_N&#38; z)</CODE>
  671. <DD>
  672. Returns <CODE>sin(z)</CODE>. The range of the result is the entire complex plane.
  673. <DT><CODE>cl_R cos (const cl_R&#38; x)</CODE>
  674. <DD>
  675. <A NAME="IDX107"></A>
  676. Returns <CODE>cos(x)</CODE>. The range of the result is the interval
  677. <CODE>-1 &#60;= cos(x) &#60;= 1</CODE>.
  678. <DT><CODE>cl_N cos (const cl_N&#38; x)</CODE>
  679. <DD>
  680. Returns <CODE>cos(z)</CODE>. The range of the result is the entire complex plane.
  681. <DT><CODE>struct cl_cos_sin_t { cl_R cos; cl_R sin; };</CODE>
  682. <DD>
  683. <A NAME="IDX108"></A>
  684. <DT><CODE>cl_cos_sin_t cl_cos_sin (const cl_R&#38; x)</CODE>
  685. <DD>
  686. Returns both <CODE>sin(x)</CODE> and <CODE>cos(x)</CODE>. This is more efficient than
  687. <A NAME="IDX109"></A>
  688. computing them separately. The relation <CODE>cos^2 + sin^2 = 1</CODE> will
  689. hold only approximately.
  690. <DT><CODE>cl_R tan (const cl_R&#38; x)</CODE>
  691. <DD>
  692. <A NAME="IDX110"></A>
  693. <DT><CODE>cl_N tan (const cl_N&#38; x)</CODE>
  694. <DD>
  695. Returns <CODE>tan(x) = sin(x)/cos(x)</CODE>.
  696. <DT><CODE>cl_N cis (const cl_R&#38; x)</CODE>
  697. <DD>
  698. <A NAME="IDX111"></A>
  699. <DT><CODE>cl_N cis (const cl_N&#38; x)</CODE>
  700. <DD>
  701. Returns <CODE>exp(i*x)</CODE>. The name <SAMP>`cis'</SAMP> means "cos + i sin", because
  702. <CODE>e^(i*x) = cos(x) + i*sin(x)</CODE>.
  703. <A NAME="IDX112"></A>
  704. <A NAME="IDX113"></A>
  705. <DT><CODE>cl_N asin (const cl_N&#38; z)</CODE>
  706. <DD>
  707. Returns <CODE>arcsin(z)</CODE>. This is defined as
  708. <CODE>arcsin(z) = log(iz+sqrt(1-z^2))/i</CODE> and satisfies
  709. <CODE>arcsin(-z) = -arcsin(z)</CODE>.
  710. The range of the result is the strip in the complex domain
  711. <CODE>-pi/2 &#60;= realpart(arcsin(z)) &#60;= pi/2</CODE>, excluding the numbers
  712. with <CODE>realpart = -pi/2</CODE> and <CODE>imagpart &#60; 0</CODE> and the numbers
  713. with <CODE>realpart = pi/2</CODE> and <CODE>imagpart &#62; 0</CODE>.
  714. <DT><CODE>cl_N acos (const cl_N&#38; z)</CODE>
  715. <DD>
  716. <A NAME="IDX114"></A>
  717. Returns <CODE>arccos(z)</CODE>. This is defined as
  718. <CODE>arccos(z) = pi/2 - arcsin(z) = log(z+i*sqrt(1-z^2))/i</CODE>
  719. and satisfies <CODE>arccos(-z) = pi - arccos(z)</CODE>.
  720. The range of the result is the strip in the complex domain
  721. <CODE>0 &#60;= realpart(arcsin(z)) &#60;= pi</CODE>, excluding the numbers
  722. with <CODE>realpart = 0</CODE> and <CODE>imagpart &#60; 0</CODE> and the numbers
  723. with <CODE>realpart = pi</CODE> and <CODE>imagpart &#62; 0</CODE>.
  724. <A NAME="IDX115"></A>
  725. <A NAME="IDX116"></A>
  726. <DT><CODE>cl_R atan (const cl_R&#38; x, const cl_R&#38; y)</CODE>
  727. <DD>
  728. Returns the angle of the polar representation of the complex number
  729. <CODE>x+iy</CODE>. This is <CODE>atan(y/x)</CODE> if <CODE>x&#62;0</CODE>. The range of
  730. the result is the interval <CODE>-pi &#60; atan(x,y) &#60;= pi</CODE>. The result will
  731. be an exact number only if <CODE>x &#62; 0</CODE> and <CODE>y</CODE> is the exact <CODE>0</CODE>.
  732. WARNING: In Common Lisp, this function is called as <CODE>(atan y x)</CODE>,
  733. with reversed order of arguments.
  734. <DT><CODE>cl_R atan (const cl_R&#38; x)</CODE>
  735. <DD>
  736. Returns <CODE>arctan(x)</CODE>. This is the same as <CODE>atan(1,x)</CODE>. The range
  737. of the result is the interval <CODE>-pi/2 &#60; atan(x) &#60; pi/2</CODE>. The result
  738. will be an exact number only if <CODE>x</CODE> is the exact <CODE>0</CODE>.
  739. <DT><CODE>cl_N atan (const cl_N&#38; z)</CODE>
  740. <DD>
  741. Returns <CODE>arctan(z)</CODE>. This is defined as
  742. <CODE>arctan(z) = (log(1+iz)-log(1-iz)) / 2i</CODE> and satisfies
  743. <CODE>arctan(-z) = -arctan(z)</CODE>. The range of the result is
  744. the strip in the complex domain
  745. <CODE>-pi/2 &#60;= realpart(arctan(z)) &#60;= pi/2</CODE>, excluding the numbers
  746. with <CODE>realpart = -pi/2</CODE> and <CODE>imagpart &#62;= 0</CODE> and the numbers
  747. with <CODE>realpart = pi/2</CODE> and <CODE>imagpart &#60;= 0</CODE>.
  748. </DL>
  749. <P>
  750. <A NAME="IDX117"></A>
  751. <A NAME="IDX118"></A>
  752. Archimedes' constant pi = 3.14... is returned by the following functions:
  753. <DL COMPACT>
  754. <DT><CODE>cl_F cl_pi (cl_float_format_t f)</CODE>
  755. <DD>
  756. <A NAME="IDX119"></A>
  757. Returns pi as a float of format <CODE>f</CODE>.
  758. <DT><CODE>cl_F cl_pi (const cl_F&#38; y)</CODE>
  759. <DD>
  760. Returns pi in the float format of <CODE>y</CODE>.
  761. <DT><CODE>cl_F cl_pi (void)</CODE>
  762. <DD>
  763. Returns pi as a float of format <CODE>cl_default_float_format</CODE>.
  764. </DL>
  765. <H3><A NAME="SEC31" HREF="cln_toc.html#TOC31">4.8.3 Hyperbolic functions</A></H3>
  766. <DL COMPACT>
  767. <DT><CODE>cl_R sinh (const cl_R&#38; x)</CODE>
  768. <DD>
  769. <A NAME="IDX120"></A>
  770. Returns <CODE>sinh(x)</CODE>.
  771. <DT><CODE>cl_N sinh (const cl_N&#38; z)</CODE>
  772. <DD>
  773. Returns <CODE>sinh(z)</CODE>. The range of the result is the entire complex plane.
  774. <DT><CODE>cl_R cosh (const cl_R&#38; x)</CODE>
  775. <DD>
  776. <A NAME="IDX121"></A>
  777. Returns <CODE>cosh(x)</CODE>. The range of the result is the interval
  778. <CODE>cosh(x) &#62;= 1</CODE>.
  779. <DT><CODE>cl_N cosh (const cl_N&#38; z)</CODE>
  780. <DD>
  781. Returns <CODE>cosh(z)</CODE>. The range of the result is the entire complex plane.
  782. <DT><CODE>struct cl_cosh_sinh_t { cl_R cosh; cl_R sinh; };</CODE>
  783. <DD>
  784. <A NAME="IDX122"></A>
  785. <DT><CODE>cl_cosh_sinh_t cl_cosh_sinh (const cl_R&#38; x)</CODE>
  786. <DD>
  787. <A NAME="IDX123"></A>
  788. Returns both <CODE>sinh(x)</CODE> and <CODE>cosh(x)</CODE>. This is more efficient than
  789. computing them separately. The relation <CODE>cosh^2 - sinh^2 = 1</CODE> will
  790. hold only approximately.
  791. <DT><CODE>cl_R tanh (const cl_R&#38; x)</CODE>
  792. <DD>
  793. <A NAME="IDX124"></A>
  794. <DT><CODE>cl_N tanh (const cl_N&#38; x)</CODE>
  795. <DD>
  796. Returns <CODE>tanh(x) = sinh(x)/cosh(x)</CODE>.
  797. <DT><CODE>cl_N asinh (const cl_N&#38; z)</CODE>
  798. <DD>
  799. <A NAME="IDX125"></A>
  800. Returns <CODE>arsinh(z)</CODE>. This is defined as
  801. <CODE>arsinh(z) = log(z+sqrt(1+z^2))</CODE> and satisfies
  802. <CODE>arsinh(-z) = -arsinh(z)</CODE>.
  803. The range of the result is the strip in the complex domain
  804. <CODE>-pi/2 &#60;= imagpart(arsinh(z)) &#60;= pi/2</CODE>, excluding the numbers
  805. with <CODE>imagpart = -pi/2</CODE> and <CODE>realpart &#62; 0</CODE> and the numbers
  806. with <CODE>imagpart = pi/2</CODE> and <CODE>realpart &#60; 0</CODE>.
  807. <DT><CODE>cl_N acosh (const cl_N&#38; z)</CODE>
  808. <DD>
  809. <A NAME="IDX126"></A>
  810. Returns <CODE>arcosh(z)</CODE>. This is defined as
  811. <CODE>arcosh(z) = 2*log(sqrt((z+1)/2)+sqrt((z-1)/2))</CODE>.
  812. The range of the result is the half-strip in the complex domain
  813. <CODE>-pi &#60; imagpart(arcosh(z)) &#60;= pi, realpart(arcosh(z)) &#62;= 0</CODE>,
  814. excluding the numbers with <CODE>realpart = 0</CODE> and <CODE>-pi &#60; imagpart &#60; 0</CODE>.
  815. <DT><CODE>cl_N atanh (const cl_N&#38; z)</CODE>
  816. <DD>
  817. <A NAME="IDX127"></A>
  818. Returns <CODE>artanh(z)</CODE>. This is defined as
  819. <CODE>artanh(z) = (log(1+z)-log(1-z)) / 2</CODE> and satisfies
  820. <CODE>artanh(-z) = -artanh(z)</CODE>. The range of the result is
  821. the strip in the complex domain
  822. <CODE>-pi/2 &#60;= imagpart(artanh(z)) &#60;= pi/2</CODE>, excluding the numbers
  823. with <CODE>imagpart = -pi/2</CODE> and <CODE>realpart &#60;= 0</CODE> and the numbers
  824. with <CODE>imagpart = pi/2</CODE> and <CODE>realpart &#62;= 0</CODE>.
  825. </DL>
  826. <H3><A NAME="SEC32" HREF="cln_toc.html#TOC32">4.8.4 Euler gamma</A></H3>
  827. <P>
  828. <A NAME="IDX128"></A>
  829. <P>
  830. Euler's constant C = 0.577... is returned by the following functions:
  831. <DL COMPACT>
  832. <DT><CODE>cl_F cl_eulerconst (cl_float_format_t f)</CODE>
  833. <DD>
  834. <A NAME="IDX129"></A>
  835. Returns Euler's constant as a float of format <CODE>f</CODE>.
  836. <DT><CODE>cl_F cl_eulerconst (const cl_F&#38; y)</CODE>
  837. <DD>
  838. Returns Euler's constant in the float format of <CODE>y</CODE>.
  839. <DT><CODE>cl_F cl_eulerconst (void)</CODE>
  840. <DD>
  841. Returns Euler's constant as a float of format <CODE>cl_default_float_format</CODE>.
  842. </DL>
  843. <P>
  844. Catalan's constant G = 0.915... is returned by the following functions:
  845. <A NAME="IDX130"></A>
  846. <DL COMPACT>
  847. <DT><CODE>cl_F cl_catalanconst (cl_float_format_t f)</CODE>
  848. <DD>
  849. <A NAME="IDX131"></A>
  850. Returns Catalan's constant as a float of format <CODE>f</CODE>.
  851. <DT><CODE>cl_F cl_catalanconst (const cl_F&#38; y)</CODE>
  852. <DD>
  853. Returns Catalan's constant in the float format of <CODE>y</CODE>.
  854. <DT><CODE>cl_F cl_catalanconst (void)</CODE>
  855. <DD>
  856. Returns Catalan's constant as a float of format <CODE>cl_default_float_format</CODE>.
  857. </DL>
  858. <H3><A NAME="SEC33" HREF="cln_toc.html#TOC33">4.8.5 Riemann zeta</A></H3>
  859. <P>
  860. <A NAME="IDX132"></A>
  861. <P>
  862. Riemann's zeta function at an integral point <CODE>s&#62;1</CODE> is returned by the
  863. following functions:
  864. <DL COMPACT>
  865. <DT><CODE>cl_F cl_zeta (int s, cl_float_format_t f)</CODE>
  866. <DD>
  867. <A NAME="IDX133"></A>
  868. Returns Riemann's zeta function at <CODE>s</CODE> as a float of format <CODE>f</CODE>.
  869. <DT><CODE>cl_F cl_zeta (int s, const cl_F&#38; y)</CODE>
  870. <DD>
  871. Returns Riemann's zeta function at <CODE>s</CODE> in the float format of <CODE>y</CODE>.
  872. <DT><CODE>cl_F cl_zeta (int s)</CODE>
  873. <DD>
  874. Returns Riemann's zeta function at <CODE>s</CODE> as a float of format
  875. <CODE>cl_default_float_format</CODE>.
  876. </DL>
  877. <H2><A NAME="SEC34" HREF="cln_toc.html#TOC34">4.9 Functions on integers</A></H2>
  878. <H3><A NAME="SEC35" HREF="cln_toc.html#TOC35">4.9.1 Logical functions</A></H3>
  879. <P>
  880. Integers, when viewed as in two's complement notation, can be thought as
  881. infinite bit strings where the bits' values eventually are constant.
  882. For example,
  883. <PRE>
  884. 17 = ......00010001
  885. -6 = ......11111010
  886. </PRE>
  887. <P>
  888. The logical operations view integers as such bit strings and operate
  889. on each of the bit positions in parallel.
  890. <DL COMPACT>
  891. <DT><CODE>cl_I lognot (const cl_I&#38; x)</CODE>
  892. <DD>
  893. <A NAME="IDX134"></A>
  894. <DT><CODE>cl_I operator ~ (const cl_I&#38; x)</CODE>
  895. <DD>
  896. <A NAME="IDX135"></A>
  897. Logical not, like <CODE>~x</CODE> in C. This is the same as <CODE>-1-x</CODE>.
  898. <DT><CODE>cl_I logand (const cl_I&#38; x, const cl_I&#38; y)</CODE>
  899. <DD>
  900. <A NAME="IDX136"></A>
  901. <DT><CODE>cl_I operator &#38; (const cl_I&#38; x, const cl_I&#38; y)</CODE>
  902. <DD>
  903. <A NAME="IDX137"></A>
  904. Logical and, like <CODE>x &#38; y</CODE> in C.
  905. <DT><CODE>cl_I logior (const cl_I&#38; x, const cl_I&#38; y)</CODE>
  906. <DD>
  907. <A NAME="IDX138"></A>
  908. <DT><CODE>cl_I operator | (const cl_I&#38; x, const cl_I&#38; y)</CODE>
  909. <DD>
  910. <A NAME="IDX139"></A>
  911. Logical (inclusive) or, like <CODE>x | y</CODE> in C.
  912. <DT><CODE>cl_I logxor (const cl_I&#38; x, const cl_I&#38; y)</CODE>
  913. <DD>
  914. <A NAME="IDX140"></A>
  915. <DT><CODE>cl_I operator ^ (const cl_I&#38; x, const cl_I&#38; y)</CODE>
  916. <DD>
  917. <A NAME="IDX141"></A>
  918. Exclusive or, like <CODE>x ^ y</CODE> in C.
  919. <DT><CODE>cl_I logeqv (const cl_I&#38; x, const cl_I&#38; y)</CODE>
  920. <DD>
  921. <A NAME="IDX142"></A>
  922. Bitwise equivalence, like <CODE>~(x ^ y)</CODE> in C.
  923. <DT><CODE>cl_I lognand (const cl_I&#38; x, const cl_I&#38; y)</CODE>
  924. <DD>
  925. <A NAME="IDX143"></A>
  926. Bitwise not and, like <CODE>~(x &#38; y)</CODE> in C.
  927. <DT><CODE>cl_I lognor (const cl_I&#38; x, const cl_I&#38; y)</CODE>
  928. <DD>
  929. <A NAME="IDX144"></A>
  930. Bitwise not or, like <CODE>~(x | y)</CODE> in C.
  931. <DT><CODE>cl_I logandc1 (const cl_I&#38; x, const cl_I&#38; y)</CODE>
  932. <DD>
  933. <A NAME="IDX145"></A>
  934. Logical and, complementing the first argument, like <CODE>~x &#38; y</CODE> in C.
  935. <DT><CODE>cl_I logandc2 (const cl_I&#38; x, const cl_I&#38; y)</CODE>
  936. <DD>
  937. <A NAME="IDX146"></A>
  938. Logical and, complementing the second argument, like <CODE>x &#38; ~y</CODE> in C.
  939. <DT><CODE>cl_I logorc1 (const cl_I&#38; x, const cl_I&#38; y)</CODE>
  940. <DD>
  941. <A NAME="IDX147"></A>
  942. Logical or, complementing the first argument, like <CODE>~x | y</CODE> in C.
  943. <DT><CODE>cl_I logorc2 (const cl_I&#38; x, const cl_I&#38; y)</CODE>
  944. <DD>
  945. <A NAME="IDX148"></A>
  946. Logical or, complementing the second argument, like <CODE>x | ~y</CODE> in C.
  947. </DL>
  948. <P>
  949. These operations are all available though the function
  950. <DL COMPACT>
  951. <DT><CODE>cl_I boole (cl_boole op, const cl_I&#38; x, const cl_I&#38; y)</CODE>
  952. <DD>
  953. <A NAME="IDX149"></A>
  954. </DL>
  955. <P>
  956. where <CODE>op</CODE> must have one of the 16 values (each one stands for a function
  957. which combines two bits into one bit): <CODE>boole_clr</CODE>, <CODE>boole_set</CODE>,
  958. <CODE>boole_1</CODE>, <CODE>boole_2</CODE>, <CODE>boole_c1</CODE>, <CODE>boole_c2</CODE>,
  959. <CODE>boole_and</CODE>, <CODE>boole_ior</CODE>, <CODE>boole_xor</CODE>, <CODE>boole_eqv</CODE>,
  960. <CODE>boole_nand</CODE>, <CODE>boole_nor</CODE>, <CODE>boole_andc1</CODE>, <CODE>boole_andc2</CODE>,
  961. <CODE>boole_orc1</CODE>, <CODE>boole_orc2</CODE>.
  962. <A NAME="IDX150"></A>
  963. <A NAME="IDX151"></A>
  964. <A NAME="IDX152"></A>
  965. <A NAME="IDX153"></A>
  966. <A NAME="IDX154"></A>
  967. <A NAME="IDX155"></A>
  968. <A NAME="IDX156"></A>
  969. <A NAME="IDX157"></A>
  970. <A NAME="IDX158"></A>
  971. <A NAME="IDX159"></A>
  972. <A NAME="IDX160"></A>
  973. <A NAME="IDX161"></A>
  974. <A NAME="IDX162"></A>
  975. <A NAME="IDX163"></A>
  976. <A NAME="IDX164"></A>
  977. <P>
  978. Other functions that view integers as bit strings:
  979. <DL COMPACT>
  980. <DT><CODE>cl_boolean logtest (const cl_I&#38; x, const cl_I&#38; y)</CODE>
  981. <DD>
  982. <A NAME="IDX165"></A>
  983. Returns true if some bit is set in both <CODE>x</CODE> and <CODE>y</CODE>, i.e. if
  984. <CODE>logand(x,y) != 0</CODE>.
  985. <DT><CODE>cl_boolean logbitp (const cl_I&#38; n, const cl_I&#38; x)</CODE>
  986. <DD>
  987. <A NAME="IDX166"></A>
  988. Returns true if the <CODE>n</CODE>th bit (from the right) of <CODE>x</CODE> is set.
  989. Bit 0 is the least significant bit.
  990. <DT><CODE>uintL logcount (const cl_I&#38; x)</CODE>
  991. <DD>
  992. <A NAME="IDX167"></A>
  993. Returns the number of one bits in <CODE>x</CODE>, if <CODE>x</CODE> &#62;= 0, or
  994. the number of zero bits in <CODE>x</CODE>, if <CODE>x</CODE> &#60; 0.
  995. </DL>
  996. <P>
  997. The following functions operate on intervals of bits in integers.
  998. The type
  999. <PRE>
  1000. struct cl_byte { uintL size; uintL position; };
  1001. </PRE>
  1002. <P>
  1003. <A NAME="IDX168"></A>
  1004. represents the bit interval containing the bits
  1005. <CODE>position</CODE>...<CODE>position+size-1</CODE> of an integer.
  1006. The constructor <CODE>cl_byte(size,position)</CODE> constructs a <CODE>cl_byte</CODE>.
  1007. <DL COMPACT>
  1008. <DT><CODE>cl_I ldb (const cl_I&#38; n, const cl_byte&#38; b)</CODE>
  1009. <DD>
  1010. <A NAME="IDX169"></A>
  1011. extracts the bits of <CODE>n</CODE> described by the bit interval <CODE>b</CODE>
  1012. and returns them as a nonnegative integer with <CODE>b.size</CODE> bits.
  1013. <DT><CODE>cl_boolean ldb_test (const cl_I&#38; n, const cl_byte&#38; b)</CODE>
  1014. <DD>
  1015. <A NAME="IDX170"></A>
  1016. Returns true if some bit described by the bit interval <CODE>b</CODE> is set in
  1017. <CODE>n</CODE>.
  1018. <DT><CODE>cl_I dpb (const cl_I&#38; newbyte, const cl_I&#38; n, const cl_byte&#38; b)</CODE>
  1019. <DD>
  1020. <A NAME="IDX171"></A>
  1021. Returns <CODE>n</CODE>, with the bits described by the bit interval <CODE>b</CODE>
  1022. replaced by <CODE>newbyte</CODE>. Only the lowest <CODE>b.size</CODE> bits of
  1023. <CODE>newbyte</CODE> are relevant.
  1024. </DL>
  1025. <P>
  1026. The functions <CODE>ldb</CODE> and <CODE>dpb</CODE> implicitly shift. The following
  1027. functions are their counterparts without shifting:
  1028. <DL COMPACT>
  1029. <DT><CODE>cl_I mask_field (const cl_I&#38; n, const cl_byte&#38; b)</CODE>
  1030. <DD>
  1031. <A NAME="IDX172"></A>
  1032. returns an integer with the bits described by the bit interval <CODE>b</CODE>
  1033. copied from the corresponding bits in <CODE>n</CODE>, the other bits zero.
  1034. <DT><CODE>cl_I deposit_field (const cl_I&#38; newbyte, const cl_I&#38; n, const cl_byte&#38; b)</CODE>
  1035. <DD>
  1036. <A NAME="IDX173"></A>
  1037. returns an integer where the bits described by the bit interval <CODE>b</CODE>
  1038. come from <CODE>newbyte</CODE> and the other bits come from <CODE>n</CODE>.
  1039. </DL>
  1040. <P>
  1041. The following relations hold:
  1042. <UL>
  1043. <LI>
  1044. <CODE>ldb (n, b) = mask_field(n, b) &#62;&#62; b.position</CODE>,
  1045. <LI>
  1046. <CODE>dpb (newbyte, n, b) = deposit_field (newbyte &#60;&#60; b.position, n, b)</CODE>,
  1047. <LI>
  1048. <CODE>deposit_field(newbyte,n,b) = n ^ mask_field(n,b) ^ mask_field(new_byte,b)</CODE>.
  1049. </UL>
  1050. <P>
  1051. The following operations on integers as bit strings are efficient shortcuts
  1052. for common arithmetic operations:
  1053. <DL COMPACT>
  1054. <DT><CODE>cl_boolean oddp (const cl_I&#38; x)</CODE>
  1055. <DD>
  1056. <A NAME="IDX174"></A>
  1057. Returns true if the least significant bit of <CODE>x</CODE> is 1. Equivalent to
  1058. <CODE>mod(x,2) != 0</CODE>.
  1059. <DT><CODE>cl_boolean evenp (const cl_I&#38; x)</CODE>
  1060. <DD>
  1061. <A NAME="IDX175"></A>
  1062. Returns true if the least significant bit of <CODE>x</CODE> is 0. Equivalent to
  1063. <CODE>mod(x,2) == 0</CODE>.
  1064. <DT><CODE>cl_I operator &#60;&#60; (const cl_I&#38; x, const cl_I&#38; n)</CODE>
  1065. <DD>
  1066. <A NAME="IDX176"></A>
  1067. Shifts <CODE>x</CODE> by <CODE>n</CODE> bits to the left. <CODE>n</CODE> should be &#62;=0.
  1068. Equivalent to <CODE>x * expt(2,n)</CODE>.
  1069. <DT><CODE>cl_I operator &#62;&#62; (const cl_I&#38; x, const cl_I&#38; n)</CODE>
  1070. <DD>
  1071. <A NAME="IDX177"></A>
  1072. Shifts <CODE>x</CODE> by <CODE>n</CODE> bits to the right. <CODE>n</CODE> should be &#62;=0.
  1073. Bits shifted out to the right are thrown away.
  1074. Equivalent to <CODE>floor(x / expt(2,n))</CODE>.
  1075. <DT><CODE>cl_I ash (const cl_I&#38; x, const cl_I&#38; y)</CODE>
  1076. <DD>
  1077. <A NAME="IDX178"></A>
  1078. Shifts <CODE>x</CODE> by <CODE>y</CODE> bits to the left (if <CODE>y</CODE>&#62;=0) or
  1079. by <CODE>-y</CODE> bits to the right (if <CODE>y</CODE>&#60;=0). In other words, this
  1080. returns <CODE>floor(x * expt(2,y))</CODE>.
  1081. <DT><CODE>uintL integer_length (const cl_I&#38; x)</CODE>
  1082. <DD>
  1083. <A NAME="IDX179"></A>
  1084. Returns the number of bits (excluding the sign bit) needed to represent <CODE>x</CODE>
  1085. in two's complement notation. This is the smallest n &#62;= 0 such that
  1086. -2^n &#60;= x &#60; 2^n. If x &#62; 0, this is the unique n &#62; 0 such that
  1087. 2^(n-1) &#60;= x &#60; 2^n.
  1088. <DT><CODE>uintL ord2 (const cl_I&#38; x)</CODE>
  1089. <DD>
  1090. <A NAME="IDX180"></A>
  1091. <CODE>x</CODE> must be non-zero. This function returns the number of 0 bits at the
  1092. right of <CODE>x</CODE> in two's complement notation. This is the largest n &#62;= 0
  1093. such that 2^n divides <CODE>x</CODE>.
  1094. <DT><CODE>uintL power2p (const cl_I&#38; x)</CODE>
  1095. <DD>
  1096. <A NAME="IDX181"></A>
  1097. <CODE>x</CODE> must be &#62; 0. This function checks whether <CODE>x</CODE> is a power of 2.
  1098. If <CODE>x</CODE> = 2^(n-1), it returns n. Else it returns 0.
  1099. (See also the function <CODE>logp</CODE>.)
  1100. </DL>
  1101. <H3><A NAME="SEC36" HREF="cln_toc.html#TOC36">4.9.2 Number theoretic functions</A></H3>
  1102. <DL COMPACT>
  1103. <DT><CODE>uint32 gcd (uint32 a, uint32 b)</CODE>
  1104. <DD>
  1105. <A NAME="IDX182"></A>
  1106. <DT><CODE>cl_I gcd (const cl_I&#38; a, const cl_I&#38; b)</CODE>
  1107. <DD>
  1108. This function returns the greatest common divisor of <CODE>a</CODE> and <CODE>b</CODE>,
  1109. normalized to be &#62;= 0.
  1110. <DT><CODE>cl_I xgcd (const cl_I&#38; a, const cl_I&#38; b, cl_I* u, cl_I* v)</CODE>
  1111. <DD>
  1112. <A NAME="IDX183"></A>
  1113. This function ("extended gcd") returns the greatest common divisor <CODE>g</CODE> of
  1114. <CODE>a</CODE> and <CODE>b</CODE> and at the same time the representation of <CODE>g</CODE>
  1115. as an integral linear combination of <CODE>a</CODE> and <CODE>b</CODE>:
  1116. <CODE>u</CODE> and <CODE>v</CODE> with <CODE>u*a+v*b = g</CODE>, <CODE>g</CODE> &#62;= 0.
  1117. <CODE>u</CODE> and <CODE>v</CODE> will be normalized to be of smallest possible absolute
  1118. value, in the following sense: If <CODE>a</CODE> and <CODE>b</CODE> are non-zero, and
  1119. <CODE>abs(a) != abs(b)</CODE>, <CODE>u</CODE> and <CODE>v</CODE> will satisfy the inequalities
  1120. <CODE>abs(u) &#60;= abs(b)/(2*g)</CODE>, <CODE>abs(v) &#60;= abs(a)/(2*g)</CODE>.
  1121. <DT><CODE>cl_I lcm (const cl_I&#38; a, const cl_I&#38; b)</CODE>
  1122. <DD>
  1123. <A NAME="IDX184"></A>
  1124. This function returns the least common multiple of <CODE>a</CODE> and <CODE>b</CODE>,
  1125. normalized to be &#62;= 0.
  1126. <DT><CODE>cl_boolean logp (const cl_I&#38; a, const cl_I&#38; b, cl_RA* l)</CODE>
  1127. <DD>
  1128. <A NAME="IDX185"></A>
  1129. <DT><CODE>cl_boolean logp (const cl_RA&#38; a, const cl_RA&#38; b, cl_RA* l)</CODE>
  1130. <DD>
  1131. <CODE>a</CODE> must be &#62; 0. <CODE>b</CODE> must be &#62;0 and != 1. If log(a,b) is
  1132. rational number, this function returns true and sets *l = log(a,b), else
  1133. it returns false.
  1134. </DL>
  1135. <H3><A NAME="SEC37" HREF="cln_toc.html#TOC37">4.9.3 Combinatorial functions</A></H3>
  1136. <DL COMPACT>
  1137. <DT><CODE>cl_I factorial (uintL n)</CODE>
  1138. <DD>
  1139. <A NAME="IDX186"></A>
  1140. <CODE>n</CODE> must be a small integer &#62;= 0. This function returns the factorial
  1141. <CODE>n</CODE>! = <CODE>1*2*...*n</CODE>.
  1142. <DT><CODE>cl_I doublefactorial (uintL n)</CODE>
  1143. <DD>
  1144. <A NAME="IDX187"></A>
  1145. <CODE>n</CODE> must be a small integer &#62;= 0. This function returns the
  1146. doublefactorial <CODE>n</CODE>!! = <CODE>1*3*...*n</CODE> or
  1147. <CODE>n</CODE>!! = <CODE>2*4*...*n</CODE>, respectively.
  1148. <DT><CODE>cl_I binomial (uintL n, uintL k)</CODE>
  1149. <DD>
  1150. <A NAME="IDX188"></A>
  1151. <CODE>n</CODE> and <CODE>k</CODE> must be small integers &#62;= 0. This function returns the
  1152. binomial coefficient
  1153. (<CODE>n</CODE> choose <CODE>k</CODE>) = <CODE>n</CODE>! / <CODE>k</CODE>! <CODE>(n-k)</CODE>!
  1154. for 0 &#60;= k &#60;= n, 0 else.
  1155. </DL>
  1156. <H2><A NAME="SEC38" HREF="cln_toc.html#TOC38">4.10 Functions on floating-point numbers</A></H2>
  1157. <P>
  1158. Recall that a floating-point number consists of a sign <CODE>s</CODE>, an
  1159. exponent <CODE>e</CODE> and a mantissa <CODE>m</CODE>. The value of the number is
  1160. <CODE>(-1)^s * 2^e * m</CODE>.
  1161. <P>
  1162. Each of the classes
  1163. <CODE>cl_F</CODE>, <CODE>cl_SF</CODE>, <CODE>cl_FF</CODE>, <CODE>cl_DF</CODE>, <CODE>cl_LF</CODE>
  1164. defines the following operations.
  1165. <DL COMPACT>
  1166. <DT><CODE><VAR>type</VAR> scale_float (const <VAR>type</VAR>&#38; x, sintL delta)</CODE>
  1167. <DD>
  1168. <A NAME="IDX189"></A>
  1169. <DT><CODE><VAR>type</VAR> scale_float (const <VAR>type</VAR>&#38; x, const cl_I&#38; delta)</CODE>
  1170. <DD>
  1171. Returns <CODE>x*2^delta</CODE>. This is more efficient than an explicit multiplication
  1172. because it copies <CODE>x</CODE> and modifies the exponent.
  1173. </DL>
  1174. <P>
  1175. The following functions provide an abstract interface to the underlying
  1176. representation of floating-point numbers.
  1177. <DL COMPACT>
  1178. <DT><CODE>sintL float_exponent (const <VAR>type</VAR>&#38; x)</CODE>
  1179. <DD>
  1180. <A NAME="IDX190"></A>
  1181. Returns the exponent <CODE>e</CODE> of <CODE>x</CODE>.
  1182. For <CODE>x = 0.0</CODE>, this is 0. For <CODE>x</CODE> non-zero, this is the unique
  1183. integer with <CODE>2^(e-1) &#60;= abs(x) &#60; 2^e</CODE>.
  1184. <DT><CODE>sintL float_radix (const <VAR>type</VAR>&#38; x)</CODE>
  1185. <DD>
  1186. <A NAME="IDX191"></A>
  1187. Returns the base of the floating-point representation. This is always <CODE>2</CODE>.
  1188. <DT><CODE><VAR>type</VAR> float_sign (const <VAR>type</VAR>&#38; x)</CODE>
  1189. <DD>
  1190. <A NAME="IDX192"></A>
  1191. Returns the sign <CODE>s</CODE> of <CODE>x</CODE> as a float. The value is 1 for
  1192. <CODE>x</CODE> &#62;= 0, -1 for <CODE>x</CODE> &#60; 0.
  1193. <DT><CODE>uintL float_digits (const <VAR>type</VAR>&#38; x)</CODE>
  1194. <DD>
  1195. <A NAME="IDX193"></A>
  1196. Returns the number of mantissa bits in the floating-point representation
  1197. of <CODE>x</CODE>, including the hidden bit. The value only depends on the type
  1198. of <CODE>x</CODE>, not on its value.
  1199. <DT><CODE>uintL float_precision (const <VAR>type</VAR>&#38; x)</CODE>
  1200. <DD>
  1201. <A NAME="IDX194"></A>
  1202. Returns the number of significant mantissa bits in the floating-point
  1203. representation of <CODE>x</CODE>. Since denormalized numbers are not supported,
  1204. this is the same as <CODE>float_digits(x)</CODE> if <CODE>x</CODE> is non-zero, and
  1205. 0 if <CODE>x</CODE> = 0.
  1206. </DL>
  1207. <P>
  1208. The complete internal representation of a float is encoded in the type
  1209. <A NAME="IDX195"></A>
  1210. <A NAME="IDX196"></A>
  1211. <A NAME="IDX197"></A>
  1212. <A NAME="IDX198"></A>
  1213. <A NAME="IDX199"></A>
  1214. <CODE>cl_decoded_float</CODE> (or <CODE>cl_decoded_sfloat</CODE>, <CODE>cl_decoded_ffloat</CODE>,
  1215. <CODE>cl_decoded_dfloat</CODE>, <CODE>cl_decoded_lfloat</CODE>, respectively), defined by
  1216. <PRE>
  1217. struct cl_decoded_<VAR>type</VAR>float {
  1218. <VAR>type</VAR> mantissa; cl_I exponent; <VAR>type</VAR> sign;
  1219. };
  1220. </PRE>
  1221. <P>
  1222. and returned by the function
  1223. <DL COMPACT>
  1224. <DT><CODE>cl_decoded_<VAR>type</VAR>float decode_float (const <VAR>type</VAR>&#38; x)</CODE>
  1225. <DD>
  1226. <A NAME="IDX200"></A>
  1227. For <CODE>x</CODE> non-zero, this returns <CODE>(-1)^s</CODE>, <CODE>e</CODE>, <CODE>m</CODE> with
  1228. <CODE>x = (-1)^s * 2^e * m</CODE> and <CODE>0.5 &#60;= m &#60; 1.0</CODE>. For <CODE>x</CODE> = 0,
  1229. it returns <CODE>(-1)^s</CODE>=1, <CODE>e</CODE>=0, <CODE>m</CODE>=0.
  1230. <CODE>e</CODE> is the same as returned by the function <CODE>float_exponent</CODE>.
  1231. </DL>
  1232. <P>
  1233. A complete decoding in terms of integers is provided as type
  1234. <PRE>
  1235. <A NAME="IDX201"></A>struct cl_idecoded_float {
  1236. cl_I mantissa; cl_I exponent; cl_I sign;
  1237. };
  1238. </PRE>
  1239. <P>
  1240. by the following function:
  1241. <DL COMPACT>
  1242. <DT><CODE>cl_idecoded_float integer_decode_float (const <VAR>type</VAR>&#38; x)</CODE>
  1243. <DD>
  1244. <A NAME="IDX202"></A>
  1245. For <CODE>x</CODE> non-zero, this returns <CODE>(-1)^s</CODE>, <CODE>e</CODE>, <CODE>m</CODE> with
  1246. <CODE>x = (-1)^s * 2^e * m</CODE> and <CODE>m</CODE> an integer with <CODE>float_digits(x)</CODE>
  1247. bits. For <CODE>x</CODE> = 0, it returns <CODE>(-1)^s</CODE>=1, <CODE>e</CODE>=0, <CODE>m</CODE>=0.
  1248. WARNING: The exponent <CODE>e</CODE> is not the same as the one returned by
  1249. the functions <CODE>decode_float</CODE> and <CODE>float_exponent</CODE>.
  1250. </DL>
  1251. <P>
  1252. Some other function, implemented only for class <CODE>cl_F</CODE>:
  1253. <DL COMPACT>
  1254. <DT><CODE>cl_F float_sign (const cl_F&#38; x, const cl_F&#38; y)</CODE>
  1255. <DD>
  1256. <A NAME="IDX203"></A>
  1257. This returns a floating point number whose precision and absolute value
  1258. is that of <CODE>y</CODE> and whose sign is that of <CODE>x</CODE>. If <CODE>x</CODE> is
  1259. zero, it is treated as positive. Same for <CODE>y</CODE>.
  1260. </DL>
  1261. <H2><A NAME="SEC39" HREF="cln_toc.html#TOC39">4.11 Conversion functions</A></H2>
  1262. <P>
  1263. <A NAME="IDX204"></A>
  1264. <H3><A NAME="SEC40" HREF="cln_toc.html#TOC40">4.11.1 Conversion to floating-point numbers</A></H3>
  1265. <P>
  1266. The type <CODE>cl_float_format_t</CODE> describes a floating-point format.
  1267. <A NAME="IDX205"></A>
  1268. <DL COMPACT>
  1269. <DT><CODE>cl_float_format_t cl_float_format (uintL n)</CODE>
  1270. <DD>
  1271. <A NAME="IDX206"></A>
  1272. Returns the smallest float format which guarantees at least <CODE>n</CODE>
  1273. decimal digits in the mantissa (after the decimal point).
  1274. <DT><CODE>cl_float_format_t cl_float_format (const cl_F&#38; x)</CODE>
  1275. <DD>
  1276. Returns the floating point format of <CODE>x</CODE>.
  1277. <DT><CODE>cl_float_format_t cl_default_float_format</CODE>
  1278. <DD>
  1279. <A NAME="IDX207"></A>
  1280. Global variable: the default float format used when converting rational numbers
  1281. to floats.
  1282. </DL>
  1283. <P>
  1284. To convert a real number to a float, each of the types
  1285. <CODE>cl_R</CODE>, <CODE>cl_F</CODE>, <CODE>cl_I</CODE>, <CODE>cl_RA</CODE>,
  1286. <CODE>int</CODE>, <CODE>unsigned int</CODE>, <CODE>float</CODE>, <CODE>double</CODE>
  1287. defines the following operations:
  1288. <DL COMPACT>
  1289. <DT><CODE>cl_F cl_float (const <VAR>type</VAR>&#38;x, cl_float_format_t f)</CODE>
  1290. <DD>
  1291. <A NAME="IDX208"></A>
  1292. Returns <CODE>x</CODE> as a float of format <CODE>f</CODE>.
  1293. <DT><CODE>cl_F cl_float (const <VAR>type</VAR>&#38;x, const cl_F&#38; y)</CODE>
  1294. <DD>
  1295. Returns <CODE>x</CODE> in the float format of <CODE>y</CODE>.
  1296. <DT><CODE>cl_F cl_float (const <VAR>type</VAR>&#38;x)</CODE>
  1297. <DD>
  1298. Returns <CODE>x</CODE> as a float of format <CODE>cl_default_float_format</CODE> if
  1299. it is an exact number, or <CODE>x</CODE> itself if it is already a float.
  1300. </DL>
  1301. <P>
  1302. Of course, converting a number to a float can lose precision.
  1303. <P>
  1304. Every floating-point format has some characteristic numbers:
  1305. <DL COMPACT>
  1306. <DT><CODE>cl_F most_positive_float (cl_float_format_t f)</CODE>
  1307. <DD>
  1308. <A NAME="IDX209"></A>
  1309. Returns the largest (most positive) floating point number in float format <CODE>f</CODE>.
  1310. <DT><CODE>cl_F most_negative_float (cl_float_format_t f)</CODE>
  1311. <DD>
  1312. <A NAME="IDX210"></A>
  1313. Returns the smallest (most negative) floating point number in float format <CODE>f</CODE>.
  1314. <DT><CODE>cl_F least_positive_float (cl_float_format_t f)</CODE>
  1315. <DD>
  1316. <A NAME="IDX211"></A>
  1317. Returns the least positive floating point number (i.e. &#62; 0 but closest to 0)
  1318. in float format <CODE>f</CODE>.
  1319. <DT><CODE>cl_F least_negative_float (cl_float_format_t f)</CODE>
  1320. <DD>
  1321. <A NAME="IDX212"></A>
  1322. Returns the least negative floating point number (i.e. &#60; 0 but closest to 0)
  1323. in float format <CODE>f</CODE>.
  1324. <DT><CODE>cl_F float_epsilon (cl_float_format_t f)</CODE>
  1325. <DD>
  1326. <A NAME="IDX213"></A>
  1327. Returns the smallest floating point number e &#62; 0 such that <CODE>1+e != 1</CODE>.
  1328. <DT><CODE>cl_F float_negative_epsilon (cl_float_format_t f)</CODE>
  1329. <DD>
  1330. <A NAME="IDX214"></A>
  1331. Returns the smallest floating point number e &#62; 0 such that <CODE>1-e != 1</CODE>.
  1332. </DL>
  1333. <H3><A NAME="SEC41" HREF="cln_toc.html#TOC41">4.11.2 Conversion to rational numbers</A></H3>
  1334. <P>
  1335. Each of the classes <CODE>cl_R</CODE>, <CODE>cl_RA</CODE>, <CODE>cl_F</CODE>
  1336. defines the following operation:
  1337. <DL COMPACT>
  1338. <DT><CODE>cl_RA rational (const <VAR>type</VAR>&#38; x)</CODE>
  1339. <DD>
  1340. <A NAME="IDX215"></A>
  1341. Returns the value of <CODE>x</CODE> as an exact number. If <CODE>x</CODE> is already
  1342. an exact number, this is <CODE>x</CODE>. If <CODE>x</CODE> is a floating-point number,
  1343. the value is a rational number whose denominator is a power of 2.
  1344. </DL>
  1345. <P>
  1346. In order to convert back, say, <CODE>(cl_F)(cl_R)"1/3"</CODE> to <CODE>1/3</CODE>, there is
  1347. the function
  1348. <DL COMPACT>
  1349. <DT><CODE>cl_RA rationalize (const cl_R&#38; x)</CODE>
  1350. <DD>
  1351. <A NAME="IDX216"></A>
  1352. If <CODE>x</CODE> is a floating-point number, it actually represents an interval
  1353. of real numbers, and this function returns the rational number with
  1354. smallest denominator (and smallest numerator, in magnitude)
  1355. which lies in this interval.
  1356. If <CODE>x</CODE> is already an exact number, this function returns <CODE>x</CODE>.
  1357. </DL>
  1358. <P>
  1359. If <CODE>x</CODE> is any float, one has
  1360. <UL>
  1361. <LI>
  1362. <CODE>cl_float(rational(x),x) = x</CODE>
  1363. <LI>
  1364. <CODE>cl_float(rationalize(x),x) = x</CODE>
  1365. </UL>
  1366. <H2><A NAME="SEC42" HREF="cln_toc.html#TOC42">4.12 Random number generators</A></H2>
  1367. <P>
  1368. A random generator is a machine which produces (pseudo-)random numbers.
  1369. The include file <CODE>&#60;cl_random.h&#62;</CODE> defines a class <CODE>cl_random_state</CODE>
  1370. which contains the state of a random generator. If you make a copy
  1371. of the random number generator, the original one and the copy will produce
  1372. the same sequence of random numbers.
  1373. <P>
  1374. The following functions return (pseudo-)random numbers in different formats.
  1375. Calling one of these modifies the state of the random number generator in
  1376. a complicated but deterministic way.
  1377. <P>
  1378. The global variable
  1379. <A NAME="IDX217"></A>
  1380. <A NAME="IDX218"></A>
  1381. <PRE>
  1382. cl_random_state cl_default_random_state
  1383. </PRE>
  1384. <P>
  1385. contains a default random number generator. It is used when the functions
  1386. below are called without <CODE>cl_random_state</CODE> argument.
  1387. <DL COMPACT>
  1388. <DT><CODE>uint32 random32 (cl_random_state&#38; randomstate)</CODE>
  1389. <DD>
  1390. <DT><CODE>uint32 random32 ()</CODE>
  1391. <DD>
  1392. <A NAME="IDX219"></A>
  1393. Returns a random unsigned 32-bit number. All bits are equally random.
  1394. <DT><CODE>cl_I random_I (cl_random_state&#38; randomstate, const cl_I&#38; n)</CODE>
  1395. <DD>
  1396. <DT><CODE>cl_I random_I (const cl_I&#38; n)</CODE>
  1397. <DD>
  1398. <A NAME="IDX220"></A>
  1399. <CODE>n</CODE> must be an integer &#62; 0. This function returns a random integer <CODE>x</CODE>
  1400. in the range <CODE>0 &#60;= x &#60; n</CODE>.
  1401. <DT><CODE>cl_F random_F (cl_random_state&#38; randomstate, const cl_F&#38; n)</CODE>
  1402. <DD>
  1403. <DT><CODE>cl_F random_F (const cl_F&#38; n)</CODE>
  1404. <DD>
  1405. <A NAME="IDX221"></A>
  1406. <CODE>n</CODE> must be a float &#62; 0. This function returns a random floating-point
  1407. number of the same format as <CODE>n</CODE> in the range <CODE>0 &#60;= x &#60; n</CODE>.
  1408. <DT><CODE>cl_R random_R (cl_random_state&#38; randomstate, const cl_R&#38; n)</CODE>
  1409. <DD>
  1410. <DT><CODE>cl_R random_R (const cl_R&#38; n)</CODE>
  1411. <DD>
  1412. <A NAME="IDX222"></A>
  1413. Behaves like <CODE>random_I</CODE> if <CODE>n</CODE> is an integer and like <CODE>random_F</CODE>
  1414. if <CODE>n</CODE> is a float.
  1415. </DL>
  1416. <H2><A NAME="SEC43" HREF="cln_toc.html#TOC43">4.13 Obfuscating operators</A></H2>
  1417. <P>
  1418. <A NAME="IDX223"></A>
  1419. <P>
  1420. The modifying C/C++ operators <CODE>+=</CODE>, <CODE>-=</CODE>, <CODE>*=</CODE>, <CODE>/=</CODE>,
  1421. <CODE>&#38;=</CODE>, <CODE>|=</CODE>, <CODE>^=</CODE>, <CODE>&#60;&#60;=</CODE>, <CODE>&#62;&#62;=</CODE>
  1422. are not available by default because their
  1423. use tends to make programs unreadable. It is trivial to get away without
  1424. them. However, if you feel that you absolutely need these operators
  1425. to get happy, then add
  1426. <PRE>
  1427. #define WANT_OBFUSCATING_OPERATORS
  1428. </PRE>
  1429. <P>
  1430. <A NAME="IDX224"></A>
  1431. to the beginning of your source files, before the inclusion of any CLN
  1432. include files. This flag will enable the following operators:
  1433. <P>
  1434. For the classes <CODE>cl_N</CODE>, <CODE>cl_R</CODE>, <CODE>cl_RA</CODE>,
  1435. <CODE>cl_F</CODE>, <CODE>cl_SF</CODE>, <CODE>cl_FF</CODE>, <CODE>cl_DF</CODE>, <CODE>cl_LF</CODE>:
  1436. <DL COMPACT>
  1437. <DT><CODE><VAR>type</VAR>&#38; operator += (<VAR>type</VAR>&#38;, const <VAR>type</VAR>&#38;)</CODE>
  1438. <DD>
  1439. <A NAME="IDX225"></A>
  1440. <DT><CODE><VAR>type</VAR>&#38; operator -= (<VAR>type</VAR>&#38;, const <VAR>type</VAR>&#38;)</CODE>
  1441. <DD>
  1442. <A NAME="IDX226"></A>
  1443. <DT><CODE><VAR>type</VAR>&#38; operator *= (<VAR>type</VAR>&#38;, const <VAR>type</VAR>&#38;)</CODE>
  1444. <DD>
  1445. <A NAME="IDX227"></A>
  1446. <DT><CODE><VAR>type</VAR>&#38; operator /= (<VAR>type</VAR>&#38;, const <VAR>type</VAR>&#38;)</CODE>
  1447. <DD>
  1448. <A NAME="IDX228"></A>
  1449. </DL>
  1450. <P>
  1451. For the class <CODE>cl_I</CODE>:
  1452. <DL COMPACT>
  1453. <DT><CODE><VAR>type</VAR>&#38; operator += (<VAR>type</VAR>&#38;, const <VAR>type</VAR>&#38;)</CODE>
  1454. <DD>
  1455. <DT><CODE><VAR>type</VAR>&#38; operator -= (<VAR>type</VAR>&#38;, const <VAR>type</VAR>&#38;)</CODE>
  1456. <DD>
  1457. <DT><CODE><VAR>type</VAR>&#38; operator *= (<VAR>type</VAR>&#38;, const <VAR>type</VAR>&#38;)</CODE>
  1458. <DD>
  1459. <DT><CODE><VAR>type</VAR>&#38; operator &#38;= (<VAR>type</VAR>&#38;, const <VAR>type</VAR>&#38;)</CODE>
  1460. <DD>
  1461. <A NAME="IDX229"></A>
  1462. <DT><CODE><VAR>type</VAR>&#38; operator |= (<VAR>type</VAR>&#38;, const <VAR>type</VAR>&#38;)</CODE>
  1463. <DD>
  1464. <A NAME="IDX230"></A>
  1465. <DT><CODE><VAR>type</VAR>&#38; operator ^= (<VAR>type</VAR>&#38;, const <VAR>type</VAR>&#38;)</CODE>
  1466. <DD>
  1467. <A NAME="IDX231"></A>
  1468. <DT><CODE><VAR>type</VAR>&#38; operator &#60;&#60;= (<VAR>type</VAR>&#38;, const <VAR>type</VAR>&#38;)</CODE>
  1469. <DD>
  1470. <A NAME="IDX232"></A>
  1471. <DT><CODE><VAR>type</VAR>&#38; operator &#62;&#62;= (<VAR>type</VAR>&#38;, const <VAR>type</VAR>&#38;)</CODE>
  1472. <DD>
  1473. <A NAME="IDX233"></A>
  1474. </DL>
  1475. <P>
  1476. For the classes <CODE>cl_N</CODE>, <CODE>cl_R</CODE>, <CODE>cl_RA</CODE>, <CODE>cl_I</CODE>,
  1477. <CODE>cl_F</CODE>, <CODE>cl_SF</CODE>, <CODE>cl_FF</CODE>, <CODE>cl_DF</CODE>, <CODE>cl_LF</CODE>:
  1478. <DL COMPACT>
  1479. <DT><CODE><VAR>type</VAR>&#38; operator ++ (<VAR>type</VAR>&#38; x)</CODE>
  1480. <DD>
  1481. <A NAME="IDX234"></A>
  1482. The prefix operator <CODE>++x</CODE>.
  1483. <DT><CODE>void operator ++ (<VAR>type</VAR>&#38; x, int)</CODE>
  1484. <DD>
  1485. The postfix operator <CODE>x++</CODE>.
  1486. <DT><CODE><VAR>type</VAR>&#38; operator -- (<VAR>type</VAR>&#38; x)</CODE>
  1487. <DD>
  1488. <A NAME="IDX235"></A>
  1489. The prefix operator <CODE>--x</CODE>.
  1490. <DT><CODE>void operator -- (<VAR>type</VAR>&#38; x, int)</CODE>
  1491. <DD>
  1492. The postfix operator <CODE>x--</CODE>.
  1493. </DL>
  1494. <P>
  1495. Note that by using these obfuscating operators, you wouldn't gain efficiency:
  1496. In CLN <SAMP>`x += y;'</SAMP> is exactly the same as <SAMP>`x = x+y;'</SAMP>, not more
  1497. efficient.
  1498. <P><HR><P>
  1499. Go to the <A HREF="cln_1.html">first</A>, <A HREF="cln_3.html">previous</A>, <A HREF="cln_5.html">next</A>, <A HREF="cln_13.html">last</A> section, <A HREF="cln_toc.html">table of contents</A>.
  1500. </BODY>
  1501. </HTML>