]> www.ginac.de Git - cln.git/blob - src/rational/misc/cl_RA_as.cc
Initial revision
[cln.git] / src / rational / misc / cl_RA_as.cc
1 // as_cl_RA().
2
3 // General includes.
4 #include "cl_sysdep.h"
5
6 // Specification.
7 #include "cl_rational.h"
8
9
10 // Implementation.
11
12 #include "cl_N.h"
13
14 // Cf. cl_RA_p in cl_RA_ring.cc.
15 // But here, for better inlining in g++, it is preferrable to finish every
16 // alternative with either "return cl_true;" or "return cl_false;".
17
18 inline cl_boolean cl_RA_p (const cl_number& x)
19 {
20         if (!x.pointer_p())
21                 switch (x.nonpointer_tag()) {
22                 case cl_FN_tag:
23                         return cl_true;
24                 }
25         else
26                 if (x.pointer_type()->flags & cl_class_flags_subclass_rational)
27                         return cl_true;
28         return cl_false;
29 }
30
31 const cl_RA& as_cl_RA (const cl_number& x, const char * filename, int line)
32 {
33         if (cl_RA_p(x)) {
34                 DeclareType(cl_RA,x);
35                 return x;
36         } else
37                 cl_as_error(x,"a rational number",filename,line);
38 }