]> www.ginac.de Git - cln.git/blob - src/complex/misc/cl_N_as.cc
Finalize CLN 1.3.7 release.
[cln.git] / src / complex / misc / cl_N_as.cc
1 // cl_N_As().
2
3 // General includes.
4 #include "base/cl_sysdep.h"
5
6 // Specification.
7 #include "cln/complex.h"
8
9
10 // Implementation.
11
12 #include "base/cl_N.h"
13 #include "cln/exception.h"
14
15 namespace cln {
16
17 // Cf. cl_N_p in cl_C_ring.cc.
18 // But here, for better inlining in g++, it is preferrable to finish every
19 // alternative with either "return true;" or "return false;".
20
21 inline bool cl_N_p (const cl_number& x)
22 {
23         if (!x.pointer_p())
24                 switch (x.nonpointer_tag()) {
25                 case cl_FN_tag:
26                 case cl_SF_tag:
27                 #if defined(CL_WIDE_POINTERS)
28                 case cl_FF_tag:
29                 #endif
30                         return true;
31                 }
32         else
33                 if (x.pointer_type()->flags & cl_class_flags_subclass_complex)
34                         return true;
35         return false;
36 }
37
38 const cl_N& cl_N_As (const cl_number& x, const char * filename, int line)
39 {
40         if (cl_N_p(x)) {
41                 DeclareType(cl_N,x);
42                 return x;
43         } else
44                 throw as_exception(x,"a number",filename,line);
45 }
46
47 }  // namespace cln