| 20192 |
bates |
1 |
|
|
|
2 |
The Debian package r-mathlib provides the library of standalone mathematical
|
|
|
3 |
functions from the GNU R sources.
|
|
|
4 |
|
|
|
5 |
Please consult the header file Rmath.h for the full list of available
|
|
|
6 |
functions, and see section "The R API", subection "Using these functions in
|
|
|
7 |
your own code" from the "Writing R Extensions" manual (available in pdf, html
|
|
|
8 |
and info in the r-doc-pdf, r-doc-html and r-doc-info packages, respectively)
|
|
|
9 |
for their usage.
|
|
|
10 |
|
|
|
11 |
A simple example is provided in the file test.c which, on a Debian system,
|
|
|
12 |
can be built as
|
|
|
13 |
$ gcc test.c -o test_mathlib -lRmath -lm
|
|
|
14 |
Running 'ldd test_mathlib' can verify that the library is linked dynamically.
|
|
|
15 |
|
|
|
16 |
The full README for the source directory R-$VERSION/src/nmath/standalone is
|
|
|
17 |
included below; you can safely ignore the part about building this library as
|
|
|
18 |
it provided by the Debian r-mathlib package.
|
|
|
19 |
|
|
|
20 |
-- Dirk Eddelbuettel <edd@debian.org> Thu, 13 Jun 2002 21:27:38 -0500
|
|
|
21 |
|
|
|
22 |
|
|
|
23 |
----- file R-$VERSION/src/nmath/standalone/README below ---------------------
|
|
|
24 |
|
|
|
25 |
If you have not yet made R, under Unix you must first configure R, and
|
|
|
26 |
under Windows you need to set up almost all the tools to make R and
|
|
|
27 |
then run (cd .../src/gnuwin32/fixed; make).
|
|
|
28 |
|
|
|
29 |
|
|
|
30 |
Under Unix, making in this directory will make standalone libraries
|
|
|
31 |
libRmath.a and libRmath.so. `make static' and `make shared' make
|
|
|
32 |
just one of them.
|
|
|
33 |
|
|
|
34 |
Under Windows, use make -f Makefile.win. This makes Rmath.dll with
|
|
|
35 |
import library libRmath.a.
|
|
|
36 |
|
|
|
37 |
NB: certain compilers are unable to do compile-time IEEE-754
|
|
|
38 |
arithmetic and so cannot compile mlutils.c. The known example is
|
|
|
39 |
Sun's cc. Use gcc for mlutils.c (or the whole library).
|
|
|
40 |
|
|
|
41 |
|
|
|
42 |
To use the routines in your own C or C++ programs, include
|
|
|
43 |
|
|
|
44 |
#define MATHLIB_STANDALONE
|
|
|
45 |
#include <Rmath.h>
|
|
|
46 |
|
|
|
47 |
and link against -lRmath. The example file test.c does nothing
|
|
|
48 |
useful, but is provided to test the process. Note that you will
|
|
|
49 |
probably not be able to run it unless you add the directory containing
|
|
|
50 |
libRmath.so to the LD_LIBRARY_PATH.
|
|
|
51 |
|
|
|
52 |
|
|
|
53 |
A little care is needed to use the random-number routines. You will
|
|
|
54 |
need to supply the uniform random number generator
|
|
|
55 |
|
|
|
56 |
double unif_rand(void)
|
|
|
57 |
|
|
|
58 |
or use the one supplied (and with a shared library or DLL you will
|
|
|
59 |
have to use the one supplied, which is the Marsaglia-multicarry with
|
|
|
60 |
an entry point
|
|
|
61 |
|
|
|
62 |
set_seed(unsigned int, unsigned int)
|
|
|
63 |
|
|
|
64 |
to set its seeds).
|
|
|
65 |
|
|
|
66 |
The facilties to change the normal random number generator are
|
|
|
67 |
available through the constant N01_kind. This takes values
|
|
|
68 |
from the enumeration type
|
|
|
69 |
|
|
|
70 |
typedef enum {
|
|
|
71 |
KINDERMAN_RAMAGE,
|
|
|
72 |
AHRENS_DIETER,
|
|
|
73 |
BOX_MULLER
|
|
|
74 |
} N01type;
|
|
|
75 |
|
|
|
76 |
(and USER_NORM is not available).
|
|
|
77 |
|
|
|
78 |
|
|
|
79 |
There is full access to R's handling of NaNs, Inf and -Inf via special
|
|
|
80 |
versions of the macros and functions
|
|
|
81 |
|
|
|
82 |
ISNAN, R_FINITE, R_log, R_pow and R_pow_di
|
|
|
83 |
|
|
|
84 |
and (extern) constants R_PosInf, R_NegInf and NA_REAL. These
|
|
|
85 |
facilities work best on IEEE 754 machines, but are available for all.
|
|
|
86 |
|
|
|
87 |
There is no support for R's notion of missing values, in particular
|
|
|
88 |
not for NA_INTEGER nor the distinction between NA and NaN for doubles.
|
|
|
89 |
|