mp_wrapper.cpp
1 #include <symengine/mp_wrapper.h>
2 #include <stdlib.h>
3 #include <cstring>
4 
5 namespace SymEngine
6 {
7 #if SYMENGINE_INTEGER_CLASS == SYMENGINE_FLINT
8 std::ostream &operator<<(std::ostream &os, const fmpz_wrapper &f)
9 {
10  void (*freefunc)(void *, size_t);
11  mp_get_memory_functions(NULL, NULL, &freefunc);
12  char *c = fmpz_get_str(NULL, 10, f.get_fmpz_t());
13  os << std::string(c);
14  freefunc(c, strlen(c) + 1);
15  return os;
16 }
17 
18 std::ostream &operator<<(std::ostream &os, const fmpq_wrapper &f)
19 {
20  void (*freefunc)(void *, size_t);
21  mp_get_memory_functions(NULL, NULL, &freefunc);
22  char *c = fmpq_get_str(NULL, 10, f.get_fmpq_t());
23  os << std::string(c);
24  freefunc(c, strlen(c) + 1);
25  return os;
26 }
27 #elif SYMENGINE_INTEGER_CLASS == SYMENGINE_GMP
28 
29 std::ostream &operator<<(std::ostream &os, const mpz_wrapper &f)
30 {
31  void (*freefunc)(void *, size_t);
32  mp_get_memory_functions(NULL, NULL, &freefunc);
33  char *c = mpz_get_str(NULL, 10, f.get_mpz_t());
34  os << std::string(c);
35  freefunc(c, strlen(c) + 1);
36  return os;
37 }
38 
39 std::ostream &operator<<(std::ostream &os, const mpq_wrapper &f)
40 {
41  void (*freefunc)(void *, size_t);
42  mp_get_memory_functions(NULL, NULL, &freefunc);
43  char *c = mpq_get_str(NULL, 10, f.get_mpq_t());
44  os << std::string(c);
45  freefunc(c, strlen(c) + 1);
46  return os;
47 }
48 #endif
49 
50 } // namespace SymEngine
Main namespace for SymEngine package.
Definition: add.cpp:19
std::ostream & operator<<(std::ostream &out, const SymEngine::Basic &p)
<< Operator
Definition: basic-inl.h:53
T strlen(T... args)