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.

3718 lines
136 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
  1. This is cln.info, produced by makeinfo version 4.0 from cln.texi.
  2. This file documents CLN, a Class Library for Numbers.
  3. Published by Bruno Haible, `<haible@clisp.cons.org>' and Richard
  4. Kreckel, `<kreckel@ginac.de>'.
  5. Copyright (C) Bruno Haible 1995, 1996, 1997, 1998, 1999, 2000.
  6. Permission is granted to make and distribute verbatim copies of this
  7. manual provided the copyright notice and this permission notice are
  8. preserved on all copies.
  9. Permission is granted to copy and distribute modified versions of this
  10. manual under the conditions for verbatim copying, provided that the
  11. entire resulting derived work is distributed under the terms of a
  12. permission notice identical to this one.
  13. Permission is granted to copy and distribute translations of this manual
  14. into another language, under the above conditions for modified versions,
  15. except that this permission notice may be stated in a translation
  16. approved by the author.
  17. 
  18. File: cln.info, Node: Top, Next: Introduction, Prev: (dir), Up: (dir)
  19. * Menu:
  20. * Introduction::
  21. * Installation::
  22. * Ordinary number types::
  23. * Functions on numbers::
  24. * Input/Output::
  25. * Rings::
  26. * Modular integers::
  27. * Symbolic data types::
  28. * Univariate polynomials::
  29. * Internals::
  30. * Using the library::
  31. * Customizing::
  32. * Index::
  33. --- The Detailed Node Listing ---
  34. Installation
  35. * Prerequisites::
  36. * Building the library::
  37. * Installing the library::
  38. * Cleaning up::
  39. Prerequisites
  40. * C++ compiler::
  41. * Make utility::
  42. * Sed utility::
  43. Building the library
  44. * Using the GNU MP Library::
  45. Ordinary number types
  46. * Exact numbers::
  47. * Floating-point numbers::
  48. * Complex numbers::
  49. * Conversions::
  50. Functions on numbers
  51. * Constructing numbers::
  52. * Elementary functions::
  53. * Elementary rational functions::
  54. * Elementary complex functions::
  55. * Comparisons::
  56. * Rounding functions::
  57. * Roots::
  58. * Transcendental functions::
  59. * Functions on integers::
  60. * Functions on floating-point numbers::
  61. * Conversion functions::
  62. * Random number generators::
  63. * Obfuscating operators::
  64. Constructing numbers
  65. * Constructing integers::
  66. * Constructing rational numbers::
  67. * Constructing floating-point numbers::
  68. * Constructing complex numbers::
  69. Transcendental functions
  70. * Exponential and logarithmic functions::
  71. * Trigonometric functions::
  72. * Hyperbolic functions::
  73. * Euler gamma::
  74. * Riemann zeta::
  75. Functions on integers
  76. * Logical functions::
  77. * Number theoretic functions::
  78. * Combinatorial functions::
  79. Conversion functions
  80. * Conversion to floating-point numbers::
  81. * Conversion to rational numbers::
  82. Input/Output
  83. * Internal and printed representation::
  84. * Input functions::
  85. * Output functions::
  86. Modular integers
  87. * Modular integer rings::
  88. * Functions on modular integers::
  89. Symbolic data types
  90. * Strings::
  91. * Symbols::
  92. Univariate polynomials
  93. * Univariate polynomial rings::
  94. * Functions on univariate polynomials::
  95. * Special polynomials::
  96. Internals
  97. * Why C++ ?::
  98. * Memory efficiency::
  99. * Speed efficiency::
  100. * Garbage collection::
  101. Using the library
  102. * Compiler options::
  103. * Include files::
  104. * An Example::
  105. * Debugging support::
  106. Customizing
  107. * Error handling::
  108. * Floating-point underflow::
  109. * Customizing I/O::
  110. * Customizing the memory allocator::
  111. 
  112. File: cln.info, Node: Introduction, Next: Installation, Prev: Top, Up: Top
  113. Introduction
  114. ************
  115. CLN is a library for computations with all kinds of numbers. It has a
  116. rich set of number classes:
  117. * Integers (with unlimited precision),
  118. * Rational numbers,
  119. * Floating-point numbers:
  120. - Short float,
  121. - Single float,
  122. - Double float,
  123. - Long float (with unlimited precision),
  124. * Complex numbers,
  125. * Modular integers (integers modulo a fixed integer),
  126. * Univariate polynomials.
  127. The subtypes of the complex numbers among these are exactly the types
  128. of numbers known to the Common Lisp language. Therefore `CLN' can be
  129. used for Common Lisp implementations, giving `CLN' another meaning: it
  130. becomes an abbreviation of "Common Lisp Numbers".
  131. The CLN package implements
  132. * Elementary functions (`+', `-', `*', `/', `sqrt', comparisons,
  133. ...),
  134. * Logical functions (logical `and', `or', `not', ...),
  135. * Transcendental functions (exponential, logarithmic, trigonometric,
  136. hyperbolic functions and their inverse functions).
  137. CLN is a C++ library. Using C++ as an implementation language provides
  138. * efficiency: it compiles to machine code,
  139. * type safety: the C++ compiler knows about the number types and
  140. complains if, for example, you try to assign a float to an integer
  141. variable.
  142. * algebraic syntax: You can use the `+', `-', `*', `=', `==', ...
  143. operators as in C or C++.
  144. CLN is memory efficient:
  145. * Small integers and short floats are immediate, not heap allocated.
  146. * Heap-allocated memory is reclaimed through an automatic,
  147. non-interruptive garbage collection.
  148. CLN is speed efficient:
  149. * The kernel of CLN has been written in assembly language for some
  150. CPUs (`i386', `m68k', `sparc', `mips', `arm').
  151. * On all CPUs, CLN may be configured to use the superefficient
  152. low-level routines from GNU GMP version 3.
  153. * It uses Karatsuba multiplication, which is significantly faster
  154. for large numbers than the standard multiplication algorithm.
  155. * For very large numbers (more than 12000 decimal digits), it uses
  156. Sch�nhage-Strassen multiplication, which is an asymptotically
  157. optimal multiplication algorithm, for multiplication, division and
  158. radix conversion.
  159. CLN aims at being easily integrated into larger software packages:
  160. * The garbage collection imposes no burden on the main application.
  161. * The library provides hooks for memory allocation and exceptions.
  162. 
  163. File: cln.info, Node: Installation, Next: Ordinary number types, Prev: Introduction, Up: Top
  164. Installation
  165. ************
  166. This section describes how to install the CLN package on your system.
  167. * Menu:
  168. * Prerequisites::
  169. * Building the library::
  170. * Installing the library::
  171. * Cleaning up::
  172. 
  173. File: cln.info, Node: Prerequisites, Next: Building the library, Prev: Installation, Up: Installation
  174. Prerequisites
  175. =============
  176. * Menu:
  177. * C++ compiler::
  178. * Make utility::
  179. * Sed utility::
  180. 
  181. File: cln.info, Node: C++ compiler, Next: Make utility, Prev: Prerequisites, Up: Prerequisites
  182. C++ compiler
  183. ------------
  184. To build CLN, you need a C++ compiler. Actually, you need GNU `g++
  185. 2.7.0' or newer. On HPPA, you need GNU `g++ 2.8.0' or newer. I
  186. recommend GNU `g++ 2.95' or newer.
  187. The following C++ features are used: classes, member functions,
  188. overloading of functions and operators, constructors and destructors,
  189. inline, const, multiple inheritance, templates.
  190. The following C++ features are not used: `new', `delete', virtual
  191. inheritance, exceptions.
  192. CLN relies on semi-automatic ordering of initializations of static and
  193. global variables, a feature which I could implement for GNU g++ only.
  194. 
  195. File: cln.info, Node: Make utility, Next: Sed utility, Prev: C++ compiler, Up: Prerequisites
  196. Make utility
  197. ------------
  198. To build CLN, you also need to have GNU `make' installed.
  199. 
  200. File: cln.info, Node: Sed utility, Prev: Make utility, Up: Prerequisites
  201. Sed utility
  202. -----------
  203. To build CLN on HP-UX, you also need to have GNU `sed' installed. This
  204. is because the libtool script, which creates the CLN library, relies on
  205. `sed', and the vendor's `sed' utility on these systems is too limited.
  206. 
  207. File: cln.info, Node: Building the library, Next: Installing the library, Prev: Prerequisites, Up: Installation
  208. Building the library
  209. ====================
  210. As with any autoconfiguring GNU software, installation is as easy as
  211. this:
  212. $ ./configure
  213. $ make
  214. $ make check
  215. If on your system, `make' is not GNU `make', you have to use `gmake'
  216. instead of `make' above.
  217. The `configure' command checks out some features of your system and C++
  218. compiler and builds the `Makefile's. The `make' command builds the
  219. library. This step may take 4 hours on an average workstation. The
  220. `make check' runs some test to check that no important subroutine has
  221. been miscompiled.
  222. The `configure' command accepts options. To get a summary of them, try
  223. $ ./configure --help
  224. Some of the options are explained in detail in the `INSTALL.generic'
  225. file.
  226. You can specify the C compiler, the C++ compiler and their options
  227. through the following environment variables when running `configure':
  228. `CC'
  229. Specifies the C compiler.
  230. `CFLAGS'
  231. Flags to be given to the C compiler when compiling programs (not
  232. when linking).
  233. `CXX'
  234. Specifies the C++ compiler.
  235. `CXXFLAGS'
  236. Flags to be given to the C++ compiler when compiling programs (not
  237. when linking).
  238. Examples:
  239. $ CC="gcc" CFLAGS="-O" CXX="g++" CXXFLAGS="-O" ./configure
  240. $ CC="gcc -V 2.7.2" CFLAGS="-O -g" \
  241. CXX="g++ -V 2.7.2" CXXFLAGS="-O -g" ./configure
  242. $ CC="gcc -V 2.8.1" CFLAGS="-O -fno-exceptions" \
  243. CXX="g++ -V 2.8.1" CXXFLAGS="-O -fno-exceptions" ./configure
  244. $ CC="gcc -V egcs-2.91.60" CFLAGS="-O2 -fno-exceptions" \
  245. CXX="g++ -V egcs-2.91.60" CFLAGS="-O2 -fno-exceptions" ./configure
  246. Note that for these environment variables to take effect, you have to
  247. set them (assuming a Bourne-compatible shell) on the same line as the
  248. `configure' command. If you made the settings in earlier shell
  249. commands, you have to `export' the environment variables before calling
  250. `configure'. In a `csh' shell, you have to use the `setenv' command for
  251. setting each of the environment variables.
  252. On Linux, `g++' needs 15 MB to compile the tests. So you should better
  253. have 17 MB swap space and 1 MB room in $TMPDIR.
  254. If you use `g++' version 2.7.x, don't add `-O2' to the CXXFLAGS,
  255. because `g++ -O' generates better code for CLN than `g++ -O2'.
  256. If you use `g++' version 2.8.x or egcs-2.91.x (a.k.a. egcs-1.1) or
  257. gcc-2.95.x, I recommend adding `-fno-exceptions' to the CXXFLAGS. This
  258. will likely generate better code.
  259. If you use `g++' version egcs-2.91.x (egcs-1.1) or gcc-2.95.x on Sparc,
  260. add either `-O' or `-O2 -fno-schedule-insns' to the CXXFLAGS. With
  261. full `-O2', `g++' miscompiles the division routines. Also, for
  262. -enable-shared to work, you need egcs-1.1.2 or newer.
  263. By default, only a static library is built. You can build CLN as a
  264. shared library too, by calling `configure' with the option
  265. `--enable-shared'. To get it built as a shared library only, call
  266. `configure' with the options `--enable-shared --disable-static'.
  267. If you use `g++' version egcs-2.91.x (egcs-1.1) on Sparc, you cannot
  268. use `--enable-shared' because `g++' would miscompile parts of the
  269. library.
  270. * Menu:
  271. * Using the GNU MP Library::
  272. 
  273. File: cln.info, Node: Using the GNU MP Library, Prev: Building the library, Up: Building the library
  274. Using the GNU MP Library
  275. ------------------------
  276. Starting with version 1.0.4, CLN may be configured to make use of a
  277. preinstalled `gmp' library. Please make sure that you have at least
  278. `gmp' version 3.0 installed since earlier versions are unsupported and
  279. likely not to work. Enabling this feature by calling `configure' with
  280. the option `--with-gmp' is known to be quite a boost for CLN's
  281. performance.
  282. If you have installed the `gmp' library and its header file in some
  283. place where your compiler cannot find it by default, you must help
  284. `configure' by setting `CPPFLAGS' and `LDFLAGS'. Here is an example:
  285. $ CC="gcc" CFLAGS="-O2" CXX="g++" CXXFLAGS="-O2 -fno-exceptions" \
  286. CPPFLAGS="-I/opt/gmp/include" LDFLAGS="-L/opt/gmp/lib" ./configure --with-gmp
  287. 
  288. File: cln.info, Node: Installing the library, Next: Cleaning up, Prev: Building the library, Up: Installation
  289. Installing the library
  290. ======================
  291. As with any autoconfiguring GNU software, installation is as easy as
  292. this:
  293. $ make install
  294. The `make install' command installs the library and the include files
  295. into public places (`/usr/local/lib/' and `/usr/local/include/', if you
  296. haven't specified a `--prefix' option to `configure'). This step may
  297. require superuser privileges.
  298. If you have already built the library and wish to install it, but didn't
  299. specify `--prefix=...' at configure time, just re-run `configure',
  300. giving it the same options as the first time, plus the `--prefix=...'
  301. option.
  302. 
  303. File: cln.info, Node: Cleaning up, Prev: Installing the library, Up: Installation
  304. Cleaning up
  305. ===========
  306. You can remove system-dependent files generated by `make' through
  307. $ make clean
  308. You can remove all files generated by `make', thus reverting to a
  309. virgin distribution of CLN, through
  310. $ make distclean
  311. 
  312. File: cln.info, Node: Ordinary number types, Next: Functions on numbers, Prev: Installation, Up: Top
  313. Ordinary number types
  314. *********************
  315. CLN implements the following class hierarchy:
  316. Number
  317. cl_number
  318. <cl_number.h>
  319. |
  320. |
  321. Real or complex number
  322. cl_N
  323. <cl_complex.h>
  324. |
  325. |
  326. Real number
  327. cl_R
  328. <cl_real.h>
  329. |
  330. +-------------------+-------------------+
  331. | |
  332. Rational number Floating-point number
  333. cl_RA cl_F
  334. <cl_rational.h> <cl_float.h>
  335. | |
  336. | +-------------+-------------+-------------+
  337. Integer | | | |
  338. cl_I Short-Float Single-Float Double-Float Long-Float
  339. <cl_integer.h> cl_SF cl_FF cl_DF cl_LF
  340. <cl_sfloat.h> <cl_ffloat.h> <cl_dfloat.h> <cl_lfloat.h>
  341. The base class `cl_number' is an abstract base class. It is not useful
  342. to declare a variable of this type except if you want to completely
  343. disable compile-time type checking and use run-time type checking
  344. instead.
  345. The class `cl_N' comprises real and complex numbers. There is no
  346. special class for complex numbers since complex numbers with imaginary
  347. part `0' are automatically converted to real numbers.
  348. The class `cl_R' comprises real numbers of different kinds. It is an
  349. abstract class.
  350. The class `cl_RA' comprises exact real numbers: rational numbers,
  351. including integers. There is no special class for non-integral rational
  352. numbers since rational numbers with denominator `1' are automatically
  353. converted to integers.
  354. The class `cl_F' implements floating-point approximations to real
  355. numbers. It is an abstract class.
  356. * Menu:
  357. * Exact numbers::
  358. * Floating-point numbers::
  359. * Complex numbers::
  360. * Conversions::
  361. 
  362. File: cln.info, Node: Exact numbers, Next: Floating-point numbers, Prev: Ordinary number types, Up: Ordinary number types
  363. Exact numbers
  364. =============
  365. Some numbers are represented as exact numbers: there is no loss of
  366. information when such a number is converted from its mathematical value
  367. to its internal representation. On exact numbers, the elementary
  368. operations (`+', `-', `*', `/', comparisons, ...) compute the completely
  369. correct result.
  370. In CLN, the exact numbers are:
  371. * rational numbers (including integers),
  372. * complex numbers whose real and imaginary parts are both rational
  373. numbers.
  374. Rational numbers are always normalized to the form
  375. `NUMERATOR/DENOMINATOR' where the numerator and denominator are coprime
  376. integers and the denominator is positive. If the resulting denominator
  377. is `1', the rational number is converted to an integer.
  378. Small integers (typically in the range `-2^30'...`2^30-1', for 32-bit
  379. machines) are especially efficient, because they consume no heap
  380. allocation. Otherwise the distinction between these immediate integers
  381. (called "fixnums") and heap allocated integers (called "bignums") is
  382. completely transparent.
  383. 
  384. File: cln.info, Node: Floating-point numbers, Next: Complex numbers, Prev: Exact numbers, Up: Ordinary number types
  385. Floating-point numbers
  386. ======================
  387. Not all real numbers can be represented exactly. (There is an easy
  388. mathematical proof for this: Only a countable set of numbers can be
  389. stored exactly in a computer, even if one assumes that it has unlimited
  390. storage. But there are uncountably many real numbers.) So some
  391. approximation is needed. CLN implements ordinary floating-point
  392. numbers, with mantissa and exponent.
  393. The elementary operations (`+', `-', `*', `/', ...) only return
  394. approximate results. For example, the value of the expression `(cl_F)
  395. 0.3 + (cl_F) 0.4' prints as `0.70000005', not as `0.7'. Rounding errors
  396. like this one are inevitable when computing with floating-point numbers.
  397. Nevertheless, CLN rounds the floating-point results of the operations
  398. `+', `-', `*', `/', `sqrt' according to the "round-to-even" rule: It
  399. first computes the exact mathematical result and then returns the
  400. floating-point number which is nearest to this. If two floating-point
  401. numbers are equally distant from the ideal result, the one with a `0'
  402. in its least significant mantissa bit is chosen.
  403. Similarly, testing floating point numbers for equality `x == y' is
  404. gambling with random errors. Better check for `abs(x - y) < epsilon'
  405. for some well-chosen `epsilon'.
  406. Floating point numbers come in four flavors:
  407. * Short floats, type `cl_SF'. They have 1 sign bit, 8 exponent bits
  408. (including the exponent's sign), and 17 mantissa bits (including
  409. the "hidden" bit). They don't consume heap allocation.
  410. * Single floats, type `cl_FF'. They have 1 sign bit, 8 exponent
  411. bits (including the exponent's sign), and 24 mantissa bits
  412. (including the "hidden" bit). In CLN, they are represented as
  413. IEEE single-precision floating point numbers. This corresponds
  414. closely to the C/C++ type `float'.
  415. * Double floats, type `cl_DF'. They have 1 sign bit, 11 exponent
  416. bits (including the exponent's sign), and 53 mantissa bits
  417. (including the "hidden" bit). In CLN, they are represented as
  418. IEEE double-precision floating point numbers. This corresponds
  419. closely to the C/C++ type `double'.
  420. * Long floats, type `cl_LF'. They have 1 sign bit, 32 exponent bits
  421. (including the exponent's sign), and n mantissa bits (including
  422. the "hidden" bit), where n >= 64. The precision of a long float
  423. is unlimited, but once created, a long float has a fixed
  424. precision. (No "lazy recomputation".)
  425. Of course, computations with long floats are more expensive than those
  426. with smaller floating-point formats.
  427. CLN does not implement features like NaNs, denormalized numbers and
  428. gradual underflow. If the exponent range of some floating-point type is
  429. too limited for your application, choose another floating-point type
  430. with larger exponent range.
  431. As a user of CLN, you can forget about the differences between the four
  432. floating-point types and just declare all your floating-point variables
  433. as being of type `cl_F'. This has the advantage that when you change
  434. the precision of some computation (say, from `cl_DF' to `cl_LF'), you
  435. don't have to change the code, only the precision of the initial
  436. values. Also, many transcendental functions have been declared as
  437. returning a `cl_F' when the argument is a `cl_F', but such declarations
  438. are missing for the types `cl_SF', `cl_FF', `cl_DF', `cl_LF'. (Such
  439. declarations would be wrong if the floating point contagion rule
  440. happened to change in the future.)
  441. 
  442. File: cln.info, Node: Complex numbers, Next: Conversions, Prev: Floating-point numbers, Up: Ordinary number types
  443. Complex numbers
  444. ===============
  445. Complex numbers, as implemented by the class `cl_N', have a real part
  446. and an imaginary part, both real numbers. A complex number whose
  447. imaginary part is the exact number `0' is automatically converted to a
  448. real number.
  449. Complex numbers can arise from real numbers alone, for example through
  450. application of `sqrt' or transcendental functions.
  451. 
  452. File: cln.info, Node: Conversions, Prev: Complex numbers, Up: Ordinary number types
  453. Conversions
  454. ===========
  455. Conversions from any class to any its superclasses ("base classes" in
  456. C++ terminology) is done automatically.
  457. Conversions from the C built-in types `long' and `unsigned long' are
  458. provided for the classes `cl_I', `cl_RA', `cl_R', `cl_N' and
  459. `cl_number'.
  460. Conversions from the C built-in types `int' and `unsigned int' are
  461. provided for the classes `cl_I', `cl_RA', `cl_R', `cl_N' and
  462. `cl_number'. However, these conversions emphasize efficiency. Their
  463. range is therefore limited:
  464. - The conversion from `int' works only if the argument is < 2^29 and
  465. > -2^29.
  466. - The conversion from `unsigned int' works only if the argument is <
  467. 2^29.
  468. In a declaration like `cl_I x = 10;' the C++ compiler is able to do the
  469. conversion of `10' from `int' to `cl_I' at compile time already. On the
  470. other hand, code like `cl_I x = 1000000000;' is in error. So, if you
  471. want to be sure that an `int' whose magnitude is not guaranteed to be <
  472. 2^29 is correctly converted to a `cl_I', first convert it to a `long'.
  473. Similarly, if a large `unsigned int' is to be converted to a `cl_I',
  474. first convert it to an `unsigned long'.
  475. Conversions from the C built-in type `float' are provided for the
  476. classes `cl_FF', `cl_F', `cl_R', `cl_N' and `cl_number'.
  477. Conversions from the C built-in type `double' are provided for the
  478. classes `cl_DF', `cl_F', `cl_R', `cl_N' and `cl_number'.
  479. Conversions from `const char *' are provided for the classes `cl_I',
  480. `cl_RA', `cl_SF', `cl_FF', `cl_DF', `cl_LF', `cl_F', `cl_R', `cl_N'.
  481. The easiest way to specify a value which is outside of the range of the
  482. C++ built-in types is therefore to specify it as a string, like this:
  483. cl_I order_of_rubiks_cube_group = "43252003274489856000";
  484. Note that this conversion is done at runtime, not at compile-time.
  485. Conversions from `cl_I' to the C built-in types `int', `unsigned int',
  486. `long', `unsigned long' are provided through the functions
  487. `int cl_I_to_int (const cl_I& x)'
  488. `unsigned int cl_I_to_uint (const cl_I& x)'
  489. `long cl_I_to_long (const cl_I& x)'
  490. `unsigned long cl_I_to_ulong (const cl_I& x)'
  491. Returns `x' as element of the C type CTYPE. If `x' is not
  492. representable in the range of CTYPE, a runtime error occurs.
  493. Conversions from the classes `cl_I', `cl_RA', `cl_SF', `cl_FF',
  494. `cl_DF', `cl_LF', `cl_F' and `cl_R' to the C built-in types `float' and
  495. `double' are provided through the functions
  496. `float cl_float_approx (const TYPE& x)'
  497. `double cl_double_approx (const TYPE& x)'
  498. Returns an approximation of `x' of C type CTYPE. If `abs(x)' is
  499. too close to 0 (underflow), 0 is returned. If `abs(x)' is too
  500. large (overflow), an IEEE infinity is returned.
  501. Conversions from any class to any of its subclasses ("derived classes"
  502. in C++ terminology) are not provided. Instead, you can assert and check
  503. that a value belongs to a certain subclass, and return it as element of
  504. that class, using the `As' and `The' macros. `As(TYPE)(VALUE)' checks
  505. that VALUE belongs to TYPE and returns it as such. `The(TYPE)(VALUE)'
  506. assumes that VALUE belongs to TYPE and returns it as such. It is your
  507. responsibility to ensure that this assumption is valid. Example:
  508. cl_I x = ...;
  509. if (!(x >= 0)) abort();
  510. cl_I ten_x = The(cl_I)(expt(10,x)); // If x >= 0, 10^x is an integer.
  511. // In general, it would be a rational number.
  512. 
  513. File: cln.info, Node: Functions on numbers, Next: Input/Output, Prev: Ordinary number types, Up: Top
  514. Functions on numbers
  515. ********************
  516. Each of the number classes declares its mathematical operations in the
  517. corresponding include file. For example, if your code operates with
  518. objects of type `cl_I', it should `#include <cl_integer.h>'.
  519. * Menu:
  520. * Constructing numbers::
  521. * Elementary functions::
  522. * Elementary rational functions::
  523. * Elementary complex functions::
  524. * Comparisons::
  525. * Rounding functions::
  526. * Roots::
  527. * Transcendental functions::
  528. * Functions on integers::
  529. * Functions on floating-point numbers::
  530. * Conversion functions::
  531. * Random number generators::
  532. * Obfuscating operators::
  533. 
  534. File: cln.info, Node: Constructing numbers, Next: Elementary functions, Prev: Functions on numbers, Up: Functions on numbers
  535. Constructing numbers
  536. ====================
  537. Here is how to create number objects "from nothing".
  538. * Menu:
  539. * Constructing integers::
  540. * Constructing rational numbers::
  541. * Constructing floating-point numbers::
  542. * Constructing complex numbers::
  543. 
  544. File: cln.info, Node: Constructing integers, Next: Constructing rational numbers, Prev: Constructing numbers, Up: Constructing numbers
  545. Constructing integers
  546. ---------------------
  547. `cl_I' objects are most easily constructed from C integers and from
  548. strings. See *Note Conversions::.
  549. 
  550. File: cln.info, Node: Constructing rational numbers, Next: Constructing floating-point numbers, Prev: Constructing integers, Up: Constructing numbers
  551. Constructing rational numbers
  552. -----------------------------
  553. `cl_RA' objects can be constructed from strings. The syntax for
  554. rational numbers is described in *Note Internal and printed
  555. representation::. Another standard way to produce a rational number is
  556. through application of `operator /' or `recip' on integers.
  557. 
  558. File: cln.info, Node: Constructing floating-point numbers, Next: Constructing complex numbers, Prev: Constructing rational numbers, Up: Constructing numbers
  559. Constructing floating-point numbers
  560. -----------------------------------
  561. `cl_F' objects with low precision are most easily constructed from C
  562. `float' and `double'. See *Note Conversions::.
  563. To construct a `cl_F' with high precision, you can use the conversion
  564. from `const char *', but you have to specify the desired precision
  565. within the string. (See *Note Internal and printed representation::.)
  566. Example:
  567. cl_F e = "0.271828182845904523536028747135266249775724709369996e+1_40";
  568. will set `e' to the given value, with a precision of 40 decimal digits.
  569. The programmatic way to construct a `cl_F' with high precision is
  570. through the `cl_float' conversion function, see *Note Conversion to
  571. floating-point numbers::. For example, to compute `e' to 40 decimal
  572. places, first construct 1.0 to 40 decimal places and then apply the
  573. exponential function:
  574. cl_float_format_t precision = cl_float_format(40);
  575. cl_F e = exp(cl_float(1,precision));
  576. 
  577. File: cln.info, Node: Constructing complex numbers, Prev: Constructing floating-point numbers, Up: Constructing numbers
  578. Constructing complex numbers
  579. ----------------------------
  580. Non-real `cl_N' objects are normally constructed through the function
  581. cl_N complex (const cl_R& realpart, const cl_R& imagpart)
  582. See *Note Elementary complex functions::.
  583. 
  584. File: cln.info, Node: Elementary functions, Next: Elementary rational functions, Prev: Constructing numbers, Up: Functions on numbers
  585. Elementary functions
  586. ====================
  587. Each of the classes `cl_N', `cl_R', `cl_RA', `cl_I', `cl_F', `cl_SF',
  588. `cl_FF', `cl_DF', `cl_LF' defines the following operations:
  589. `TYPE operator + (const TYPE&, const TYPE&)'
  590. Addition.
  591. `TYPE operator - (const TYPE&, const TYPE&)'
  592. Subtraction.
  593. `TYPE operator - (const TYPE&)'
  594. Returns the negative of the argument.
  595. `TYPE plus1 (const TYPE& x)'
  596. Returns `x + 1'.
  597. `TYPE minus1 (const TYPE& x)'
  598. Returns `x - 1'.
  599. `TYPE operator * (const TYPE&, const TYPE&)'
  600. Multiplication.
  601. `TYPE square (const TYPE& x)'
  602. Returns `x * x'.
  603. Each of the classes `cl_N', `cl_R', `cl_RA', `cl_F', `cl_SF', `cl_FF',
  604. `cl_DF', `cl_LF' defines the following operations:
  605. `TYPE operator / (const TYPE&, const TYPE&)'
  606. Division.
  607. `TYPE recip (const TYPE&)'
  608. Returns the reciprocal of the argument.
  609. The class `cl_I' doesn't define a `/' operation because in the C/C++
  610. language this operator, applied to integral types, denotes the `floor'
  611. or `truncate' operation (which one of these, is implementation
  612. dependent). (*Note Rounding functions::.) Instead, `cl_I' defines an
  613. "exact quotient" function:
  614. `cl_I exquo (const cl_I& x, const cl_I& y)'
  615. Checks that `y' divides `x', and returns the quotient `x'/`y'.
  616. The following exponentiation functions are defined:
  617. `cl_I expt_pos (const cl_I& x, const cl_I& y)'
  618. `cl_RA expt_pos (const cl_RA& x, const cl_I& y)'
  619. `y' must be > 0. Returns `x^y'.
  620. `cl_RA expt (const cl_RA& x, const cl_I& y)'
  621. `cl_R expt (const cl_R& x, const cl_I& y)'
  622. `cl_N expt (const cl_N& x, const cl_I& y)'
  623. Returns `x^y'.
  624. Each of the classes `cl_R', `cl_RA', `cl_I', `cl_F', `cl_SF', `cl_FF',
  625. `cl_DF', `cl_LF' defines the following operation:
  626. `TYPE abs (const TYPE& x)'
  627. Returns the absolute value of `x'. This is `x' if `x >= 0', and
  628. `-x' if `x <= 0'.
  629. The class `cl_N' implements this as follows:
  630. `cl_R abs (const cl_N x)'
  631. Returns the absolute value of `x'.
  632. Each of the classes `cl_N', `cl_R', `cl_RA', `cl_I', `cl_F', `cl_SF',
  633. `cl_FF', `cl_DF', `cl_LF' defines the following operation:
  634. `TYPE signum (const TYPE& x)'
  635. Returns the sign of `x', in the same number format as `x'. This
  636. is defined as `x / abs(x)' if `x' is non-zero, and `x' if `x' is
  637. zero. If `x' is real, the value is either 0 or 1 or -1.
  638. 
  639. File: cln.info, Node: Elementary rational functions, Next: Elementary complex functions, Prev: Elementary functions, Up: Functions on numbers
  640. Elementary rational functions
  641. =============================
  642. Each of the classes `cl_RA', `cl_I' defines the following operations:
  643. `cl_I numerator (const TYPE& x)'
  644. Returns the numerator of `x'.
  645. `cl_I denominator (const TYPE& x)'
  646. Returns the denominator of `x'.
  647. The numerator and denominator of a rational number are normalized in
  648. such a way that they have no factor in common and the denominator is
  649. positive.
  650. 
  651. File: cln.info, Node: Elementary complex functions, Next: Comparisons, Prev: Elementary rational functions, Up: Functions on numbers
  652. Elementary complex functions
  653. ============================
  654. The class `cl_N' defines the following operation:
  655. `cl_N complex (const cl_R& a, const cl_R& b)'
  656. Returns the complex number `a+bi', that is, the complex number with
  657. real part `a' and imaginary part `b'.
  658. Each of the classes `cl_N', `cl_R' defines the following operations:
  659. `cl_R realpart (const TYPE& x)'
  660. Returns the real part of `x'.
  661. `cl_R imagpart (const TYPE& x)'
  662. Returns the imaginary part of `x'.
  663. `TYPE conjugate (const TYPE& x)'
  664. Returns the complex conjugate of `x'.
  665. We have the relations
  666. `x = complex(realpart(x), imagpart(x))'
  667. `conjugate(x) = complex(realpart(x), -imagpart(x))'
  668. 
  669. File: cln.info, Node: Comparisons, Next: Rounding functions, Prev: Elementary complex functions, Up: Functions on numbers
  670. Comparisons
  671. ===========
  672. Each of the classes `cl_N', `cl_R', `cl_RA', `cl_I', `cl_F', `cl_SF',
  673. `cl_FF', `cl_DF', `cl_LF' defines the following operations:
  674. `bool operator == (const TYPE&, const TYPE&)'
  675. `bool operator != (const TYPE&, const TYPE&)'
  676. Comparison, as in C and C++.
  677. `uint32 cl_equal_hashcode (const TYPE&)'
  678. Returns a 32-bit hash code that is the same for any two numbers
  679. which are the same according to `=='. This hash code depends on
  680. the number's value, not its type or precision.
  681. `cl_boolean zerop (const TYPE& x)'
  682. Compare against zero: `x == 0'
  683. Each of the classes `cl_R', `cl_RA', `cl_I', `cl_F', `cl_SF', `cl_FF',
  684. `cl_DF', `cl_LF' defines the following operations:
  685. `cl_signean cl_compare (const TYPE& x, const TYPE& y)'
  686. Compares `x' and `y'. Returns +1 if `x'>`y', -1 if `x'<`y', 0 if
  687. `x'=`y'.
  688. `bool operator <= (const TYPE&, const TYPE&)'
  689. `bool operator < (const TYPE&, const TYPE&)'
  690. `bool operator >= (const TYPE&, const TYPE&)'
  691. `bool operator > (const TYPE&, const TYPE&)'
  692. Comparison, as in C and C++.
  693. `cl_boolean minusp (const TYPE& x)'
  694. Compare against zero: `x < 0'
  695. `cl_boolean plusp (const TYPE& x)'
  696. Compare against zero: `x > 0'
  697. `TYPE max (const TYPE& x, const TYPE& y)'
  698. Return the maximum of `x' and `y'.
  699. `TYPE min (const TYPE& x, const TYPE& y)'
  700. Return the minimum of `x' and `y'.
  701. When a floating point number and a rational number are compared, the
  702. float is first converted to a rational number using the function
  703. `rational'. Since a floating point number actually represents an
  704. interval of real numbers, the result might be surprising. For example,
  705. `(cl_F)(cl_R)"1/3" == (cl_R)"1/3"' returns false because there is no
  706. floating point number whose value is exactly `1/3'.
  707. 
  708. File: cln.info, Node: Rounding functions, Next: Roots, Prev: Comparisons, Up: Functions on numbers
  709. Rounding functions
  710. ==================
  711. When a real number is to be converted to an integer, there is no "best"
  712. rounding. The desired rounding function depends on the application.
  713. The Common Lisp and ISO Lisp standards offer four rounding functions:
  714. `floor(x)'
  715. This is the largest integer <=`x'.
  716. `ceiling(x)'
  717. This is the smallest integer >=`x'.
  718. `truncate(x)'
  719. Among the integers between 0 and `x' (inclusive) the one nearest
  720. to `x'.
  721. `round(x)'
  722. The integer nearest to `x'. If `x' is exactly halfway between two
  723. integers, choose the even one.
  724. These functions have different advantages:
  725. `floor' and `ceiling' are translation invariant: `floor(x+n) = floor(x)
  726. + n' and `ceiling(x+n) = ceiling(x) + n' for every `x' and every
  727. integer `n'.
  728. On the other hand, `truncate' and `round' are symmetric: `truncate(-x)
  729. = -truncate(x)' and `round(-x) = -round(x)', and furthermore `round' is
  730. unbiased: on the "average", it rounds down exactly as often as it
  731. rounds up.
  732. The functions are related like this:
  733. `ceiling(m/n) = floor((m+n-1)/n) = floor((m-1)/n)+1' for rational
  734. numbers `m/n' (`m', `n' integers, `n'>0), and
  735. `truncate(x) = sign(x) * floor(abs(x))'
  736. Each of the classes `cl_R', `cl_RA', `cl_F', `cl_SF', `cl_FF', `cl_DF',
  737. `cl_LF' defines the following operations:
  738. `cl_I floor1 (const TYPE& x)'
  739. Returns `floor(x)'.
  740. `cl_I ceiling1 (const TYPE& x)'
  741. Returns `ceiling(x)'.
  742. `cl_I truncate1 (const TYPE& x)'
  743. Returns `truncate(x)'.
  744. `cl_I round1 (const TYPE& x)'
  745. Returns `round(x)'.
  746. Each of the classes `cl_R', `cl_RA', `cl_I', `cl_F', `cl_SF', `cl_FF',
  747. `cl_DF', `cl_LF' defines the following operations:
  748. `cl_I floor1 (const TYPE& x, const TYPE& y)'
  749. Returns `floor(x/y)'.
  750. `cl_I ceiling1 (const TYPE& x, const TYPE& y)'
  751. Returns `ceiling(x/y)'.
  752. `cl_I truncate1 (const TYPE& x, const TYPE& y)'
  753. Returns `truncate(x/y)'.
  754. `cl_I round1 (const TYPE& x, const TYPE& y)'
  755. Returns `round(x/y)'.
  756. These functions are called `floor1', ... here instead of `floor', ...,
  757. because on some systems, system dependent include files define `floor'
  758. and `ceiling' as macros.
  759. In many cases, one needs both the quotient and the remainder of a
  760. division. It is more efficient to compute both at the same time than
  761. to perform two divisions, one for quotient and the next one for the
  762. remainder. The following functions therefore return a structure
  763. containing both the quotient and the remainder. The suffix `2'
  764. indicates the number of "return values". The remainder is defined as
  765. follows:
  766. * for the computation of `quotient = floor(x)', `remainder = x -
  767. quotient',
  768. * for the computation of `quotient = floor(x,y)', `remainder = x -
  769. quotient*y',
  770. and similarly for the other three operations.
  771. Each of the classes `cl_R', `cl_RA', `cl_F', `cl_SF', `cl_FF', `cl_DF',
  772. `cl_LF' defines the following operations:
  773. `struct TYPE_div_t { cl_I quotient; TYPE remainder; };'
  774. `TYPE_div_t floor2 (const TYPE& x)'
  775. `TYPE_div_t ceiling2 (const TYPE& x)'
  776. `TYPE_div_t truncate2 (const TYPE& x)'
  777. `TYPE_div_t round2 (const TYPE& x)'
  778. Each of the classes `cl_R', `cl_RA', `cl_I', `cl_F', `cl_SF', `cl_FF',
  779. `cl_DF', `cl_LF' defines the following operations:
  780. `struct TYPE_div_t { cl_I quotient; TYPE remainder; };'
  781. `TYPE_div_t floor2 (const TYPE& x, const TYPE& y)'
  782. `TYPE_div_t ceiling2 (const TYPE& x, const TYPE& y)'
  783. `TYPE_div_t truncate2 (const TYPE& x, const TYPE& y)'
  784. `TYPE_div_t round2 (const TYPE& x, const TYPE& y)'
  785. Sometimes, one wants the quotient as a floating-point number (of the
  786. same format as the argument, if the argument is a float) instead of as
  787. an integer. The prefix `f' indicates this.
  788. Each of the classes `cl_F', `cl_SF', `cl_FF', `cl_DF', `cl_LF' defines
  789. the following operations:
  790. `TYPE ffloor (const TYPE& x)'
  791. `TYPE fceiling (const TYPE& x)'
  792. `TYPE ftruncate (const TYPE& x)'
  793. `TYPE fround (const TYPE& x)'
  794. and similarly for class `cl_R', but with return type `cl_F'.
  795. The class `cl_R' defines the following operations:
  796. `cl_F ffloor (const TYPE& x, const TYPE& y)'
  797. `cl_F fceiling (const TYPE& x, const TYPE& y)'
  798. `cl_F ftruncate (const TYPE& x, const TYPE& y)'
  799. `cl_F fround (const TYPE& x, const TYPE& y)'
  800. These functions also exist in versions which return both the quotient
  801. and the remainder. The suffix `2' indicates this.
  802. Each of the classes `cl_F', `cl_SF', `cl_FF', `cl_DF', `cl_LF' defines
  803. the following operations:
  804. `struct TYPE_fdiv_t { TYPE quotient; TYPE remainder; };'
  805. `TYPE_fdiv_t ffloor2 (const TYPE& x)'
  806. `TYPE_fdiv_t fceiling2 (const TYPE& x)'
  807. `TYPE_fdiv_t ftruncate2 (const TYPE& x)'
  808. `TYPE_fdiv_t fround2 (const TYPE& x)'
  809. and similarly for class `cl_R', but with quotient type `cl_F'.
  810. The class `cl_R' defines the following operations:
  811. `struct TYPE_fdiv_t { cl_F quotient; cl_R remainder; };'
  812. `TYPE_fdiv_t ffloor2 (const TYPE& x, const TYPE& y)'
  813. `TYPE_fdiv_t fceiling2 (const TYPE& x, const TYPE& y)'
  814. `TYPE_fdiv_t ftruncate2 (const TYPE& x, const TYPE& y)'
  815. `TYPE_fdiv_t fround2 (const TYPE& x, const TYPE& y)'
  816. Other applications need only the remainder of a division. The
  817. remainder of `floor' and `ffloor' is called `mod' (abbreviation of
  818. "modulo"). The remainder `truncate' and `ftruncate' is called `rem'
  819. (abbreviation of "remainder").
  820. * `mod(x,y) = floor2(x,y).remainder = x - floor(x/y)*y'
  821. * `rem(x,y) = truncate2(x,y).remainder = x - truncate(x/y)*y'
  822. If `x' and `y' are both >= 0, `mod(x,y) = rem(x,y) >= 0'. In general,
  823. `mod(x,y)' has the sign of `y' or is zero, and `rem(x,y)' has the sign
  824. of `x' or is zero.
  825. The classes `cl_R', `cl_I' define the following operations:
  826. `TYPE mod (const TYPE& x, const TYPE& y)'
  827. `TYPE rem (const TYPE& x, const TYPE& y)'
  828. 
  829. File: cln.info, Node: Roots, Next: Transcendental functions, Prev: Rounding functions, Up: Functions on numbers
  830. Roots
  831. =====
  832. Each of the classes `cl_R', `cl_F', `cl_SF', `cl_FF', `cl_DF', `cl_LF'
  833. defines the following operation:
  834. `TYPE sqrt (const TYPE& x)'
  835. `x' must be >= 0. This function returns the square root of `x',
  836. normalized to be >= 0. If `x' is the square of a rational number,
  837. `sqrt(x)' will be a rational number, else it will return a
  838. floating-point approximation.
  839. The classes `cl_RA', `cl_I' define the following operation:
  840. `cl_boolean sqrtp (const TYPE& x, TYPE* root)'
  841. This tests whether `x' is a perfect square. If so, it returns true
  842. and the exact square root in `*root', else it returns false.
  843. Furthermore, for integers, similarly:
  844. `cl_boolean isqrt (const TYPE& x, TYPE* root)'
  845. `x' should be >= 0. This function sets `*root' to `floor(sqrt(x))'
  846. and returns the same value as `sqrtp': the boolean value
  847. `(expt(*root,2) == x)'.
  848. For `n'th roots, the classes `cl_RA', `cl_I' define the following
  849. operation:
  850. `cl_boolean rootp (const TYPE& x, const cl_I& n, TYPE* root)'
  851. `x' must be >= 0. `n' must be > 0. This tests whether `x' is an
  852. `n'th power of a rational number. If so, it returns true and the
  853. exact root in `*root', else it returns false.
  854. The only square root function which accepts negative numbers is the one
  855. for class `cl_N':
  856. `cl_N sqrt (const cl_N& z)'
  857. Returns the square root of `z', as defined by the formula `sqrt(z)
  858. = exp(log(z)/2)'. Conversion to a floating-point type or to a
  859. complex number are done if necessary. The range of the result is
  860. the right half plane `realpart(sqrt(z)) >= 0' including the
  861. positive imaginary axis and 0, but excluding the negative
  862. imaginary axis. The result is an exact number only if `z' is an
  863. exact number.
  864. 
  865. File: cln.info, Node: Transcendental functions, Next: Functions on integers, Prev: Roots, Up: Functions on numbers
  866. Transcendental functions
  867. ========================
  868. The transcendental functions return an exact result if the argument is
  869. exact and the result is exact as well. Otherwise they must return
  870. inexact numbers even if the argument is exact. For example, `cos(0) =
  871. 1' returns the rational number `1'.
  872. * Menu:
  873. * Exponential and logarithmic functions::
  874. * Trigonometric functions::
  875. * Hyperbolic functions::
  876. * Euler gamma::
  877. * Riemann zeta::
  878. 
  879. File: cln.info, Node: Exponential and logarithmic functions, Next: Trigonometric functions, Prev: Transcendental functions, Up: Transcendental functions
  880. Exponential and logarithmic functions
  881. -------------------------------------
  882. `cl_R exp (const cl_R& x)'
  883. `cl_N exp (const cl_N& x)'
  884. Returns the exponential function of `x'. This is `e^x' where `e'
  885. is the base of the natural logarithms. The range of the result is
  886. the entire complex plane excluding 0.
  887. `cl_R ln (const cl_R& x)'
  888. `x' must be > 0. Returns the (natural) logarithm of x.
  889. `cl_N log (const cl_N& x)'
  890. Returns the (natural) logarithm of x. If `x' is real and positive,
  891. this is `ln(x)'. In general, `log(x) = log(abs(x)) + i*phase(x)'.
  892. The range of the result is the strip in the complex plane `-pi <
  893. imagpart(log(x)) <= pi'.
  894. `cl_R phase (const cl_N& x)'
  895. Returns the angle part of `x' in its polar representation as a
  896. complex number. That is, `phase(x) =
  897. atan(realpart(x),imagpart(x))'. This is also the imaginary part
  898. of `log(x)'. The range of the result is the interval `-pi <
  899. phase(x) <= pi'. The result will be an exact number only if
  900. `zerop(x)' or if `x' is real and positive.
  901. `cl_R log (const cl_R& a, const cl_R& b)'
  902. `a' and `b' must be > 0. Returns the logarithm of `a' with respect
  903. to base `b'. `log(a,b) = ln(a)/ln(b)'. The result can be exact
  904. only if `a = 1' or if `a' and `b' are both rational.
  905. `cl_N log (const cl_N& a, const cl_N& b)'
  906. Returns the logarithm of `a' with respect to base `b'. `log(a,b)
  907. = log(a)/log(b)'.
  908. `cl_N expt (const cl_N& x, const cl_N& y)'
  909. Exponentiation: Returns `x^y = exp(y*log(x))'.
  910. The constant e = exp(1) = 2.71828... is returned by the following
  911. functions:
  912. `cl_F cl_exp1 (cl_float_format_t f)'
  913. Returns e as a float of format `f'.
  914. `cl_F cl_exp1 (const cl_F& y)'
  915. Returns e in the float format of `y'.
  916. `cl_F cl_exp1 (void)'
  917. Returns e as a float of format `cl_default_float_format'.
  918. 
  919. File: cln.info, Node: Trigonometric functions, Next: Hyperbolic functions, Prev: Exponential and logarithmic functions, Up: Transcendental functions
  920. Trigonometric functions
  921. -----------------------
  922. `cl_R sin (const cl_R& x)'
  923. Returns `sin(x)'. The range of the result is the interval `-1 <=
  924. sin(x) <= 1'.
  925. `cl_N sin (const cl_N& z)'
  926. Returns `sin(z)'. The range of the result is the entire complex
  927. plane.
  928. `cl_R cos (const cl_R& x)'
  929. Returns `cos(x)'. The range of the result is the interval `-1 <=
  930. cos(x) <= 1'.
  931. `cl_N cos (const cl_N& x)'
  932. Returns `cos(z)'. The range of the result is the entire complex
  933. plane.
  934. `struct cl_cos_sin_t { cl_R cos; cl_R sin; };'
  935. `cl_cos_sin_t cl_cos_sin (const cl_R& x)'
  936. Returns both `sin(x)' and `cos(x)'. This is more efficient than
  937. computing them separately. The relation `cos^2 + sin^2 = 1' will
  938. hold only approximately.
  939. `cl_R tan (const cl_R& x)'
  940. `cl_N tan (const cl_N& x)'
  941. Returns `tan(x) = sin(x)/cos(x)'.
  942. `cl_N cis (const cl_R& x)'
  943. `cl_N cis (const cl_N& x)'
  944. Returns `exp(i*x)'. The name `cis' means "cos + i sin", because
  945. `e^(i*x) = cos(x) + i*sin(x)'.
  946. `cl_N asin (const cl_N& z)'
  947. Returns `arcsin(z)'. This is defined as `arcsin(z) =
  948. log(iz+sqrt(1-z^2))/i' and satisfies `arcsin(-z) = -arcsin(z)'.
  949. The range of the result is the strip in the complex domain `-pi/2
  950. <= realpart(arcsin(z)) <= pi/2', excluding the numbers with
  951. `realpart = -pi/2' and `imagpart < 0' and the numbers with
  952. `realpart = pi/2' and `imagpart > 0'.
  953. `cl_N acos (const cl_N& z)'
  954. Returns `arccos(z)'. This is defined as `arccos(z) = pi/2 -
  955. arcsin(z) = log(z+i*sqrt(1-z^2))/i' and satisfies `arccos(-z) = pi
  956. - arccos(z)'. The range of the result is the strip in the complex
  957. domain `0 <= realpart(arcsin(z)) <= pi', excluding the numbers
  958. with `realpart = 0' and `imagpart < 0' and the numbers with
  959. `realpart = pi' and `imagpart > 0'.
  960. `cl_R atan (const cl_R& x, const cl_R& y)'
  961. Returns the angle of the polar representation of the complex number
  962. `x+iy'. This is `atan(y/x)' if `x>0'. The range of the result is
  963. the interval `-pi < atan(x,y) <= pi'. The result will be an exact
  964. number only if `x > 0' and `y' is the exact `0'. WARNING: In
  965. Common Lisp, this function is called as `(atan y x)', with
  966. reversed order of arguments.
  967. `cl_R atan (const cl_R& x)'
  968. Returns `arctan(x)'. This is the same as `atan(1,x)'. The range of
  969. the result is the interval `-pi/2 < atan(x) < pi/2'. The result
  970. will be an exact number only if `x' is the exact `0'.
  971. `cl_N atan (const cl_N& z)'
  972. Returns `arctan(z)'. This is defined as `arctan(z) =
  973. (log(1+iz)-log(1-iz)) / 2i' and satisfies `arctan(-z) =
  974. -arctan(z)'. The range of the result is the strip in the complex
  975. domain `-pi/2 <= realpart(arctan(z)) <= pi/2', excluding the
  976. numbers with `realpart = -pi/2' and `imagpart >= 0' and the numbers
  977. with `realpart = pi/2' and `imagpart <= 0'.
  978. Archimedes' constant pi = 3.14... is returned by the following
  979. functions:
  980. `cl_F cl_pi (cl_float_format_t f)'
  981. Returns pi as a float of format `f'.
  982. `cl_F cl_pi (const cl_F& y)'
  983. Returns pi in the float format of `y'.
  984. `cl_F cl_pi (void)'
  985. Returns pi as a float of format `cl_default_float_format'.
  986. 
  987. File: cln.info, Node: Hyperbolic functions, Next: Euler gamma, Prev: Trigonometric functions, Up: Transcendental functions
  988. Hyperbolic functions
  989. --------------------
  990. `cl_R sinh (const cl_R& x)'
  991. Returns `sinh(x)'.
  992. `cl_N sinh (const cl_N& z)'
  993. Returns `sinh(z)'. The range of the result is the entire complex
  994. plane.
  995. `cl_R cosh (const cl_R& x)'
  996. Returns `cosh(x)'. The range of the result is the interval
  997. `cosh(x) >= 1'.
  998. `cl_N cosh (const cl_N& z)'
  999. Returns `cosh(z)'. The range of the result is the entire complex
  1000. plane.
  1001. `struct cl_cosh_sinh_t { cl_R cosh; cl_R sinh; };'
  1002. `cl_cosh_sinh_t cl_cosh_sinh (const cl_R& x)'
  1003. Returns both `sinh(x)' and `cosh(x)'. This is more efficient than
  1004. computing them separately. The relation `cosh^2 - sinh^2 = 1' will
  1005. hold only approximately.
  1006. `cl_R tanh (const cl_R& x)'
  1007. `cl_N tanh (const cl_N& x)'
  1008. Returns `tanh(x) = sinh(x)/cosh(x)'.
  1009. `cl_N asinh (const cl_N& z)'
  1010. Returns `arsinh(z)'. This is defined as `arsinh(z) =
  1011. log(z+sqrt(1+z^2))' and satisfies `arsinh(-z) = -arsinh(z)'. The
  1012. range of the result is the strip in the complex domain `-pi/2 <=
  1013. imagpart(arsinh(z)) <= pi/2', excluding the numbers with `imagpart
  1014. = -pi/2' and `realpart > 0' and the numbers with `imagpart = pi/2'
  1015. and `realpart < 0'.
  1016. `cl_N acosh (const cl_N& z)'
  1017. Returns `arcosh(z)'. This is defined as `arcosh(z) =
  1018. 2*log(sqrt((z+1)/2)+sqrt((z-1)/2))'. The range of the result is
  1019. the half-strip in the complex domain `-pi < imagpart(arcosh(z)) <=
  1020. pi, realpart(arcosh(z)) >= 0', excluding the numbers with
  1021. `realpart = 0' and `-pi < imagpart < 0'.
  1022. `cl_N atanh (const cl_N& z)'
  1023. Returns `artanh(z)'. This is defined as `artanh(z) =
  1024. (log(1+z)-log(1-z)) / 2' and satisfies `artanh(-z) = -artanh(z)'.
  1025. The range of the result is the strip in the complex domain `-pi/2
  1026. <= imagpart(artanh(z)) <= pi/2', excluding the numbers with
  1027. `imagpart = -pi/2' and `realpart <= 0' and the numbers with
  1028. `imagpart = pi/2' and `realpart >= 0'.
  1029. 
  1030. File: cln.info, Node: Euler gamma, Next: Riemann zeta, Prev: Hyperbolic functions, Up: Transcendental functions
  1031. Euler gamma
  1032. -----------
  1033. Euler's constant C = 0.577... is returned by the following functions:
  1034. `cl_F cl_eulerconst (cl_float_format_t f)'
  1035. Returns Euler's constant as a float of format `f'.
  1036. `cl_F cl_eulerconst (const cl_F& y)'
  1037. Returns Euler's constant in the float format of `y'.
  1038. `cl_F cl_eulerconst (void)'
  1039. Returns Euler's constant as a float of format
  1040. `cl_default_float_format'.
  1041. Catalan's constant G = 0.915... is returned by the following functions:
  1042. `cl_F cl_catalanconst (cl_float_format_t f)'
  1043. Returns Catalan's constant as a float of format `f'.
  1044. `cl_F cl_catalanconst (const cl_F& y)'
  1045. Returns Catalan's constant in the float format of `y'.
  1046. `cl_F cl_catalanconst (void)'
  1047. Returns Catalan's constant as a float of format
  1048. `cl_default_float_format'.
  1049. 
  1050. File: cln.info, Node: Riemann zeta, Prev: Euler gamma, Up: Transcendental functions
  1051. Riemann zeta
  1052. ------------
  1053. Riemann's zeta function at an integral point `s>1' is returned by the
  1054. following functions:
  1055. `cl_F cl_zeta (int s, cl_float_format_t f)'
  1056. Returns Riemann's zeta function at `s' as a float of format `f'.
  1057. `cl_F cl_zeta (int s, const cl_F& y)'
  1058. Returns Riemann's zeta function at `s' in the float format of `y'.
  1059. `cl_F cl_zeta (int s)'
  1060. Returns Riemann's zeta function at `s' as a float of format
  1061. `cl_default_float_format'.
  1062. 
  1063. File: cln.info, Node: Functions on integers, Next: Functions on floating-point numbers, Prev: Transcendental functions, Up: Functions on numbers
  1064. Functions on integers
  1065. =====================
  1066. * Menu:
  1067. * Logical functions::
  1068. * Number theoretic functions::
  1069. * Combinatorial functions::
  1070. 
  1071. File: cln.info, Node: Logical functions, Next: Number theoretic functions, Prev: Functions on integers, Up: Functions on integers
  1072. Logical functions
  1073. -----------------
  1074. Integers, when viewed as in two's complement notation, can be thought as
  1075. infinite bit strings where the bits' values eventually are constant.
  1076. For example,
  1077. 17 = ......00010001
  1078. -6 = ......11111010
  1079. The logical operations view integers as such bit strings and operate on
  1080. each of the bit positions in parallel.
  1081. `cl_I lognot (const cl_I& x)'
  1082. `cl_I operator ~ (const cl_I& x)'
  1083. Logical not, like `~x' in C. This is the same as `-1-x'.
  1084. `cl_I logand (const cl_I& x, const cl_I& y)'
  1085. `cl_I operator & (const cl_I& x, const cl_I& y)'
  1086. Logical and, like `x & y' in C.
  1087. `cl_I logior (const cl_I& x, const cl_I& y)'
  1088. `cl_I operator | (const cl_I& x, const cl_I& y)'
  1089. Logical (inclusive) or, like `x | y' in C.
  1090. `cl_I logxor (const cl_I& x, const cl_I& y)'
  1091. `cl_I operator ^ (const cl_I& x, const cl_I& y)'
  1092. Exclusive or, like `x ^ y' in C.
  1093. `cl_I logeqv (const cl_I& x, const cl_I& y)'
  1094. Bitwise equivalence, like `~(x ^ y)' in C.
  1095. `cl_I lognand (const cl_I& x, const cl_I& y)'
  1096. Bitwise not and, like `~(x & y)' in C.
  1097. `cl_I lognor (const cl_I& x, const cl_I& y)'
  1098. Bitwise not or, like `~(x | y)' in C.
  1099. `cl_I logandc1 (const cl_I& x, const cl_I& y)'
  1100. Logical and, complementing the first argument, like `~x & y' in C.
  1101. `cl_I logandc2 (const cl_I& x, const cl_I& y)'
  1102. Logical and, complementing the second argument, like `x & ~y' in C.
  1103. `cl_I logorc1 (const cl_I& x, const cl_I& y)'
  1104. Logical or, complementing the first argument, like `~x | y' in C.
  1105. `cl_I logorc2 (const cl_I& x, const cl_I& y)'
  1106. Logical or, complementing the second argument, like `x | ~y' in C.
  1107. These operations are all available though the function
  1108. `cl_I boole (cl_boole op, const cl_I& x, const cl_I& y)'
  1109. where `op' must have one of the 16 values (each one stands for a
  1110. function which combines two bits into one bit): `boole_clr',
  1111. `boole_set', `boole_1', `boole_2', `boole_c1', `boole_c2', `boole_and',
  1112. `boole_ior', `boole_xor', `boole_eqv', `boole_nand', `boole_nor',
  1113. `boole_andc1', `boole_andc2', `boole_orc1', `boole_orc2'.
  1114. Other functions that view integers as bit strings:
  1115. `cl_boolean logtest (const cl_I& x, const cl_I& y)'
  1116. Returns true if some bit is set in both `x' and `y', i.e. if
  1117. `logand(x,y) != 0'.
  1118. `cl_boolean logbitp (const cl_I& n, const cl_I& x)'
  1119. Returns true if the `n'th bit (from the right) of `x' is set. Bit
  1120. 0 is the least significant bit.
  1121. `uintL logcount (const cl_I& x)'
  1122. Returns the number of one bits in `x', if `x' >= 0, or the number
  1123. of zero bits in `x', if `x' < 0.
  1124. The following functions operate on intervals of bits in integers. The
  1125. type
  1126. struct cl_byte { uintL size; uintL position; };
  1127. represents the bit interval containing the bits
  1128. `position'...`position+size-1' of an integer. The constructor
  1129. `cl_byte(size,position)' constructs a `cl_byte'.
  1130. `cl_I ldb (const cl_I& n, const cl_byte& b)'
  1131. extracts the bits of `n' described by the bit interval `b' and
  1132. returns them as a nonnegative integer with `b.size' bits.
  1133. `cl_boolean ldb_test (const cl_I& n, const cl_byte& b)'
  1134. Returns true if some bit described by the bit interval `b' is set
  1135. in `n'.
  1136. `cl_I dpb (const cl_I& newbyte, const cl_I& n, const cl_byte& b)'
  1137. Returns `n', with the bits described by the bit interval `b'
  1138. replaced by `newbyte'. Only the lowest `b.size' bits of `newbyte'
  1139. are relevant.
  1140. The functions `ldb' and `dpb' implicitly shift. The following functions
  1141. are their counterparts without shifting:
  1142. `cl_I mask_field (const cl_I& n, const cl_byte& b)'
  1143. returns an integer with the bits described by the bit interval `b'
  1144. copied from the corresponding bits in `n', the other bits zero.
  1145. `cl_I deposit_field (const cl_I& newbyte, const cl_I& n, const cl_byte& b)'
  1146. returns an integer where the bits described by the bit interval `b'
  1147. come from `newbyte' and the other bits come from `n'.
  1148. The following relations hold:
  1149. `ldb (n, b) = mask_field(n, b) >> b.position',
  1150. `dpb (newbyte, n, b) = deposit_field (newbyte << b.position, n,
  1151. b)',
  1152. `deposit_field(newbyte,n,b) = n ^ mask_field(n,b) ^
  1153. mask_field(new_byte,b)'.
  1154. The following operations on integers as bit strings are efficient
  1155. shortcuts for common arithmetic operations:
  1156. `cl_boolean oddp (const cl_I& x)'
  1157. Returns true if the least significant bit of `x' is 1. Equivalent
  1158. to `mod(x,2) != 0'.
  1159. `cl_boolean evenp (const cl_I& x)'
  1160. Returns true if the least significant bit of `x' is 0. Equivalent
  1161. to `mod(x,2) == 0'.
  1162. `cl_I operator << (const cl_I& x, const cl_I& n)'
  1163. Shifts `x' by `n' bits to the left. `n' should be >=0. Equivalent
  1164. to `x * expt(2,n)'.
  1165. `cl_I operator >> (const cl_I& x, const cl_I& n)'
  1166. Shifts `x' by `n' bits to the right. `n' should be >=0. Bits
  1167. shifted out to the right are thrown away. Equivalent to `floor(x
  1168. / expt(2,n))'.
  1169. `cl_I ash (const cl_I& x, const cl_I& y)'
  1170. Shifts `x' by `y' bits to the left (if `y'>=0) or by `-y' bits to
  1171. the right (if `y'<=0). In other words, this returns `floor(x *
  1172. expt(2,y))'.
  1173. `uintL integer_length (const cl_I& x)'
  1174. Returns the number of bits (excluding the sign bit) needed to
  1175. represent `x' in two's complement notation. This is the smallest n
  1176. >= 0 such that -2^n <= x < 2^n. If x > 0, this is the unique n > 0
  1177. such that 2^(n-1) <= x < 2^n.
  1178. `uintL ord2 (const cl_I& x)'
  1179. `x' must be non-zero. This function returns the number of 0 bits
  1180. at the right of `x' in two's complement notation. This is the
  1181. largest n >= 0 such that 2^n divides `x'.
  1182. `uintL power2p (const cl_I& x)'
  1183. `x' must be > 0. This function checks whether `x' is a power of 2.
  1184. If `x' = 2^(n-1), it returns n. Else it returns 0. (See also the
  1185. function `logp'.)
  1186. 
  1187. File: cln.info, Node: Number theoretic functions, Next: Combinatorial functions, Prev: Logical functions, Up: Functions on integers
  1188. Number theoretic functions
  1189. --------------------------
  1190. `uint32 gcd (uint32 a, uint32 b)'
  1191. `cl_I gcd (const cl_I& a, const cl_I& b)'
  1192. This function returns the greatest common divisor of `a' and `b',
  1193. normalized to be >= 0.
  1194. `cl_I xgcd (const cl_I& a, const cl_I& b, cl_I* u, cl_I* v)'
  1195. This function ("extended gcd") returns the greatest common divisor
  1196. `g' of `a' and `b' and at the same time the representation of `g'
  1197. as an integral linear combination of `a' and `b': `u' and `v' with
  1198. `u*a+v*b = g', `g' >= 0. `u' and `v' will be normalized to be of
  1199. smallest possible absolute value, in the following sense: If `a'
  1200. and `b' are non-zero, and `abs(a) != abs(b)', `u' and `v' will
  1201. satisfy the inequalities `abs(u) <= abs(b)/(2*g)', `abs(v) <=
  1202. abs(a)/(2*g)'.
  1203. `cl_I lcm (const cl_I& a, const cl_I& b)'
  1204. This function returns the least common multiple of `a' and `b',
  1205. normalized to be >= 0.
  1206. `cl_boolean logp (const cl_I& a, const cl_I& b, cl_RA* l)'
  1207. `cl_boolean logp (const cl_RA& a, const cl_RA& b, cl_RA* l)'
  1208. `a' must be > 0. `b' must be >0 and != 1. If log(a,b) is rational
  1209. number, this function returns true and sets *l = log(a,b), else it
  1210. returns false.
  1211. 
  1212. File: cln.info, Node: Combinatorial functions, Prev: Number theoretic functions, Up: Functions on integers
  1213. Combinatorial functions
  1214. -----------------------
  1215. `cl_I factorial (uintL n)'
  1216. `n' must be a small integer >= 0. This function returns the
  1217. factorial `n'! = `1*2*...*n'.
  1218. `cl_I doublefactorial (uintL n)'
  1219. `n' must be a small integer >= 0. This function returns the
  1220. doublefactorial `n'!! = `1*3*...*n' or `n'!! = `2*4*...*n',
  1221. respectively.
  1222. `cl_I binomial (uintL n, uintL k)'
  1223. `n' and `k' must be small integers >= 0. This function returns the
  1224. binomial coefficient (`n' choose `k') = `n'! / `k'! `(n-k)'! for
  1225. 0 <= k <= n, 0 else.
  1226. 
  1227. File: cln.info, Node: Functions on floating-point numbers, Next: Conversion functions, Prev: Functions on integers, Up: Functions on numbers
  1228. Functions on floating-point numbers
  1229. ===================================
  1230. Recall that a floating-point number consists of a sign `s', an exponent
  1231. `e' and a mantissa `m'. The value of the number is `(-1)^s * 2^e * m'.
  1232. Each of the classes `cl_F', `cl_SF', `cl_FF', `cl_DF', `cl_LF' defines
  1233. the following operations.
  1234. `TYPE scale_float (const TYPE& x, sintL delta)'
  1235. `TYPE scale_float (const TYPE& x, const cl_I& delta)'
  1236. Returns `x*2^delta'. This is more efficient than an explicit
  1237. multiplication because it copies `x' and modifies the exponent.
  1238. The following functions provide an abstract interface to the underlying
  1239. representation of floating-point numbers.
  1240. `sintL float_exponent (const TYPE& x)'
  1241. Returns the exponent `e' of `x'. For `x = 0.0', this is 0. For
  1242. `x' non-zero, this is the unique integer with `2^(e-1) <= abs(x) <
  1243. 2^e'.
  1244. `sintL float_radix (const TYPE& x)'
  1245. Returns the base of the floating-point representation. This is
  1246. always `2'.
  1247. `TYPE float_sign (const TYPE& x)'
  1248. Returns the sign `s' of `x' as a float. The value is 1 for `x' >=
  1249. 0, -1 for `x' < 0.
  1250. `uintL float_digits (const TYPE& x)'
  1251. Returns the number of mantissa bits in the floating-point
  1252. representation of `x', including the hidden bit. The value only
  1253. depends on the type of `x', not on its value.
  1254. `uintL float_precision (const TYPE& x)'
  1255. Returns the number of significant mantissa bits in the
  1256. floating-point representation of `x'. Since denormalized numbers
  1257. are not supported, this is the same as `float_digits(x)' if `x' is
  1258. non-zero, and 0 if `x' = 0.
  1259. The complete internal representation of a float is encoded in the type
  1260. `cl_decoded_float' (or `cl_decoded_sfloat', `cl_decoded_ffloat',
  1261. `cl_decoded_dfloat', `cl_decoded_lfloat', respectively), defined by
  1262. struct cl_decoded_TYPEfloat {
  1263. TYPE mantissa; cl_I exponent; TYPE sign;
  1264. };
  1265. and returned by the function
  1266. `cl_decoded_TYPEfloat decode_float (const TYPE& x)'
  1267. For `x' non-zero, this returns `(-1)^s', `e', `m' with `x = (-1)^s
  1268. * 2^e * m' and `0.5 <= m < 1.0'. For `x' = 0, it returns
  1269. `(-1)^s'=1, `e'=0, `m'=0. `e' is the same as returned by the
  1270. function `float_exponent'.
  1271. A complete decoding in terms of integers is provided as type
  1272. struct cl_idecoded_float {
  1273. cl_I mantissa; cl_I exponent; cl_I sign;
  1274. };
  1275. by the following function:
  1276. `cl_idecoded_float integer_decode_float (const TYPE& x)'
  1277. For `x' non-zero, this returns `(-1)^s', `e', `m' with `x = (-1)^s
  1278. * 2^e * m' and `m' an integer with `float_digits(x)' bits. For `x'
  1279. = 0, it returns `(-1)^s'=1, `e'=0, `m'=0. WARNING: The exponent
  1280. `e' is not the same as the one returned by the functions
  1281. `decode_float' and `float_exponent'.
  1282. Some other function, implemented only for class `cl_F':
  1283. `cl_F float_sign (const cl_F& x, const cl_F& y)'
  1284. This returns a floating point number whose precision and absolute
  1285. value is that of `y' and whose sign is that of `x'. If `x' is
  1286. zero, it is treated as positive. Same for `y'.
  1287. 
  1288. File: cln.info, Node: Conversion functions, Next: Random number generators, Prev: Functions on floating-point numbers, Up: Functions on numbers
  1289. Conversion functions
  1290. ====================
  1291. * Menu:
  1292. * Conversion to floating-point numbers::
  1293. * Conversion to rational numbers::
  1294. 
  1295. File: cln.info, Node: Conversion to floating-point numbers, Next: Conversion to rational numbers, Prev: Conversion functions, Up: Conversion functions
  1296. Conversion to floating-point numbers
  1297. ------------------------------------
  1298. The type `cl_float_format_t' describes a floating-point format.
  1299. `cl_float_format_t cl_float_format (uintL n)'
  1300. Returns the smallest float format which guarantees at least `n'
  1301. decimal digits in the mantissa (after the decimal point).
  1302. `cl_float_format_t cl_float_format (const cl_F& x)'
  1303. Returns the floating point format of `x'.
  1304. `cl_float_format_t cl_default_float_format'
  1305. Global variable: the default float format used when converting
  1306. rational numbers to floats.
  1307. To convert a real number to a float, each of the types `cl_R', `cl_F',
  1308. `cl_I', `cl_RA', `int', `unsigned int', `float', `double' defines the
  1309. following operations:
  1310. `cl_F cl_float (const TYPE&x, cl_float_format_t f)'
  1311. Returns `x' as a float of format `f'.
  1312. `cl_F cl_float (const TYPE&x, const cl_F& y)'
  1313. Returns `x' in the float format of `y'.
  1314. `cl_F cl_float (const TYPE&x)'
  1315. Returns `x' as a float of format `cl_default_float_format' if it
  1316. is an exact number, or `x' itself if it is already a float.
  1317. Of course, converting a number to a float can lose precision.
  1318. Every floating-point format has some characteristic numbers:
  1319. `cl_F most_positive_float (cl_float_format_t f)'
  1320. Returns the largest (most positive) floating point number in float
  1321. format `f'.
  1322. `cl_F most_negative_float (cl_float_format_t f)'
  1323. Returns the smallest (most negative) floating point number in
  1324. float format `f'.
  1325. `cl_F least_positive_float (cl_float_format_t f)'
  1326. Returns the least positive floating point number (i.e. > 0 but
  1327. closest to 0) in float format `f'.
  1328. `cl_F least_negative_float (cl_float_format_t f)'
  1329. Returns the least negative floating point number (i.e. < 0 but
  1330. closest to 0) in float format `f'.
  1331. `cl_F float_epsilon (cl_float_format_t f)'
  1332. Returns the smallest floating point number e > 0 such that `1+e !=
  1333. 1'.
  1334. `cl_F float_negative_epsilon (cl_float_format_t f)'
  1335. Returns the smallest floating point number e > 0 such that `1-e !=
  1336. 1'.
  1337. 
  1338. File: cln.info, Node: Conversion to rational numbers, Prev: Conversion to floating-point numbers, Up: Conversion functions
  1339. Conversion to rational numbers
  1340. ------------------------------
  1341. Each of the classes `cl_R', `cl_RA', `cl_F' defines the following
  1342. operation:
  1343. `cl_RA rational (const TYPE& x)'
  1344. Returns the value of `x' as an exact number. If `x' is already an
  1345. exact number, this is `x'. If `x' is a floating-point number, the
  1346. value is a rational number whose denominator is a power of 2.
  1347. In order to convert back, say, `(cl_F)(cl_R)"1/3"' to `1/3', there is
  1348. the function
  1349. `cl_RA rationalize (const cl_R& x)'
  1350. If `x' is a floating-point number, it actually represents an
  1351. interval of real numbers, and this function returns the rational
  1352. number with smallest denominator (and smallest numerator, in
  1353. magnitude) which lies in this interval. If `x' is already an
  1354. exact number, this function returns `x'.
  1355. If `x' is any float, one has
  1356. `cl_float(rational(x),x) = x'
  1357. `cl_float(rationalize(x),x) = x'
  1358. 
  1359. File: cln.info, Node: Random number generators, Next: Obfuscating operators, Prev: Conversion functions, Up: Functions on numbers
  1360. Random number generators
  1361. ========================
  1362. A random generator is a machine which produces (pseudo-)random numbers.
  1363. The include file `<cl_random.h>' defines a class `cl_random_state'
  1364. which contains the state of a random generator. If you make a copy of
  1365. the random number generator, the original one and the copy will produce
  1366. the same sequence of random numbers.
  1367. The following functions return (pseudo-)random numbers in different
  1368. formats. Calling one of these modifies the state of the random number
  1369. generator in a complicated but deterministic way.
  1370. The global variable
  1371. cl_random_state cl_default_random_state
  1372. contains a default random number generator. It is used when the
  1373. functions below are called without `cl_random_state' argument.
  1374. `uint32 random32 (cl_random_state& randomstate)'
  1375. `uint32 random32 ()'
  1376. Returns a random unsigned 32-bit number. All bits are equally
  1377. random.
  1378. `cl_I random_I (cl_random_state& randomstate, const cl_I& n)'
  1379. `cl_I random_I (const cl_I& n)'
  1380. `n' must be an integer > 0. This function returns a random integer
  1381. `x' in the range `0 <= x < n'.
  1382. `cl_F random_F (cl_random_state& randomstate, const cl_F& n)'
  1383. `cl_F random_F (const cl_F& n)'
  1384. `n' must be a float > 0. This function returns a random
  1385. floating-point number of the same format as `n' in the range `0 <=
  1386. x < n'.
  1387. `cl_R random_R (cl_random_state& randomstate, const cl_R& n)'
  1388. `cl_R random_R (const cl_R& n)'
  1389. Behaves like `random_I' if `n' is an integer and like `random_F'
  1390. if `n' is a float.
  1391. 
  1392. File: cln.info, Node: Obfuscating operators, Prev: Random number generators, Up: Functions on numbers
  1393. Obfuscating operators
  1394. =====================
  1395. The modifying C/C++ operators `+=', `-=', `*=', `/=', `&=', `|=', `^=',
  1396. `<<=', `>>=' are not available by default because their use tends to
  1397. make programs unreadable. It is trivial to get away without them.
  1398. However, if you feel that you absolutely need these operators to get
  1399. happy, then add
  1400. #define WANT_OBFUSCATING_OPERATORS
  1401. to the beginning of your source files, before the inclusion of any CLN
  1402. include files. This flag will enable the following operators:
  1403. For the classes `cl_N', `cl_R', `cl_RA', `cl_F', `cl_SF', `cl_FF',
  1404. `cl_DF', `cl_LF':
  1405. `TYPE& operator += (TYPE&, const TYPE&)'
  1406. `TYPE& operator -= (TYPE&, const TYPE&)'
  1407. `TYPE& operator *= (TYPE&, const TYPE&)'
  1408. `TYPE& operator /= (TYPE&, const TYPE&)'
  1409. For the class `cl_I':
  1410. `TYPE& operator += (TYPE&, const TYPE&)'
  1411. `TYPE& operator -= (TYPE&, const TYPE&)'
  1412. `TYPE& operator *= (TYPE&, const TYPE&)'
  1413. `TYPE& operator &= (TYPE&, const TYPE&)'
  1414. `TYPE& operator |= (TYPE&, const TYPE&)'
  1415. `TYPE& operator ^= (TYPE&, const TYPE&)'
  1416. `TYPE& operator <<= (TYPE&, const TYPE&)'
  1417. `TYPE& operator >>= (TYPE&, const TYPE&)'
  1418. For the classes `cl_N', `cl_R', `cl_RA', `cl_I', `cl_F', `cl_SF',
  1419. `cl_FF', `cl_DF', `cl_LF':
  1420. `TYPE& operator ++ (TYPE& x)'
  1421. The prefix operator `++x'.
  1422. `void operator ++ (TYPE& x, int)'
  1423. The postfix operator `x++'.
  1424. `TYPE& operator -- (TYPE& x)'
  1425. The prefix operator `--x'.
  1426. `void operator -- (TYPE& x, int)'
  1427. The postfix operator `x--'.
  1428. Note that by using these obfuscating operators, you wouldn't gain
  1429. efficiency: In CLN `x += y;' is exactly the same as `x = x+y;', not
  1430. more efficient.
  1431. 
  1432. File: cln.info, Node: Input/Output, Next: Rings, Prev: Functions on numbers, Up: Top
  1433. Input/Output
  1434. ************
  1435. * Menu:
  1436. * Internal and printed representation::
  1437. * Input functions::
  1438. * Output functions::
  1439. 
  1440. File: cln.info, Node: Internal and printed representation, Next: Input functions, Prev: Input/Output, Up: Input/Output
  1441. Internal and printed representation
  1442. ===================================
  1443. All computations deal with the internal representations of the numbers.
  1444. Every number has an external representation as a sequence of ASCII
  1445. characters. Several external representations may denote the same
  1446. number, for example, "20.0" and "20.000".
  1447. Converting an internal to an external representation is called
  1448. "printing", converting an external to an internal representation is
  1449. called "reading". In CLN, it is always true that conversion of an
  1450. internal to an external representation and then back to an internal
  1451. representation will yield the same internal representation.
  1452. Symbolically: `read(print(x)) == x'. This is called "print-read
  1453. consistency".
  1454. Different types of numbers have different external representations (case
  1455. is insignificant):
  1456. Integers
  1457. External representation: SIGN{DIGIT}+. The reader also accepts the
  1458. Common Lisp syntaxes SIGN{DIGIT}+`.' with a trailing dot for
  1459. decimal integers and the `#NR', `#b', `#o', `#x' prefixes.
  1460. Rational numbers
  1461. External representation: SIGN{DIGIT}+`/'{DIGIT}+. The `#NR',
  1462. `#b', `#o', `#x' prefixes are allowed here as well.
  1463. Floating-point numbers
  1464. External representation: SIGN{DIGIT}*EXPONENT or
  1465. SIGN{DIGIT}*`.'{DIGIT}*EXPONENT or SIGN{DIGIT}*`.'{DIGIT}+. A
  1466. precision specifier of the form _PREC may be appended. There must
  1467. be at least one digit in the non-exponent part. The exponent has
  1468. the syntax EXPMARKER EXPSIGN {DIGIT}+. The exponent marker is
  1469. `s' for short-floats,
  1470. `f' for single-floats,
  1471. `d' for double-floats,
  1472. `L' for long-floats,
  1473. or `e', which denotes a default float format. The precision
  1474. specifying suffix has the syntax _PREC where PREC denotes the
  1475. number of valid mantissa digits (in decimal, excluding leading
  1476. zeroes), cf. also function `cl_float_format'.
  1477. Complex numbers
  1478. External representation:
  1479. In algebraic notation: `REALPART+IMAGPARTi'. Of course, if
  1480. IMAGPART is negative, its printed representation begins with
  1481. a `-', and the `+' between REALPART and IMAGPART may be
  1482. omitted. Note that this notation cannot be used when the
  1483. IMAGPART is rational and the rational number's base is >18,
  1484. because the `i' is then read as a digit.
  1485. In Common Lisp notation: `#C(REALPART IMAGPART)'.
  1486. 
  1487. File: cln.info, Node: Input functions, Next: Output functions, Prev: Internal and printed representation, Up: Input/Output
  1488. Input functions
  1489. ===============
  1490. Including `<cl_io.h>' defines a type `cl_istream', which is the type of
  1491. the first argument to all input functions. Unless you build and use CLN
  1492. with the macro CL_IO_STDIO being defined, `cl_istream' is the same as
  1493. `istream&'.
  1494. The variable
  1495. `cl_istream cl_stdin'
  1496. contains the standard input stream.
  1497. These are the simple input functions:
  1498. `int freadchar (cl_istream stream)'
  1499. Reads a character from `stream'. Returns `cl_EOF' (not a `char'!)
  1500. if the end of stream was encountered or an error occurred.
  1501. `int funreadchar (cl_istream stream, int c)'
  1502. Puts back `c' onto `stream'. `c' must be the result of the last
  1503. `freadchar' operation on `stream'.
  1504. Each of the classes `cl_N', `cl_R', `cl_RA', `cl_I', `cl_F', `cl_SF',
  1505. `cl_FF', `cl_DF', `cl_LF' defines, in `<cl_TYPE_io.h>', the following
  1506. input function:
  1507. `cl_istream operator>> (cl_istream stream, TYPE& result)'
  1508. Reads a number from `stream' and stores it in the `result'.
  1509. The most flexible input functions, defined in `<cl_TYPE_io.h>', are the
  1510. following:
  1511. `cl_N read_complex (cl_istream stream, const cl_read_flags& flags)'
  1512. `cl_R read_real (cl_istream stream, const cl_read_flags& flags)'
  1513. `cl_F read_float (cl_istream stream, const cl_read_flags& flags)'
  1514. `cl_RA read_rational (cl_istream stream, const cl_read_flags& flags)'
  1515. `cl_I read_integer (cl_istream stream, const cl_read_flags& flags)'
  1516. Reads a number from `stream'. The `flags' are parameters which
  1517. affect the input syntax. Whitespace before the number is silently
  1518. skipped.
  1519. `cl_N read_complex (const cl_read_flags& flags, const char * string, const char * string_limit, const char * * end_of_parse)'
  1520. `cl_R read_real (const cl_read_flags& flags, const char * string, const char * string_limit, const char * * end_of_parse)'
  1521. `cl_F read_float (const cl_read_flags& flags, const char * string, const char * string_limit, const char * * end_of_parse)'
  1522. `cl_RA read_rational (const cl_read_flags& flags, const char * string, const char * string_limit, const char * * end_of_parse)'
  1523. `cl_I read_integer (const cl_read_flags& flags, const char * string, const char * string_limit, const char * * end_of_parse)'
  1524. Reads a number from a string in memory. The `flags' are parameters
  1525. which affect the input syntax. The string starts at `string' and
  1526. ends at `string_limit' (exclusive limit). `string_limit' may also
  1527. be `NULL', denoting the entire string, i.e. equivalent to
  1528. `string_limit = string + strlen(string)'. If `end_of_parse' is
  1529. `NULL', the string in memory must contain exactly one number and
  1530. nothing more, else a fatal error will be signalled. If
  1531. `end_of_parse' is not `NULL', `*end_of_parse' will be assigned a
  1532. pointer past the last parsed character (i.e. `string_limit' if
  1533. nothing came after the number). Whitespace is not allowed.
  1534. The structure `cl_read_flags' contains the following fields:
  1535. `cl_read_syntax_t syntax'
  1536. The possible results of the read operation. Possible values are
  1537. `syntax_number', `syntax_real', `syntax_rational',
  1538. `syntax_integer', `syntax_float', `syntax_sfloat',
  1539. `syntax_ffloat', `syntax_dfloat', `syntax_lfloat'.
  1540. `cl_read_lsyntax_t lsyntax'
  1541. Specifies the language-dependent syntax variant for the read
  1542. operation. Possible values are
  1543. `lsyntax_standard'
  1544. accept standard algebraic notation only, no complex numbers,
  1545. `lsyntax_algebraic'
  1546. accept the algebraic notation `X+Yi' for complex numbers,
  1547. `lsyntax_commonlisp'
  1548. accept the `#b', `#o', `#x' syntaxes for binary, octal,
  1549. hexadecimal numbers, `#BASER' for rational numbers in a given
  1550. base, `#c(REALPART IMAGPART)' for complex numbers,
  1551. `lsyntax_all'
  1552. accept all of these extensions.
  1553. `unsigned int rational_base'
  1554. The base in which rational numbers are read.
  1555. `cl_float_format_t float_flags.default_float_format'
  1556. The float format used when reading floats with exponent marker `e'.
  1557. `cl_float_format_t float_flags.default_lfloat_format'
  1558. The float format used when reading floats with exponent marker `l'.
  1559. `cl_boolean float_flags.mantissa_dependent_float_format'
  1560. When this flag is true, floats specified with more digits than
  1561. corresponding to the exponent marker they contain, but without
  1562. _NNN suffix, will get a precision corresponding to their number of
  1563. significant digits.
  1564. 
  1565. File: cln.info, Node: Output functions, Prev: Input functions, Up: Input/Output
  1566. Output functions
  1567. ================
  1568. Including `<cl_io.h>' defines a type `cl_ostream', which is the type of
  1569. the first argument to all output functions. Unless you build and use
  1570. CLN with the macro CL_IO_STDIO being defined, `cl_ostream' is the same
  1571. as `ostream&'.
  1572. The variable
  1573. `cl_ostream cl_stdout'
  1574. contains the standard output stream.
  1575. The variable
  1576. `cl_ostream cl_stderr'
  1577. contains the standard error output stream.
  1578. These are the simple output functions:
  1579. `void fprintchar (cl_ostream stream, char c)'
  1580. Prints the character `x' literally on the `stream'.
  1581. `void fprint (cl_ostream stream, const char * string)'
  1582. Prints the `string' literally on the `stream'.
  1583. `void fprintdecimal (cl_ostream stream, int x)'
  1584. `void fprintdecimal (cl_ostream stream, const cl_I& x)'
  1585. Prints the integer `x' in decimal on the `stream'.
  1586. `void fprintbinary (cl_ostream stream, const cl_I& x)'
  1587. Prints the integer `x' in binary (base 2, without prefix) on the
  1588. `stream'.
  1589. `void fprintoctal (cl_ostream stream, const cl_I& x)'
  1590. Prints the integer `x' in octal (base 8, without prefix) on the
  1591. `stream'.
  1592. `void fprinthexadecimal (cl_ostream stream, const cl_I& x)'
  1593. Prints the integer `x' in hexadecimal (base 16, without prefix) on
  1594. the `stream'.
  1595. Each of the classes `cl_N', `cl_R', `cl_RA', `cl_I', `cl_F', `cl_SF',
  1596. `cl_FF', `cl_DF', `cl_LF' defines, in `<cl_TYPE_io.h>', the following
  1597. output functions:
  1598. `void fprint (cl_ostream stream, const TYPE& x)'
  1599. `cl_ostream operator<< (cl_ostream stream, const TYPE& x)'
  1600. Prints the number `x' on the `stream'. The output may depend on
  1601. the global printer settings in the variable
  1602. `cl_default_print_flags'. The `ostream' flags and settings
  1603. (flags, width and locale) are ignored.
  1604. The most flexible output function, defined in `<cl_TYPE_io.h>', are the
  1605. following:
  1606. void print_complex (cl_ostream stream, const cl_print_flags& flags,
  1607. const cl_N& z);
  1608. void print_real (cl_ostream stream, const cl_print_flags& flags,
  1609. const cl_R& z);
  1610. void print_float (cl_ostream stream, const cl_print_flags& flags,
  1611. const cl_F& z);
  1612. void print_rational (cl_ostream stream, const cl_print_flags& flags,
  1613. const cl_RA& z);
  1614. void print_integer (cl_ostream stream, const cl_print_flags& flags,
  1615. const cl_I& z);
  1616. Prints the number `x' on the `stream'. The `flags' are parameters which
  1617. affect the output.
  1618. The structure type `cl_print_flags' contains the following fields:
  1619. `unsigned int rational_base'
  1620. The base in which rational numbers are printed. Default is `10'.
  1621. `cl_boolean rational_readably'
  1622. If this flag is true, rational numbers are printed with radix
  1623. specifiers in Common Lisp syntax (`#NR' or `#b' or `#o' or `#x'
  1624. prefixes, trailing dot). Default is false.
  1625. `cl_boolean float_readably'
  1626. If this flag is true, type specific exponent markers have
  1627. precedence over 'E'. Default is false.
  1628. `cl_float_format_t default_float_format'
  1629. Floating point numbers of this format will be printed using the
  1630. 'E' exponent marker. Default is `cl_float_format_ffloat'.
  1631. `cl_boolean complex_readably'
  1632. If this flag is true, complex numbers will be printed using the
  1633. Common Lisp syntax `#C(REALPART IMAGPART)'. Default is false.
  1634. `cl_string univpoly_varname'
  1635. Univariate polynomials with no explicit indeterminate name will be
  1636. printed using this variable name. Default is `"x"'.
  1637. The global variable `cl_default_print_flags' contains the default
  1638. values, used by the function `fprint'.
  1639. 
  1640. File: cln.info, Node: Rings, Next: Modular integers, Prev: Input/Output, Up: Top
  1641. Rings
  1642. *****
  1643. CLN has a class of abstract rings.
  1644. Ring
  1645. cl_ring
  1646. <cl_ring.h>
  1647. Rings can be compared for equality:
  1648. `bool operator== (const cl_ring&, const cl_ring&)'
  1649. `bool operator!= (const cl_ring&, const cl_ring&)'
  1650. These compare two rings for equality.
  1651. Given a ring `R', the following members can be used.
  1652. `void R->fprint (cl_ostream stream, const cl_ring_element& x)'
  1653. `cl_boolean R->equal (const cl_ring_element& x, const cl_ring_element& y)'
  1654. `cl_ring_element R->zero ()'
  1655. `cl_boolean R->zerop (const cl_ring_element& x)'
  1656. `cl_ring_element R->plus (const cl_ring_element& x, const cl_ring_element& y)'
  1657. `cl_ring_element R->minus (const cl_ring_element& x, const cl_ring_element& y)'
  1658. `cl_ring_element R->uminus (const cl_ring_element& x)'
  1659. `cl_ring_element R->one ()'
  1660. `cl_ring_element R->canonhom (const cl_I& x)'
  1661. `cl_ring_element R->mul (const cl_ring_element& x, const cl_ring_element& y)'
  1662. `cl_ring_element R->square (const cl_ring_element& x)'
  1663. `cl_ring_element R->expt_pos (const cl_ring_element& x, const cl_I& y)'
  1664. The following rings are built-in.
  1665. `cl_null_ring cl_0_ring'
  1666. The null ring, containing only zero.
  1667. `cl_complex_ring cl_C_ring'
  1668. The ring of complex numbers. This corresponds to the type `cl_N'.
  1669. `cl_real_ring cl_R_ring'
  1670. The ring of real numbers. This corresponds to the type `cl_R'.
  1671. `cl_rational_ring cl_RA_ring'
  1672. The ring of rational numbers. This corresponds to the type `cl_RA'.
  1673. `cl_integer_ring cl_I_ring'
  1674. The ring of integers. This corresponds to the type `cl_I'.
  1675. Type tests can be performed for any of `cl_C_ring', `cl_R_ring',
  1676. `cl_RA_ring', `cl_I_ring':
  1677. `cl_boolean instanceof (const cl_number& x, const cl_number_ring& R)'
  1678. Tests whether the given number is an element of the number ring R.
  1679. 
  1680. File: cln.info, Node: Modular integers, Next: Symbolic data types, Prev: Rings, Up: Top
  1681. Modular integers
  1682. ****************
  1683. * Menu:
  1684. * Modular integer rings::
  1685. * Functions on modular integers::
  1686. 
  1687. File: cln.info, Node: Modular integer rings, Next: Functions on modular integers, Prev: Modular integers, Up: Modular integers
  1688. Modular integer rings
  1689. =====================
  1690. CLN implements modular integers, i.e. integers modulo a fixed integer N.
  1691. The modulus is explicitly part of every modular integer. CLN doesn't
  1692. allow you to (accidentally) mix elements of different modular rings,
  1693. e.g. `(3 mod 4) + (2 mod 5)' will result in a runtime error. (Ideally
  1694. one would imagine a generic data type `cl_MI(N)', but C++ doesn't have
  1695. generic types. So one has to live with runtime checks.)
  1696. The class of modular integer rings is
  1697. Ring
  1698. cl_ring
  1699. <cl_ring.h>
  1700. |
  1701. |
  1702. Modular integer ring
  1703. cl_modint_ring
  1704. <cl_modinteger.h>
  1705. and the class of all modular integers (elements of modular integer
  1706. rings) is
  1707. Modular integer
  1708. cl_MI
  1709. <cl_modinteger.h>
  1710. Modular integer rings are constructed using the function
  1711. `cl_modint_ring cl_find_modint_ring (const cl_I& N)'
  1712. This function returns the modular ring `Z/NZ'. It takes care of
  1713. finding out about special cases of `N', like powers of two and odd
  1714. numbers for which Montgomery multiplication will be a win, and
  1715. precomputes any necessary auxiliary data for computing modulo `N'.
  1716. There is a cache table of rings, indexed by `N' (or, more
  1717. precisely, by `abs(N)'). This ensures that the precomputation
  1718. costs are reduced to a minimum.
  1719. Modular integer rings can be compared for equality:
  1720. `bool operator== (const cl_modint_ring&, const cl_modint_ring&)'
  1721. `bool operator!= (const cl_modint_ring&, const cl_modint_ring&)'
  1722. These compare two modular integer rings for equality. Two
  1723. different calls to `cl_find_modint_ring' with the same argument
  1724. necessarily return the same ring because it is memoized in the
  1725. cache table.
  1726. 
  1727. File: cln.info, Node: Functions on modular integers, Prev: Modular integer rings, Up: Modular integers
  1728. Functions on modular integers
  1729. =============================
  1730. Given a modular integer ring `R', the following members can be used.
  1731. `cl_I R->modulus'
  1732. This is the ring's modulus, normalized to be nonnegative: `abs(N)'.
  1733. `cl_MI R->zero()'
  1734. This returns `0 mod N'.
  1735. `cl_MI R->one()'
  1736. This returns `1 mod N'.
  1737. `cl_MI R->canonhom (const cl_I& x)'
  1738. This returns `x mod N'.
  1739. `cl_I R->retract (const cl_MI& x)'
  1740. This is a partial inverse function to `R->canonhom'. It returns the
  1741. standard representative (`>=0', `<N') of `x'.
  1742. `cl_MI R->random(cl_random_state& randomstate)'
  1743. `cl_MI R->random()'
  1744. This returns a random integer modulo `N'.
  1745. The following operations are defined on modular integers.
  1746. `cl_modint_ring x.ring ()'
  1747. Returns the ring to which the modular integer `x' belongs.
  1748. `cl_MI operator+ (const cl_MI&, const cl_MI&)'
  1749. Returns the sum of two modular integers. One of the arguments may
  1750. also be a plain integer.
  1751. `cl_MI operator- (const cl_MI&, const cl_MI&)'
  1752. Returns the difference of two modular integers. One of the
  1753. arguments may also be a plain integer.
  1754. `cl_MI operator- (const cl_MI&)'
  1755. Returns the negative of a modular integer.
  1756. `cl_MI operator* (const cl_MI&, const cl_MI&)'
  1757. Returns the product of two modular integers. One of the arguments
  1758. may also be a plain integer.
  1759. `cl_MI square (const cl_MI&)'
  1760. Returns the square of a modular integer.
  1761. `cl_MI recip (const cl_MI& x)'
  1762. Returns the reciprocal `x^-1' of a modular integer `x'. `x' must
  1763. be coprime to the modulus, otherwise an error message is issued.
  1764. `cl_MI div (const cl_MI& x, const cl_MI& y)'
  1765. Returns the quotient `x*y^-1' of two modular integers `x', `y'.
  1766. `y' must be coprime to the modulus, otherwise an error message is
  1767. issued.
  1768. `cl_MI expt_pos (const cl_MI& x, const cl_I& y)'
  1769. `y' must be > 0. Returns `x^y'.
  1770. `cl_MI expt (const cl_MI& x, const cl_I& y)'
  1771. Returns `x^y'. If `y' is negative, `x' must be coprime to the
  1772. modulus, else an error message is issued.
  1773. `cl_MI operator<< (const cl_MI& x, const cl_I& y)'
  1774. Returns `x*2^y'.
  1775. `cl_MI operator>> (const cl_MI& x, const cl_I& y)'
  1776. Returns `x*2^-y'. When `y' is positive, the modulus must be odd,
  1777. or an error message is issued.
  1778. `bool operator== (const cl_MI&, const cl_MI&)'
  1779. `bool operator!= (const cl_MI&, const cl_MI&)'
  1780. Compares two modular integers, belonging to the same modular
  1781. integer ring, for equality.
  1782. `cl_boolean zerop (const cl_MI& x)'
  1783. Returns true if `x' is `0 mod N'.
  1784. The following output functions are defined (see also the chapter on
  1785. input/output).
  1786. `void fprint (cl_ostream stream, const cl_MI& x)'
  1787. `cl_ostream operator<< (cl_ostream stream, const cl_MI& x)'
  1788. Prints the modular integer `x' on the `stream'. The output may
  1789. depend on the global printer settings in the variable
  1790. `cl_default_print_flags'.
  1791. 
  1792. File: cln.info, Node: Symbolic data types, Next: Univariate polynomials, Prev: Modular integers, Up: Top
  1793. Symbolic data types
  1794. *******************
  1795. CLN implements two symbolic (non-numeric) data types: strings and
  1796. symbols.
  1797. * Menu:
  1798. * Strings::
  1799. * Symbols::
  1800. 
  1801. File: cln.info, Node: Strings, Next: Symbols, Prev: Symbolic data types, Up: Symbolic data types
  1802. Strings
  1803. =======
  1804. The class
  1805. String
  1806. cl_string
  1807. <cl_string.h>
  1808. implements immutable strings.
  1809. Strings are constructed through the following constructors:
  1810. `cl_string (const char * s)'
  1811. Returns an immutable copy of the (zero-terminated) C string `s'.
  1812. `cl_string (const char * ptr, unsigned long len)'
  1813. Returns an immutable copy of the `len' characters at `ptr[0]',
  1814. ..., `ptr[len-1]'. NUL characters are allowed.
  1815. The following functions are available on strings:
  1816. `operator ='
  1817. Assignment from `cl_string' and `const char *'.
  1818. `s.length()'
  1819. `strlen(s)'
  1820. Returns the length of the string `s'.
  1821. `s[i]'
  1822. Returns the `i'th character of the string `s'. `i' must be in the
  1823. range `0 <= i < s.length()'.
  1824. `bool equal (const cl_string& s1, const cl_string& s2)'
  1825. Compares two strings for equality. One of the arguments may also
  1826. be a plain `const char *'.
  1827. 
  1828. File: cln.info, Node: Symbols, Prev: Strings, Up: Symbolic data types
  1829. Symbols
  1830. =======
  1831. Symbols are uniquified strings: all symbols with the same name are
  1832. shared. This means that comparison of two symbols is fast (effectively
  1833. just a pointer comparison), whereas comparison of two strings must in
  1834. the worst case walk both strings until their end. Symbols are used,
  1835. for example, as tags for properties, as names of variables in
  1836. polynomial rings, etc.
  1837. Symbols are constructed through the following constructor:
  1838. `cl_symbol (const cl_string& s)'
  1839. Looks up or creates a new symbol with a given name.
  1840. The following operations are available on symbols:
  1841. `cl_string (const cl_symbol& sym)'
  1842. Conversion to `cl_string': Returns the string which names the
  1843. symbol `sym'.
  1844. `bool equal (const cl_symbol& sym1, const cl_symbol& sym2)'
  1845. Compares two symbols for equality. This is very fast.
  1846. 
  1847. File: cln.info, Node: Univariate polynomials, Next: Internals, Prev: Symbolic data types, Up: Top
  1848. Univariate polynomials
  1849. **********************
  1850. * Menu:
  1851. * Univariate polynomial rings::
  1852. * Functions on univariate polynomials::
  1853. * Special polynomials::
  1854. 
  1855. File: cln.info, Node: Univariate polynomial rings, Next: Functions on univariate polynomials, Prev: Univariate polynomials, Up: Univariate polynomials
  1856. Univariate polynomial rings
  1857. ===========================
  1858. CLN implements univariate polynomials (polynomials in one variable)
  1859. over an arbitrary ring. The indeterminate variable may be either
  1860. unnamed (and will be printed according to
  1861. `cl_default_print_flags.univpoly_varname', which defaults to `x') or
  1862. carry a given name. The base ring and the indeterminate are explicitly
  1863. part of every polynomial. CLN doesn't allow you to (accidentally) mix
  1864. elements of different polynomial rings, e.g. `(a^2+1) * (b^3-1)' will
  1865. result in a runtime error. (Ideally this should return a multivariate
  1866. polynomial, but they are not yet implemented in CLN.)
  1867. The classes of univariate polynomial rings are
  1868. Ring
  1869. cl_ring
  1870. <cl_ring.h>
  1871. |
  1872. |
  1873. Univariate polynomial ring
  1874. cl_univpoly_ring
  1875. <cl_univpoly.h>
  1876. |
  1877. +----------------+-------------------+
  1878. | | |
  1879. Complex polynomial ring | Modular integer polynomial ring
  1880. cl_univpoly_complex_ring | cl_univpoly_modint_ring
  1881. <cl_univpoly_complex.h> | <cl_univpoly_modint.h>
  1882. |
  1883. +----------------+
  1884. | |
  1885. Real polynomial ring |
  1886. cl_univpoly_real_ring |
  1887. <cl_univpoly_real.h> |
  1888. |
  1889. +----------------+
  1890. | |
  1891. Rational polynomial ring |
  1892. cl_univpoly_rational_ring |
  1893. <cl_univpoly_rational.h> |
  1894. |
  1895. +----------------+
  1896. |
  1897. Integer polynomial ring
  1898. cl_univpoly_integer_ring
  1899. <cl_univpoly_integer.h>
  1900. and the corresponding classes of univariate polynomials are
  1901. Univariate polynomial
  1902. cl_UP
  1903. <cl_univpoly.h>
  1904. |
  1905. +----------------+-------------------+
  1906. | | |
  1907. Complex polynomial | Modular integer polynomial
  1908. cl_UP_N | cl_UP_MI
  1909. <cl_univpoly_complex.h> | <cl_univpoly_modint.h>
  1910. |
  1911. +----------------+
  1912. | |
  1913. Real polynomial |
  1914. cl_UP_R |
  1915. <cl_univpoly_real.h> |
  1916. |
  1917. +----------------+
  1918. | |
  1919. Rational polynomial |
  1920. cl_UP_RA |
  1921. <cl_univpoly_rational.h> |
  1922. |
  1923. +----------------+
  1924. |
  1925. Integer polynomial
  1926. cl_UP_I
  1927. <cl_univpoly_integer.h>
  1928. Univariate polynomial rings are constructed using the functions
  1929. `cl_univpoly_ring cl_find_univpoly_ring (const cl_ring& R)'
  1930. `cl_univpoly_ring cl_find_univpoly_ring (const cl_ring& R, const cl_symbol& varname)'
  1931. This function returns the polynomial ring `R[X]', unnamed or named.
  1932. `R' may be an arbitrary ring. This function takes care of finding
  1933. out about special cases of `R', such as the rings of complex
  1934. numbers, real numbers, rational numbers, integers, or modular
  1935. integer rings. There is a cache table of rings, indexed by `R'
  1936. and `varname'. This ensures that two calls of this function with
  1937. the same arguments will return the same polynomial ring.
  1938. `cl_univpoly_complex_ring cl_find_univpoly_ring (const cl_complex_ring& R)'
  1939. `cl_univpoly_complex_ring cl_find_univpoly_ring (const cl_complex_ring& R, const cl_symbol& varname)'
  1940. `cl_univpoly_real_ring cl_find_univpoly_ring (const cl_real_ring& R)'
  1941. `cl_univpoly_real_ring cl_find_univpoly_ring (const cl_real_ring& R, const cl_symbol& varname)'
  1942. `cl_univpoly_rational_ring cl_find_univpoly_ring (const cl_rational_ring& R)'
  1943. `cl_univpoly_rational_ring cl_find_univpoly_ring (const cl_rational_ring& R, const cl_symbol& varname)'
  1944. `cl_univpoly_integer_ring cl_find_univpoly_ring (const cl_integer_ring& R)'
  1945. `cl_univpoly_integer_ring cl_find_univpoly_ring (const cl_integer_ring& R, const cl_symbol& varname)'
  1946. `cl_univpoly_modint_ring cl_find_univpoly_ring (const cl_modint_ring& R)'
  1947. `cl_univpoly_modint_ring cl_find_univpoly_ring (const cl_modint_ring& R, const cl_symbol& varname)'
  1948. These functions are equivalent to the general
  1949. `cl_find_univpoly_ring', only the return type is more specific,
  1950. according to the base ring's type.
  1951. 
  1952. File: cln.info, Node: Functions on univariate polynomials, Next: Special polynomials, Prev: Univariate polynomial rings, Up: Univariate polynomials
  1953. Functions on univariate polynomials
  1954. ===================================
  1955. Given a univariate polynomial ring `R', the following members can be
  1956. used.
  1957. `cl_ring R->basering()'
  1958. This returns the base ring, as passed to `cl_find_univpoly_ring'.
  1959. `cl_UP R->zero()'
  1960. This returns `0 in R', a polynomial of degree -1.
  1961. `cl_UP R->one()'
  1962. This returns `1 in R', a polynomial of degree <= 0.
  1963. `cl_UP R->canonhom (const cl_I& x)'
  1964. This returns `x in R', a polynomial of degree <= 0.
  1965. `cl_UP R->monomial (const cl_ring_element& x, uintL e)'
  1966. This returns a sparse polynomial: `x * X^e', where `X' is the
  1967. indeterminate.
  1968. `cl_UP R->create (sintL degree)'
  1969. Creates a new polynomial with a given degree. The zero polynomial
  1970. has degree `-1'. After creating the polynomial, you should put in
  1971. the coefficients, using the `set_coeff' member function, and then
  1972. call the `finalize' member function.
  1973. The following are the only destructive operations on univariate
  1974. polynomials.
  1975. `void set_coeff (cl_UP& x, uintL index, const cl_ring_element& y)'
  1976. This changes the coefficient of `X^index' in `x' to be `y'. After
  1977. changing a polynomial and before applying any "normal" operation
  1978. on it, you should call its `finalize' member function.
  1979. `void finalize (cl_UP& x)'
  1980. This function marks the endpoint of destructive modifications of a
  1981. polynomial. It normalizes the internal representation so that
  1982. subsequent computations have less overhead. Doing normal
  1983. computations on unnormalized polynomials may produce wrong results
  1984. or crash the program.
  1985. The following operations are defined on univariate polynomials.
  1986. `cl_univpoly_ring x.ring ()'
  1987. Returns the ring to which the univariate polynomial `x' belongs.
  1988. `cl_UP operator+ (const cl_UP&, const cl_UP&)'
  1989. Returns the sum of two univariate polynomials.
  1990. `cl_UP operator- (const cl_UP&, const cl_UP&)'
  1991. Returns the difference of two univariate polynomials.
  1992. `cl_UP operator- (const cl_UP&)'
  1993. Returns the negative of a univariate polynomial.
  1994. `cl_UP operator* (const cl_UP&, const cl_UP&)'
  1995. Returns the product of two univariate polynomials. One of the
  1996. arguments may also be a plain integer or an element of the base
  1997. ring.
  1998. `cl_UP square (const cl_UP&)'
  1999. Returns the square of a univariate polynomial.
  2000. `cl_UP expt_pos (const cl_UP& x, const cl_I& y)'
  2001. `y' must be > 0. Returns `x^y'.
  2002. `bool operator== (const cl_UP&, const cl_UP&)'
  2003. `bool operator!= (const cl_UP&, const cl_UP&)'
  2004. Compares two univariate polynomials, belonging to the same
  2005. univariate polynomial ring, for equality.
  2006. `cl_boolean zerop (const cl_UP& x)'
  2007. Returns true if `x' is `0 in R'.
  2008. `sintL degree (const cl_UP& x)'
  2009. Returns the degree of the polynomial. The zero polynomial has
  2010. degree `-1'.
  2011. `cl_ring_element coeff (const cl_UP& x, uintL index)'
  2012. Returns the coefficient of `X^index' in the polynomial `x'.
  2013. `cl_ring_element x (const cl_ring_element& y)'
  2014. Evaluation: If `x' is a polynomial and `y' belongs to the base
  2015. ring, then `x(y)' returns the value of the substitution of `y' into
  2016. `x'.
  2017. `cl_UP deriv (const cl_UP& x)'
  2018. Returns the derivative of the polynomial `x' with respect to the
  2019. indeterminate `X'.
  2020. The following output functions are defined (see also the chapter on
  2021. input/output).
  2022. `void fprint (cl_ostream stream, const cl_UP& x)'
  2023. `cl_ostream operator<< (cl_ostream stream, const cl_UP& x)'
  2024. Prints the univariate polynomial `x' on the `stream'. The output
  2025. may depend on the global printer settings in the variable
  2026. `cl_default_print_flags'.
  2027. 
  2028. File: cln.info, Node: Special polynomials, Prev: Functions on univariate polynomials, Up: Univariate polynomials
  2029. Special polynomials
  2030. ===================
  2031. The following functions return special polynomials.
  2032. `cl_UP_I cl_tschebychev (sintL n)'
  2033. Returns the n-th Tchebychev polynomial (n >= 0).
  2034. `cl_UP_I cl_hermite (sintL n)'
  2035. Returns the n-th Hermite polynomial (n >= 0).
  2036. `cl_UP_RA cl_legendre (sintL n)'
  2037. Returns the n-th Legendre polynomial (n >= 0).
  2038. `cl_UP_I cl_laguerre (sintL n)'
  2039. Returns the n-th Laguerre polynomial (n >= 0).
  2040. Information how to derive the differential equation satisfied by each
  2041. of these polynomials from their definition can be found in the
  2042. `doc/polynomial/' directory.
  2043. 
  2044. File: cln.info, Node: Internals, Next: Using the library, Prev: Univariate polynomials, Up: Top
  2045. Internals
  2046. *********
  2047. * Menu:
  2048. * Why C++ ?::
  2049. * Memory efficiency::
  2050. * Speed efficiency::
  2051. * Garbage collection::
  2052. 
  2053. File: cln.info, Node: Why C++ ?, Next: Memory efficiency, Prev: Internals, Up: Internals
  2054. Why C++ ?
  2055. =========
  2056. Using C++ as an implementation language provides
  2057. * Efficiency: It compiles to machine code.
  2058. * Portability: It runs on all platforms supporting a C++ compiler.
  2059. Because of the availability of GNU C++, this includes all
  2060. currently used 32-bit and 64-bit platforms, independently of the
  2061. quality of the vendor's C++ compiler.
  2062. * Type safety: The C++ compilers knows about the number types and
  2063. complains if, for example, you try to assign a float to an integer
  2064. variable. However, a drawback is that C++ doesn't know about
  2065. generic types, hence a restriction like that `operator+ (const
  2066. cl_MI&, const cl_MI&)' requires that both arguments belong to the
  2067. same modular ring cannot be expressed as a compile-time
  2068. information.
  2069. * Algebraic syntax: The elementary operations `+', `-', `*', `=',
  2070. `==', ... can be used in infix notation, which is more convenient
  2071. than Lisp notation `(+ x y)' or C notation `add(x,y,&z)'.
  2072. With these language features, there is no need for two separate
  2073. languages, one for the implementation of the library and one in which
  2074. the library's users can program. This means that a prototype
  2075. implementation of an algorithm can be integrated into the library
  2076. immediately after it has been tested and debugged. No need to rewrite
  2077. it in a low-level language after having prototyped in a high-level
  2078. language.
  2079. 
  2080. File: cln.info, Node: Memory efficiency, Next: Speed efficiency, Prev: Why C++ ?, Up: Internals
  2081. Memory efficiency
  2082. =================
  2083. In order to save memory allocations, CLN implements:
  2084. * Object sharing: An operation like `x+0' returns `x' without copying
  2085. it.
  2086. * Garbage collection: A reference counting mechanism makes sure that
  2087. any number object's storage is freed immediately when the last
  2088. reference to the object is gone.
  2089. * Small integers are represented as immediate values instead of
  2090. pointers to heap allocated storage. This means that integers `>
  2091. -2^29', `< 2^29' don't consume heap memory, unless they were
  2092. explicitly allocated on the heap.
  2093. 
  2094. File: cln.info, Node: Speed efficiency, Next: Garbage collection, Prev: Memory efficiency, Up: Internals
  2095. Speed efficiency
  2096. ================
  2097. Speed efficiency is obtained by the combination of the following tricks
  2098. and algorithms:
  2099. * Small integers, being represented as immediate values, don't
  2100. require memory access, just a couple of instructions for each
  2101. elementary operation.
  2102. * The kernel of CLN has been written in assembly language for some
  2103. CPUs (`i386', `m68k', `sparc', `mips', `arm').
  2104. * On all CPUs, CLN may be configured to use the superefficient
  2105. low-level routines from GNU GMP version 3.
  2106. * For large numbers, CLN uses, instead of the standard `O(N^2)'
  2107. algorithm, the Karatsuba multiplication, which is an `O(N^1.6)'
  2108. algorithm.
  2109. * For very large numbers (more than 12000 decimal digits), CLN uses
  2110. Sch�nhage-Strassen multiplication, which is an asymptotically
  2111. optimal multiplication algorithm.
  2112. * These fast multiplication algorithms also give improvements in the
  2113. speed of division and radix conversion.
  2114. 
  2115. File: cln.info, Node: Garbage collection, Prev: Speed efficiency, Up: Internals
  2116. Garbage collection
  2117. ==================
  2118. All the number classes are reference count classes: They only contain a
  2119. pointer to an object in the heap. Upon construction, assignment and
  2120. destruction of number objects, only the objects' reference count are
  2121. manipulated.
  2122. Memory occupied by number objects are automatically reclaimed as soon as
  2123. their reference count drops to zero.
  2124. For number rings, another strategy is implemented: There is a cache of,
  2125. for example, the modular integer rings. A modular integer ring is
  2126. destroyed only if its reference count dropped to zero and the cache is
  2127. about to be resized. The effect of this strategy is that recently used
  2128. rings remain cached, whereas undue memory consumption through cached
  2129. rings is avoided.
  2130. 
  2131. File: cln.info, Node: Using the library, Next: Customizing, Prev: Internals, Up: Top
  2132. Using the library
  2133. *****************
  2134. For the following discussion, we will assume that you have installed
  2135. the CLN source in `$CLN_DIR' and built it in `$CLN_TARGETDIR'. For
  2136. example, for me it's `CLN_DIR="$HOME/cln"' and
  2137. `CLN_TARGETDIR="$HOME/cln/linuxelf"'. You might define these as
  2138. environment variables, or directly substitute the appropriate values.
  2139. * Menu:
  2140. * Compiler options::
  2141. * Include files::
  2142. * An Example::
  2143. * Debugging support::
  2144. 
  2145. File: cln.info, Node: Compiler options, Next: Include files, Prev: Using the library, Up: Using the library
  2146. Compiler options
  2147. ================
  2148. Until you have installed CLN in a public place, the following options
  2149. are needed:
  2150. When you compile CLN application code, add the flags
  2151. -I$CLN_DIR/include -I$CLN_TARGETDIR/include
  2152. to the C++ compiler's command line (`make' variable CFLAGS or CXXFLAGS).
  2153. When you link CLN application code to form an executable, add the flags
  2154. $CLN_TARGETDIR/src/libcln.a
  2155. to the C/C++ compiler's command line (`make' variable LIBS).
  2156. If you did a `make install', the include files are installed in a
  2157. public directory (normally `/usr/local/include'), hence you don't need
  2158. special flags for compiling. The library has been installed to a public
  2159. directory as well (normally `/usr/local/lib'), hence when linking a CLN
  2160. application it is sufficient to give the flag `-lcln'.
  2161. 
  2162. File: cln.info, Node: Include files, Next: An Example, Prev: Compiler options, Up: Using the library
  2163. Include files
  2164. =============
  2165. Here is a summary of the include files and their contents.
  2166. `<cl_object.h>'
  2167. General definitions, reference counting, garbage collection.
  2168. `<cl_number.h>'
  2169. The class cl_number.
  2170. `<cl_complex.h>'
  2171. Functions for class cl_N, the complex numbers.
  2172. `<cl_real.h>'
  2173. Functions for class cl_R, the real numbers.
  2174. `<cl_float.h>'
  2175. Functions for class cl_F, the floats.
  2176. `<cl_sfloat.h>'
  2177. Functions for class cl_SF, the short-floats.
  2178. `<cl_ffloat.h>'
  2179. Functions for class cl_FF, the single-floats.
  2180. `<cl_dfloat.h>'
  2181. Functions for class cl_DF, the double-floats.
  2182. `<cl_lfloat.h>'
  2183. Functions for class cl_LF, the long-floats.
  2184. `<cl_rational.h>'
  2185. Functions for class cl_RA, the rational numbers.
  2186. `<cl_integer.h>'
  2187. Functions for class cl_I, the integers.
  2188. `<cl_io.h>'
  2189. Input/Output.
  2190. `<cl_complex_io.h>'
  2191. Input/Output for class cl_N, the complex numbers.
  2192. `<cl_real_io.h>'
  2193. Input/Output for class cl_R, the real numbers.
  2194. `<cl_float_io.h>'
  2195. Input/Output for class cl_F, the floats.
  2196. `<cl_sfloat_io.h>'
  2197. Input/Output for class cl_SF, the short-floats.
  2198. `<cl_ffloat_io.h>'
  2199. Input/Output for class cl_FF, the single-floats.
  2200. `<cl_dfloat_io.h>'
  2201. Input/Output for class cl_DF, the double-floats.
  2202. `<cl_lfloat_io.h>'
  2203. Input/Output for class cl_LF, the long-floats.
  2204. `<cl_rational_io.h>'
  2205. Input/Output for class cl_RA, the rational numbers.
  2206. `<cl_integer_io.h>'
  2207. Input/Output for class cl_I, the integers.
  2208. `<cl_input.h>'
  2209. Flags for customizing input operations.
  2210. `<cl_output.h>'
  2211. Flags for customizing output operations.
  2212. `<cl_malloc.h>'
  2213. `cl_malloc_hook', `cl_free_hook'.
  2214. `<cl_abort.h>'
  2215. `cl_abort'.
  2216. `<cl_condition.h>'
  2217. Conditions/exceptions.
  2218. `<cl_string.h>'
  2219. Strings.
  2220. `<cl_symbol.h>'
  2221. Symbols.
  2222. `<cl_proplist.h>'
  2223. Property lists.
  2224. `<cl_ring.h>'
  2225. General rings.
  2226. `<cl_null_ring.h>'
  2227. The null ring.
  2228. `<cl_complex_ring.h>'
  2229. The ring of complex numbers.
  2230. `<cl_real_ring.h>'
  2231. The ring of real numbers.
  2232. `<cl_rational_ring.h>'
  2233. The ring of rational numbers.
  2234. `<cl_integer_ring.h>'
  2235. The ring of integers.
  2236. `<cl_numtheory.h>'
  2237. Number threory functions.
  2238. `<cl_modinteger.h>'
  2239. Modular integers.
  2240. `<cl_V.h>'
  2241. Vectors.
  2242. `<cl_GV.h>'
  2243. General vectors.
  2244. `<cl_GV_number.h>'
  2245. General vectors over cl_number.
  2246. `<cl_GV_complex.h>'
  2247. General vectors over cl_N.
  2248. `<cl_GV_real.h>'
  2249. General vectors over cl_R.
  2250. `<cl_GV_rational.h>'
  2251. General vectors over cl_RA.
  2252. `<cl_GV_integer.h>'
  2253. General vectors over cl_I.
  2254. `<cl_GV_modinteger.h>'
  2255. General vectors of modular integers.
  2256. `<cl_SV.h>'
  2257. Simple vectors.
  2258. `<cl_SV_number.h>'
  2259. Simple vectors over cl_number.
  2260. `<cl_SV_complex.h>'
  2261. Simple vectors over cl_N.
  2262. `<cl_SV_real.h>'
  2263. Simple vectors over cl_R.
  2264. `<cl_SV_rational.h>'
  2265. Simple vectors over cl_RA.
  2266. `<cl_SV_integer.h>'
  2267. Simple vectors over cl_I.
  2268. `<cl_SV_ringelt.h>'
  2269. Simple vectors of general ring elements.
  2270. `<cl_univpoly.h>'
  2271. Univariate polynomials.
  2272. `<cl_univpoly_integer.h>'
  2273. Univariate polynomials over the integers.
  2274. `<cl_univpoly_rational.h>'
  2275. Univariate polynomials over the rational numbers.
  2276. `<cl_univpoly_real.h>'
  2277. Univariate polynomials over the real numbers.
  2278. `<cl_univpoly_complex.h>'
  2279. Univariate polynomials over the complex numbers.
  2280. `<cl_univpoly_modint.h>'
  2281. Univariate polynomials over modular integer rings.
  2282. `<cl_timing.h>'
  2283. Timing facilities.
  2284. `<cln.h>'
  2285. Includes all of the above.
  2286. 
  2287. File: cln.info, Node: An Example, Next: Debugging support, Prev: Include files, Up: Using the library
  2288. An Example
  2289. ==========
  2290. A function which computes the nth Fibonacci number can be written as
  2291. follows.
  2292. #include <cl_integer.h>
  2293. #include <cl_real.h>
  2294. // Returns F_n, computed as the nearest integer to
  2295. // ((1+sqrt(5))/2)^n/sqrt(5). Assume n>=0.
  2296. const cl_I fibonacci (int n)
  2297. {
  2298. // Need a precision of ((1+sqrt(5))/2)^-n.
  2299. cl_float_format_t prec = cl_float_format((int)(0.208987641*n+5));
  2300. cl_R sqrt5 = sqrt(cl_float(5,prec));
  2301. cl_R phi = (1+sqrt5)/2;
  2302. return round1( expt(phi,n)/sqrt5 );
  2303. }
  2304. Let's explain what is going on in detail.
  2305. The include file `<cl_integer.h>' is necessary because the type `cl_I'
  2306. is used in the function, and the include file `<cl_real.h>' is needed
  2307. for the type `cl_R' and the floating point number functions. The order
  2308. of the include files does not matter.
  2309. Then comes the function declaration. The argument is an `int', the
  2310. result an integer. The return type is defined as `const cl_I', not
  2311. simply `cl_I', because that allows the compiler to detect typos like
  2312. `fibonacci(n) = 100'. It would be possible to declare the return type
  2313. as `const cl_R' (real number) or even `const cl_N' (complex number). We
  2314. use the most specialized possible return type because functions which
  2315. call `fibonacci' will be able to profit from the compiler's type
  2316. analysis: Adding two integers is slightly more efficient than adding the
  2317. same objects declared as complex numbers, because it needs less type
  2318. dispatch. Also, when linking to CLN as a non-shared library, this
  2319. minimizes the size of the resulting executable program.
  2320. The result will be computed as expt(phi,n)/sqrt(5), rounded to the
  2321. nearest integer. In order to get a correct result, the absolute error
  2322. should be less than 1/2, i.e. the relative error should be less than
  2323. sqrt(5)/(2*expt(phi,n)). To this end, the first line computes a
  2324. floating point precision for sqrt(5) and phi.
  2325. Then sqrt(5) is computed by first converting the integer 5 to a
  2326. floating point number and than taking the square root. The converse,
  2327. first taking the square root of 5, and then converting to the desired
  2328. precision, would not work in CLN: The square root would be computed to
  2329. a default precision (normally single-float precision), and the
  2330. following conversion could not help about the lacking accuracy. This is
  2331. because CLN is not a symbolic computer algebra system and does not
  2332. represent sqrt(5) in a non-numeric way.
  2333. The type `cl_R' for sqrt5 and, in the following line, phi is the only
  2334. possible choice. You cannot write `cl_F' because the C++ compiler can
  2335. only infer that `cl_float(5,prec)' is a real number. You cannot write
  2336. `cl_N' because a `round1' does not exist for general complex numbers.
  2337. When the function returns, all the local variables in the function are
  2338. automatically reclaimed (garbage collected). Only the result survives
  2339. and gets passed to the caller.
  2340. The file `fibonacci.cc' in the subdirectory `examples' contains this
  2341. implementation together with an even faster algorithm.
  2342. 
  2343. File: cln.info, Node: Debugging support, Prev: An Example, Up: Using the library
  2344. Debugging support
  2345. =================
  2346. When debugging a CLN application with GNU `gdb', two facilities are
  2347. available from the library:
  2348. * The library does type checks, range checks, consistency checks at
  2349. many places. When one of these fails, the function `cl_abort()' is
  2350. called. Its default implementation is to perform an `exit(1)', so
  2351. you won't have a core dump. But for debugging, it is best to set a
  2352. breakpoint at this function:
  2353. (gdb) break cl_abort
  2354. When this breakpoint is hit, look at the stack's backtrace:
  2355. (gdb) where
  2356. * The debugger's normal `print' command doesn't know about CLN's
  2357. types and therefore prints mostly useless hexadecimal addresses.
  2358. CLN offers a function `cl_print', callable from the debugger, for
  2359. printing number objects. In order to get this function, you have
  2360. to define the macro `CL_DEBUG' and then include all the header
  2361. files for which you want `cl_print' debugging support. For example:
  2362. #define CL_DEBUG
  2363. #include <cl_string.h>
  2364. Now, if you have in your program a variable `cl_string s', and
  2365. inspect it under `gdb', the output may look like this:
  2366. (gdb) print s
  2367. $7 = {<cl_gcpointer> = { = {pointer = 0x8055b60, heappointer = 0x8055b60,
  2368. word = 134568800}}, }
  2369. (gdb) call cl_print(s)
  2370. (cl_string) ""
  2371. $8 = 134568800
  2372. Note that the output of `cl_print' goes to the program's error
  2373. output, not to gdb's standard output.
  2374. Note, however, that the above facility does not work with all CLN
  2375. types, only with number objects and similar. Therefore CLN offers
  2376. a member function `debug_print()' on all CLN types. The same macro
  2377. `CL_DEBUG' is needed for this member function to be implemented.
  2378. Under `gdb', you call it like this:
  2379. (gdb) print s
  2380. $7 = {<cl_gcpointer> = { = {pointer = 0x8055b60, heappointer = 0x8055b60,
  2381. word = 134568800}}, }
  2382. (gdb) call s.debug_print()
  2383. (cl_string) ""
  2384. (gdb) define cprint
  2385. >call ($1).debug_print()
  2386. >end
  2387. (gdb) cprint s
  2388. (cl_string) ""
  2389. Unfortunately, this feature does not seem to work under all
  2390. circumstances.
  2391. 
  2392. File: cln.info, Node: Customizing, Next: Index, Prev: Using the library, Up: Top
  2393. Customizing
  2394. ***********
  2395. * Menu:
  2396. * Error handling::
  2397. * Floating-point underflow::
  2398. * Customizing I/O::
  2399. * Customizing the memory allocator::
  2400. 
  2401. File: cln.info, Node: Error handling, Next: Floating-point underflow, Prev: Customizing, Up: Customizing
  2402. Error handling
  2403. ==============
  2404. When a fatal error occurs, an error message is output to the standard
  2405. error output stream, and the function `cl_abort' is called. The default
  2406. version of this function (provided in the library) terminates the
  2407. application. To catch such a fatal error, you need to define the
  2408. function `cl_abort' yourself, with the prototype
  2409. #include <cl_abort.h>
  2410. void cl_abort (void);
  2411. This function must not return control to its caller.
  2412. 
  2413. File: cln.info, Node: Floating-point underflow, Next: Customizing I/O, Prev: Error handling, Up: Customizing
  2414. Floating-point underflow
  2415. ========================
  2416. Floating point underflow denotes the situation when a floating-point
  2417. number is to be created which is so close to `0' that its exponent is
  2418. too low to be represented internally. By default, this causes a fatal
  2419. error. If you set the global variable
  2420. cl_boolean cl_inhibit_floating_point_underflow
  2421. to `cl_true', the error will be inhibited, and a floating-point zero
  2422. will be generated instead. The default value of
  2423. `cl_inhibit_floating_point_underflow' is `cl_false'.
  2424. 
  2425. File: cln.info, Node: Customizing I/O, Next: Customizing the memory allocator, Prev: Floating-point underflow, Up: Customizing
  2426. Customizing I/O
  2427. ===============
  2428. The output of the function `fprint' may be customized by changing the
  2429. value of the global variable `cl_default_print_flags'.
  2430. 
  2431. File: cln.info, Node: Customizing the memory allocator, Prev: Customizing I/O, Up: Customizing
  2432. Customizing the memory allocator
  2433. ================================
  2434. Every memory allocation of CLN is done through the function pointer
  2435. `cl_malloc_hook'. Freeing of this memory is done through the function
  2436. pointer `cl_free_hook'. The default versions of these functions,
  2437. provided in the library, call `malloc' and `free' and check the
  2438. `malloc' result against `NULL'. If you want to provide another memory
  2439. allocator, you need to define the variables `cl_malloc_hook' and
  2440. `cl_free_hook' yourself, like this:
  2441. #include <cl_malloc.h>
  2442. void* (*cl_malloc_hook) (size_t size) = ...;
  2443. void (*cl_free_hook) (void* ptr) = ...;
  2444. The `cl_malloc_hook' function must not return a `NULL' pointer.
  2445. It is not possible to change the memory allocator at runtime, because
  2446. it is already called at program startup by the constructors of some
  2447. global variables.
  2448. 
  2449. File: cln.info, Node: Index, Prev: Customizing, Up: Top
  2450. Index
  2451. *****
  2452. * Menu:
  2453. * abs (): Elementary functions.
  2454. * abstract class: Ordinary number types.
  2455. * acos (): Trigonometric functions.
  2456. * acosh (): Hyperbolic functions.
  2457. * advocacy: Why C++ ?.
  2458. * Archimedes' constant: Trigonometric functions.
  2459. * As()(): Conversions.
  2460. * ash (): Logical functions.
  2461. * asin: Trigonometric functions.
  2462. * asin (): Trigonometric functions.
  2463. * asinh (): Hyperbolic functions.
  2464. * atan: Trigonometric functions.
  2465. * atan (): Trigonometric functions.
  2466. * atanh (): Hyperbolic functions.
  2467. * basering (): Functions on univariate polynomials.
  2468. * binomial (): Combinatorial functions.
  2469. * boole (): Logical functions.
  2470. * boole_1: Logical functions.
  2471. * boole_2: Logical functions.
  2472. * boole_and: Logical functions.
  2473. * boole_andc1: Logical functions.
  2474. * boole_andc2: Logical functions.
  2475. * boole_c1: Logical functions.
  2476. * boole_c2: Logical functions.
  2477. * boole_clr: Logical functions.
  2478. * boole_eqv: Logical functions.
  2479. * boole_nand: Logical functions.
  2480. * boole_nor: Logical functions.
  2481. * boole_orc1: Logical functions.
  2482. * boole_orc2: Logical functions.
  2483. * boole_set: Logical functions.
  2484. * boole_xor: Logical functions.
  2485. * canonhom () <1>: Functions on univariate polynomials.
  2486. * canonhom (): Functions on modular integers.
  2487. * Catalan's constant: Euler gamma.
  2488. * ceiling1 (): Rounding functions.
  2489. * ceiling2 (): Rounding functions.
  2490. * cis (): Trigonometric functions.
  2491. * cl_abort (): Error handling.
  2492. * cl_byte: Logical functions.
  2493. * cl_catalanconst (): Euler gamma.
  2494. * cl_compare (): Comparisons.
  2495. * cl_cos_sin (): Trigonometric functions.
  2496. * cl_cos_sin_t: Trigonometric functions.
  2497. * cl_cosh_sinh (): Hyperbolic functions.
  2498. * cl_cosh_sinh_t: Hyperbolic functions.
  2499. * CL_DEBUG: Debugging support.
  2500. * cl_decoded_dfloat: Functions on floating-point numbers.
  2501. * cl_decoded_ffloat: Functions on floating-point numbers.
  2502. * cl_decoded_float: Functions on floating-point numbers.
  2503. * cl_decoded_lfloat: Functions on floating-point numbers.
  2504. * cl_decoded_sfloat: Functions on floating-point numbers.
  2505. * cl_default_float_format: Conversion to floating-point numbers.
  2506. * cl_default_print_flags: Customizing I/O.
  2507. * cl_default_random_state: Random number generators.
  2508. * cl_DF: Floating-point numbers.
  2509. * cl_DF_fdiv_t: Rounding functions.
  2510. * cl_double_approx (): Conversions.
  2511. * cl_equal_hashcode (): Comparisons.
  2512. * cl_eulerconst (): Euler gamma.
  2513. * cl_F <1>: Floating-point numbers.
  2514. * cl_F: Ordinary number types.
  2515. * cl_F_fdiv_t: Rounding functions.
  2516. * cl_FF: Floating-point numbers.
  2517. * cl_FF_fdiv_t: Rounding functions.
  2518. * cl_find_modint_ring (): Modular integer rings.
  2519. * cl_find_univpoly_ring (): Univariate polynomial rings.
  2520. * cl_float (): Conversion to floating-point numbers.
  2521. * cl_float_approx (): Conversions.
  2522. * cl_float_format (): Conversion to floating-point numbers.
  2523. * cl_float_format_t: Conversion to floating-point numbers.
  2524. * cl_free_hook (): Customizing the memory allocator.
  2525. * cl_hermite (): Special polynomials.
  2526. * cl_I_to_int (): Conversions.
  2527. * cl_I_to_long (): Conversions.
  2528. * cl_I_to_uint (): Conversions.
  2529. * cl_I_to_ulong (): Conversions.
  2530. * cl_idecoded_float: Functions on floating-point numbers.
  2531. * cl_laguerre (): Special polynomials.
  2532. * cl_legendre (): Special polynomials.
  2533. * cl_LF: Floating-point numbers.
  2534. * cl_LF_fdiv_t: Rounding functions.
  2535. * cl_malloc_hook (): Customizing the memory allocator.
  2536. * cl_modint_ring: Modular integer rings.
  2537. * cl_N: Ordinary number types.
  2538. * cl_number: Ordinary number types.
  2539. * cl_pi (): Trigonometric functions.
  2540. * cl_R: Ordinary number types.
  2541. * cl_R_fdiv_t: Rounding functions.
  2542. * cl_RA: Ordinary number types.
  2543. * cl_random_state: Random number generators.
  2544. * cl_SF: Floating-point numbers.
  2545. * cl_SF_fdiv_t: Rounding functions.
  2546. * cl_string (): Strings.
  2547. * cl_symbol (): Symbols.
  2548. * cl_tschebychev (): Special polynomials.
  2549. * cl_zeta (): Riemann zeta.
  2550. * coeff (): Functions on univariate polynomials.
  2551. * comparison: Comparisons.
  2552. * compiler options: Compiler options.
  2553. * complex (): Elementary complex functions.
  2554. * complex number <1>: Complex numbers.
  2555. * complex number: Ordinary number types.
  2556. * conjugate (): Elementary complex functions.
  2557. * conversion <1>: Conversion functions.
  2558. * conversion: Conversions.
  2559. * cos (): Trigonometric functions.
  2560. * cosh (): Hyperbolic functions.
  2561. * create (): Functions on univariate polynomials.
  2562. * customizing: Customizing.
  2563. * debug_print (): Debugging support.
  2564. * debugging: Debugging support.
  2565. * decode_float (): Functions on floating-point numbers.
  2566. * degree (): Functions on univariate polynomials.
  2567. * denominator (): Elementary rational functions.
  2568. * deposit_field (): Logical functions.
  2569. * deriv (): Functions on univariate polynomials.
  2570. * div (): Functions on modular integers.
  2571. * doublefactorial (): Combinatorial functions.
  2572. * dpb (): Logical functions.
  2573. * equal () <1>: Symbols.
  2574. * equal (): Strings.
  2575. * Euler's constant: Euler gamma.
  2576. * evenp (): Logical functions.
  2577. * exact number: Exact numbers.
  2578. * exp (): Exponential and logarithmic functions.
  2579. * exp1 (): Exponential and logarithmic functions.
  2580. * expt () <1>: Functions on modular integers.
  2581. * expt () <2>: Exponential and logarithmic functions.
  2582. * expt (): Elementary functions.
  2583. * expt_pos () <1>: Functions on univariate polynomials.
  2584. * expt_pos () <2>: Functions on modular integers.
  2585. * expt_pos (): Elementary functions.
  2586. * exquo (): Elementary functions.
  2587. * factorial (): Combinatorial functions.
  2588. * fceiling (): Rounding functions.
  2589. * fceiling2 (): Rounding functions.
  2590. * ffloor (): Rounding functions.
  2591. * ffloor2 (): Rounding functions.
  2592. * Fibonacci number: An Example.
  2593. * finalize (): Functions on univariate polynomials.
  2594. * float_digits (): Functions on floating-point numbers.
  2595. * float_epsilon (): Conversion to floating-point numbers.
  2596. * float_exponent (): Functions on floating-point numbers.
  2597. * float_negative_epsilon (): Conversion to floating-point numbers.
  2598. * float_precision (): Functions on floating-point numbers.
  2599. * float_radix (): Functions on floating-point numbers.
  2600. * float_sign (): Functions on floating-point numbers.
  2601. * floating-point number: Floating-point numbers.
  2602. * floor1 (): Rounding functions.
  2603. * floor2 (): Rounding functions.
  2604. * fprint () <1>: Functions on univariate polynomials.
  2605. * fprint (): Functions on modular integers.
  2606. * fround (): Rounding functions.
  2607. * fround2 (): Rounding functions.
  2608. * ftruncate (): Rounding functions.
  2609. * ftruncate2 (): Rounding functions.
  2610. * garbage collection <1>: Garbage collection.
  2611. * garbage collection: Memory efficiency.
  2612. * gcd (): Number theoretic functions.
  2613. * GMP <1>: Using the GNU MP Library.
  2614. * GMP: Introduction.
  2615. * header files: Include files.
  2616. * Hermite polynomial: Special polynomials.
  2617. * imagpart (): Elementary complex functions.
  2618. * include files: Include files.
  2619. * Input/Output: Input/Output.
  2620. * installation: Installing the library.
  2621. * integer: Ordinary number types.
  2622. * integer_decode_float (): Functions on floating-point numbers.
  2623. * integer_length (): Logical functions.
  2624. * isqrt (): Roots.
  2625. * Laguerre polynomial: Special polynomials.
  2626. * lcm (): Number theoretic functions.
  2627. * ldb (): Logical functions.
  2628. * ldb_test (): Logical functions.
  2629. * least_negative_float (): Conversion to floating-point numbers.
  2630. * least_positive_float (): Conversion to floating-point numbers.
  2631. * Legende polynomial: Special polynomials.
  2632. * length (): Strings.
  2633. * ln (): Exponential and logarithmic functions.
  2634. * log (): Exponential and logarithmic functions.
  2635. * logand (): Logical functions.
  2636. * logandc1 (): Logical functions.
  2637. * logandc2 (): Logical functions.
  2638. * logbitp (): Logical functions.
  2639. * logcount (): Logical functions.
  2640. * logeqv (): Logical functions.
  2641. * logior (): Logical functions.
  2642. * lognand (): Logical functions.
  2643. * lognor (): Logical functions.
  2644. * lognot (): Logical functions.
  2645. * logorc1 (): Logical functions.
  2646. * logorc2 (): Logical functions.
  2647. * logp (): Number theoretic functions.
  2648. * logtest (): Logical functions.
  2649. * logxor (): Logical functions.
  2650. * make: Make utility.
  2651. * mask_field (): Logical functions.
  2652. * max (): Comparisons.
  2653. * min (): Comparisons.
  2654. * minus1 (): Elementary functions.
  2655. * minusp (): Comparisons.
  2656. * mod (): Rounding functions.
  2657. * modifying operators: Obfuscating operators.
  2658. * modular integer: Modular integers.
  2659. * modulus: Functions on modular integers.
  2660. * monomial (): Functions on univariate polynomials.
  2661. * Montgomery multiplication: Modular integer rings.
  2662. * most_negative_float (): Conversion to floating-point numbers.
  2663. * most_positive_float (): Conversion to floating-point numbers.
  2664. * numerator (): Elementary rational functions.
  2665. * oddp (): Logical functions.
  2666. * one () <1>: Functions on univariate polynomials.
  2667. * one (): Functions on modular integers.
  2668. * operator != () <1>: Functions on univariate polynomials.
  2669. * operator != () <2>: Functions on modular integers.
  2670. * operator != () <3>: Modular integer rings.
  2671. * operator != (): Comparisons.
  2672. * operator & (): Logical functions.
  2673. * operator &= (): Obfuscating operators.
  2674. * operator () (): Functions on univariate polynomials.
  2675. * operator * () <1>: Functions on univariate polynomials.
  2676. * operator * () <2>: Functions on modular integers.
  2677. * operator * (): Elementary functions.
  2678. * operator *= (): Obfuscating operators.
  2679. * operator + () <1>: Functions on univariate polynomials.
  2680. * operator + () <2>: Functions on modular integers.
  2681. * operator + (): Elementary functions.
  2682. * operator ++ (): Obfuscating operators.
  2683. * operator += (): Obfuscating operators.
  2684. * operator - () <1>: Functions on univariate polynomials.
  2685. * operator - () <2>: Functions on modular integers.
  2686. * operator - (): Elementary functions.
  2687. * operator -- (): Obfuscating operators.
  2688. * operator -= (): Obfuscating operators.
  2689. * operator / (): Elementary functions.
  2690. * operator /= (): Obfuscating operators.
  2691. * operator < (): Comparisons.
  2692. * operator << () <1>: Functions on univariate polynomials.
  2693. * operator << () <2>: Functions on modular integers.
  2694. * operator << (): Logical functions.
  2695. * operator <<= (): Obfuscating operators.
  2696. * operator <= (): Comparisons.
  2697. * operator == () <1>: Functions on univariate polynomials.
  2698. * operator == () <2>: Functions on modular integers.
  2699. * operator == () <3>: Modular integer rings.
  2700. * operator == (): Comparisons.
  2701. * operator > (): Comparisons.
  2702. * operator >= (): Comparisons.
  2703. * operator >> () <1>: Functions on modular integers.
  2704. * operator >> (): Logical functions.
  2705. * operator >>= (): Obfuscating operators.
  2706. * operator [] (): Strings.
  2707. * operator ^ (): Logical functions.
  2708. * operator ^= (): Obfuscating operators.
  2709. * operator | (): Logical functions.
  2710. * operator |= (): Obfuscating operators.
  2711. * operator ~ (): Logical functions.
  2712. * ord2 (): Logical functions.
  2713. * phase (): Exponential and logarithmic functions.
  2714. * pi: Trigonometric functions.
  2715. * plus1 (): Elementary functions.
  2716. * plusp (): Comparisons.
  2717. * polynomial: Univariate polynomials.
  2718. * portability: Why C++ ?.
  2719. * power2p (): Logical functions.
  2720. * printing: Internal and printed representation.
  2721. * random (): Functions on modular integers.
  2722. * random32 (): Random number generators.
  2723. * random_F (): Random number generators.
  2724. * random_I (): Random number generators.
  2725. * random_R (): Random number generators.
  2726. * rational (): Conversion to rational numbers.
  2727. * rational number: Ordinary number types.
  2728. * rationalize (): Conversion to rational numbers.
  2729. * reading: Internal and printed representation.
  2730. * real number: Ordinary number types.
  2731. * realpart (): Elementary complex functions.
  2732. * recip () <1>: Functions on modular integers.
  2733. * recip (): Elementary functions.
  2734. * reference counting: Memory efficiency.
  2735. * rem (): Rounding functions.
  2736. * representation: Internal and printed representation.
  2737. * retract (): Functions on modular integers.
  2738. * Riemann's zeta: Riemann zeta.
  2739. * ring: Modular integer rings.
  2740. * ring () <1>: Functions on univariate polynomials.
  2741. * ring (): Functions on modular integers.
  2742. * rootp (): Roots.
  2743. * round1 (): Rounding functions.
  2744. * round2 (): Rounding functions.
  2745. * rounding: Rounding functions.
  2746. * rounding error: Floating-point numbers.
  2747. * Rubik's cube: Conversions.
  2748. * scale_float (): Functions on floating-point numbers.
  2749. * Sch�nhage-Strassen multiplication <1>: Speed efficiency.
  2750. * Sch�nhage-Strassen multiplication: Introduction.
  2751. * sed: Sed utility.
  2752. * set_coeff (): Functions on univariate polynomials.
  2753. * signum (): Elementary functions.
  2754. * sin (): Trigonometric functions.
  2755. * sinh (): Hyperbolic functions.
  2756. * sqrt (): Roots.
  2757. * sqrtp (): Roots.
  2758. * square () <1>: Functions on univariate polynomials.
  2759. * square () <2>: Functions on modular integers.
  2760. * square (): Elementary functions.
  2761. * string: Strings.
  2762. * strlen (): Strings.
  2763. * symbol: Symbols.
  2764. * symbolic type: Symbolic data types.
  2765. * tan (): Trigonometric functions.
  2766. * tanh (): Hyperbolic functions.
  2767. * The()(): Conversions.
  2768. * transcendental functions: Transcendental functions.
  2769. * truncate1 (): Rounding functions.
  2770. * truncate2 (): Rounding functions.
  2771. * Tschebychev polynomial: Special polynomials.
  2772. * underflow: Floating-point underflow.
  2773. * univariate polynomial: Univariate polynomials.
  2774. * WANT_OBFUSCATING_OPERATORS: Obfuscating operators.
  2775. * xgcd (): Number theoretic functions.
  2776. * zero () <1>: Functions on univariate polynomials.
  2777. * zero (): Functions on modular integers.
  2778. * zerop () <1>: Functions on univariate polynomials.
  2779. * zerop () <2>: Functions on modular integers.
  2780. * zerop (): Comparisons.
  2781. 
  2782. Tag Table:
  2783. Node: Top931
  2784. Node: Introduction3153
  2785. Node: Installation5675
  2786. Node: Prerequisites5969
  2787. Node: C++ compiler6167
  2788. Node: Make utility6882
  2789. Node: Sed utility7068
  2790. Node: Building the library7388
  2791. Node: Using the GNU MP Library10609
  2792. Node: Installing the library11487
  2793. Node: Cleaning up12210
  2794. Node: Ordinary number types12535
  2795. Node: Exact numbers14882
  2796. Node: Floating-point numbers16047
  2797. Node: Complex numbers19626
  2798. Node: Conversions20123
  2799. Node: Functions on numbers23589
  2800. Node: Constructing numbers24292
  2801. Node: Constructing integers24664
  2802. Node: Constructing rational numbers24954
  2803. Node: Constructing floating-point numbers25429
  2804. Node: Constructing complex numbers26549
  2805. Node: Elementary functions26913
  2806. Node: Elementary rational functions29382
  2807. Node: Elementary complex functions29954
  2808. Node: Comparisons30782
  2809. Node: Rounding functions32681
  2810. Node: Roots38458
  2811. Node: Transcendental functions40339
  2812. Node: Exponential and logarithmic functions40895
  2813. Node: Trigonometric functions42912
  2814. Node: Hyperbolic functions46263
  2815. Node: Euler gamma48336
  2816. Node: Riemann zeta49252
  2817. Node: Functions on integers49808
  2818. Node: Logical functions50096
  2819. Node: Number theoretic functions56049
  2820. Node: Combinatorial functions57416
  2821. Node: Functions on floating-point numbers58094
  2822. Node: Conversion functions61325
  2823. Node: Conversion to floating-point numbers61605
  2824. Node: Conversion to rational numbers63828
  2825. Node: Random number generators64882
  2826. Node: Obfuscating operators66556
  2827. Node: Input/Output68286
  2828. Node: Internal and printed representation68496
  2829. Node: Input functions71038
  2830. Node: Output functions75589
  2831. Node: Rings79325
  2832. Node: Modular integers81249
  2833. Node: Modular integer rings81449
  2834. Node: Functions on modular integers83539
  2835. Node: Symbolic data types86549
  2836. Node: Strings86812
  2837. Node: Symbols87877
  2838. Node: Univariate polynomials88779
  2839. Node: Univariate polynomial rings89037
  2840. Node: Functions on univariate polynomials93991
  2841. Node: Special polynomials97772
  2842. Node: Internals98492
  2843. Node: Why C++ ?98706
  2844. Node: Memory efficiency100206
  2845. Node: Speed efficiency100904
  2846. Node: Garbage collection101988
  2847. Node: Using the library102815
  2848. Node: Compiler options103349
  2849. Node: Include files104267
  2850. Node: An Example107908
  2851. Node: Debugging support111058
  2852. Node: Customizing113408
  2853. Node: Error handling113636
  2854. Node: Floating-point underflow114210
  2855. Node: Customizing I/O114849
  2856. Node: Customizing the memory allocator115142
  2857. Node: Index116099
  2858. 
  2859. End Tag Table