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.

3719 lines
137 KiB

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