]> www.ginac.de Git - cln.git/blob - src/real/random/cl_R_random.cc
f81143ca07ad9c5b8e4e444fc423e8a0de766d51
[cln.git] / src / real / random / cl_R_random.cc
1 // random_R().
2
3 // General includes.
4 #include "cl_sysdep.h"
5
6 // Specification.
7 #include "cln/real.h"
8
9
10 // Implementation.
11
12 #include "cl_R.h"
13 #include "cl_RA.h"
14 #include "cln/io.h"
15 #include "cln/real_io.h"
16 #include "cln/exception.h"
17 #include <sstream>
18
19 namespace cln {
20
21 const cl_R random_R (random_state& r, const cl_R& n)
22 {
23         // n muß eine reelle Zahl sein, >0 und Float oder Integer
24         if (plusp(n)) {
25                 if (floatp(n)) {
26                         DeclareType(cl_F,n);
27                         return random_F(r,n);
28                 } else {
29                         DeclareType(cl_RA,n);
30                         if (integerp(n)) {
31                                 DeclareType(cl_I,n);
32                                 return random_I(r,n);
33                         }
34                 }
35         }
36         std::ostringstream buf;
37         fprint(buf, "random: argument should be positive and an integer or float: ");
38         fprint(buf, n);
39         throw runtime_exception(buf.str());
40 }
41
42 }  // namespace cln