From bb2866ed001b2dd297fa83573ffc10dd95a12c97 Mon Sep 17 00:00:00 2001 From: Alexey Sheplyakov Date: Thu, 12 Dec 2019 08:38:18 +0100 Subject: [PATCH] [PATCH] numeric, ex: added constructors taking `long long`. Fixes MinGW64 build. On 64-bit windows std::size_t is `unsigned long long` (64 bit). However there is no ex constructor taking (unsigned) long long. This patch adds ex and numeric constructors taking `long long` and `unsigned long long`. --- ginac/ex.cpp | 20 +++++++++++++++++++- ginac/ex.h | 16 ++++++++++++++++ ginac/numeric.cpp | 11 +++++++++++ ginac/numeric.h | 2 ++ 4 files changed, 48 insertions(+), 1 deletion(-) diff --git a/ginac/ex.cpp b/ginac/ex.cpp index 73a3ba79..11ae077e 100644 --- a/ginac/ex.cpp +++ b/ginac/ex.cpp @@ -530,7 +530,25 @@ basic & ex::construct_from_ulong(unsigned long i) return dynallocate(i); } } - + +basic & ex::construct_from_longlong(long long i) +{ + if (i >= -12 && i <= 12) { + return construct_from_int(static_cast(i)); + } else { + return dynallocate(i); + } +} + +basic & ex::construct_from_ulonglong(unsigned long long i) +{ + if (i <= 12) { + return construct_from_uint(static_cast(i)); + } else { + return dynallocate(i); + } +} + basic & ex::construct_from_double(double d) { return dynallocate(d); diff --git a/ginac/ex.h b/ginac/ex.h index dd3cfe05..abef5ecf 100644 --- a/ginac/ex.h +++ b/ginac/ex.h @@ -87,6 +87,8 @@ public: ex(unsigned int i); ex(long i); ex(unsigned long i); + ex(long long i); + ex(unsigned long long i); ex(double const d); /** Construct ex from string and a list of symbols. The input grammar is @@ -236,6 +238,8 @@ private: static basic & construct_from_uint(unsigned int i); static basic & construct_from_long(long i); static basic & construct_from_ulong(unsigned long i); + static basic & construct_from_longlong(long long i); + static basic & construct_from_ulonglong(unsigned long long i); static basic & construct_from_double(double d); static ptr construct_from_string_and_lst(const std::string &s, const ex &l); void makewriteable(); @@ -290,6 +294,18 @@ ex::ex(unsigned long i) : bp(construct_from_ulong(i)) GINAC_ASSERT(bp->flags & status_flags::dynallocated); } +inline +ex::ex(long long i) : bp(construct_from_longlong(i)) +{ + GINAC_ASSERT(bp->flags & status_flags::dynallocated); +} + +inline +ex::ex(unsigned long long i) : bp(construct_from_ulonglong(i)) +{ + GINAC_ASSERT(bp->flags & status_flags::dynallocated); +} + inline ex::ex(double const d) : bp(construct_from_double(d)) { diff --git a/ginac/numeric.cpp b/ginac/numeric.cpp index 4cfd7e4a..1f87f422 100644 --- a/ginac/numeric.cpp +++ b/ginac/numeric.cpp @@ -141,6 +141,17 @@ numeric::numeric(unsigned long i) setflag(status_flags::evaluated | status_flags::expanded); } +numeric::numeric(long long i) +{ + value = cln::cl_I(i); + setflag(status_flags::evaluated | status_flags::expanded); +} + +numeric::numeric(unsigned long long i) +{ + value = cln::cl_I(i); + setflag(status_flags::evaluated | status_flags::expanded); +} /** Constructor for rational numerics a/b. * diff --git a/ginac/numeric.h b/ginac/numeric.h index da41bd32..654926d8 100644 --- a/ginac/numeric.h +++ b/ginac/numeric.h @@ -90,6 +90,8 @@ public: numeric(unsigned int i); numeric(long i); numeric(unsigned long i); + numeric(long long i); + numeric(unsigned long long i); numeric(long numer, long denom); numeric(double d); numeric(const char *); -- 2.44.0