From 4309a30dfeed2913b06ee4e699daae678764c528 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Thu, 8 Dec 2016 14:51:49 +0100 Subject: Add opBinary for the other math operations on Integer --- .travis | 19 ------------------- .travis.yml | 19 +++++++++++++++++++ source/tanya/math/mp.d | 23 ++++++++++++++--------- 3 files changed, 33 insertions(+), 28 deletions(-) delete mode 100644 .travis create mode 100644 .travis.yml diff --git a/.travis b/.travis deleted file mode 100644 index 07d22bf..0000000 --- a/.travis +++ /dev/null @@ -1,19 +0,0 @@ -sudo: false - -os: - - linux - - osx - - windows - -language: d - -d: - - dmd-2.072.1 - -env: - matrix: - - ARCH=x86 - - ARCH=x86_64 - -script: - - dub test --arch=$ARCH diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..07d22bf --- /dev/null +++ b/.travis.yml @@ -0,0 +1,19 @@ +sudo: false + +os: + - linux + - osx + - windows + +language: d + +d: + - dmd-2.072.1 + +env: + matrix: + - ARCH=x86 + - ARCH=x86_64 + +script: + - dub test --arch=$ARCH diff --git a/source/tanya/math/mp.d b/source/tanya/math/mp.d index 2d06f8a..5c89c6b 100644 --- a/source/tanya/math/mp.d +++ b/source/tanya/math/mp.d @@ -993,18 +993,12 @@ struct Integer /// Ditto. Integer opBinary(string op)(in size_t n) nothrow @safe @nogc - if (op == "<<" || op == ">>") + if (op == "<<" || op == ">>" || op == "+" || op == "-" || op == "/" + || op == "*" || op == "^^" || op == "%") { checkAllocator(); auto ret = Integer(this, allocator); - static if (op == "<<") - { - ret <<= n; - } - else - { - ret >>= n; - } + mixin("ret " ~ op ~ "= n;"); return ret; } @@ -1018,4 +1012,15 @@ struct Integer h2 = h1 >> 1; assert(cast(long) h2 == 212); } + + /// Ditto. + Integer opBinary(string op)(in Integer h) nothrow @safe @nogc + if (op == "+" || op == "-" || op == "/" + || op == "*" || op == "^^" || op == "%") + { + checkAllocator(); + auto ret = Integer(this, allocator); + mixin("ret " ~ op ~ "= h;"); + return ret; + } } -- cgit v1.2.3