7 #ifdef WITH_SYMENGINE_THREAD_SAFE
16 : name_{name} {SYMENGINE_ASSIGN_TYPEID()}
20 hash_t seed = SYMENGINE_CONSTANT;
21 hash_combine<std::string>(seed,
name_);
27 if (is_a<Constant>(o))
28 return name_ == down_cast<const Constant &>(o).name_;
34 SYMENGINE_ASSERT(is_a<Constant>(o))
35 const Constant &s = down_cast<const Constant &>(o);
41 #define sqrt_(arg) pow(arg, div(one, i2))
43 #ifdef WITH_SYMENGINE_THREAD_SAFE
46 static int nifty_counter;
52 #define DEFINE_CONSTANTS \
53 DEFINE_CONSTANT(Integer, zero, integer(0)); \
54 DEFINE_CONSTANT(Integer, one, integer(1)); \
55 DEFINE_CONSTANT(Integer, minus_one, integer(-1)); \
56 DEFINE_CONSTANT(Integer, two, integer(2)); \
57 DEFINE_CONSTANT(Number, I, Complex::from_two_nums(*zero, *one)); \
58 DEFINE_CONSTANT(Constant, pi, constant("pi")); \
59 DEFINE_CONSTANT(Constant, E, constant("E")); \
60 DEFINE_CONSTANT(Constant, EulerGamma, constant("EulerGamma")); \
61 DEFINE_CONSTANT(Constant, Catalan, constant("Catalan")); \
62 DEFINE_CONSTANT(Constant, GoldenRatio, constant("GoldenRatio")); \
63 DEFINE_CONSTANT(Infty, Inf, Infty::from_int(1)); \
64 DEFINE_CONSTANT(Infty, NegInf, Infty::from_int(-1)); \
65 DEFINE_CONSTANT(Infty, ComplexInf, Infty::from_int(0)); \
66 DEFINE_CONSTANT(NaN, Nan, make_rcp<NaN>()); \
67 DEFINE_CONSTANT(Basic, i2, integer(2)); \
68 DEFINE_CONSTANT(Basic, i3, integer(3)); \
69 DEFINE_CONSTANT(Basic, i5, integer(5)); \
70 DEFINE_CONSTANT(Basic, im2, integer(-2)); \
71 DEFINE_CONSTANT(Basic, im3, integer(-3)); \
72 DEFINE_CONSTANT(Basic, im5, integer(-5)); \
73 DEFINE_CONSTANT(Basic, sq3, sqrt_(i3)); \
74 DEFINE_CONSTANT(Basic, sq2, sqrt_(i2)); \
75 DEFINE_CONSTANT(Basic, sq5, sqrt_(i5)); \
76 DEFINE_CONSTANT(Basic, C0, div(sub(sq3, one), mul(i2, sq2))); \
77 DEFINE_CONSTANT(Basic, C1, div(one, i2)); \
78 DEFINE_CONSTANT(Basic, C2, div(sq2, i2)); \
79 DEFINE_CONSTANT(Basic, C3, div(sq3, i2)); \
80 DEFINE_CONSTANT(Basic, C4, div(add(sq3, one), mul(i2, sq2))); \
81 DEFINE_CONSTANT(Basic, C5, div(sqrt_(sub(i5, sqrt_(i5))), integer(8))); \
82 DEFINE_CONSTANT(Basic, C6, div(sub(sqrt_(i5), one), integer(4))); \
83 DEFINE_CONSTANT(Basic, mC0, mul(minus_one, C0)); \
84 DEFINE_CONSTANT(Basic, mC1, mul(minus_one, C1)); \
85 DEFINE_CONSTANT(Basic, mC2, mul(minus_one, C2)); \
86 DEFINE_CONSTANT(Basic, mC3, mul(minus_one, C3)); \
87 DEFINE_CONSTANT(Basic, mC4, mul(minus_one, C4)); \
88 DEFINE_CONSTANT(Basic, mC5, mul(minus_one, C5)); \
89 DEFINE_CONSTANT(Basic, mC6, mul(minus_one, C6)); \
90 DEFINE_CONSTANT(BooleanAtom, boolTrue, make_rcp<BooleanAtom>(true)); \
91 DEFINE_CONSTANT(BooleanAtom, boolFalse, make_rcp<BooleanAtom>(false));
93 #if __cplusplus >= 201703L
96 alignas(T) std::byte data[
sizeof(T)];
105 #define DEFINE_CONSTANT(t, n, d) \
106 static storage_for<RCP<const t>> n##_buf; \
107 RCP<const t> &n = reinterpret_cast<RCP<const t> &>(n##_buf);
110 #undef DEFINE_CONSTANT
112 ConstantInitializer::ConstantInitializer()
114 if (nifty_counter++ == 0) {
115 #define DEFINE_CONSTANT(t, n, d) new (&n) RCP<const t>(d);
117 #undef DEFINE_CONSTANT
121 ConstantInitializer::~ConstantInitializer()
123 if (--nifty_counter == 0) {
124 #define DEFINE_CONSTANT(t, n, d) n.~RCP();
126 #undef DEFINE_CONSTANT
Classes and functions relating to the binary operation of addition.
The lowest unit of symbolic representation.
hash_t __hash__() const override
std::string name_
name of Constant
Constant(const std::string &name)
Constant Constructor.
int compare(const Basic &o) const override
bool __eq__(const Basic &o) const override
Main namespace for SymEngine package.