summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2016-12-08 14:51:49 +0100
committerEugen Wissner <belka@caraus.de>2016-12-08 14:51:49 +0100
commit4309a30dfeed2913b06ee4e699daae678764c528 (patch)
treeccb2924f5c3fc3c8d714b043a221a3794e95733f
parent9362287938622d49bf2aebdcefcfafa717e62643 (diff)
downloadtanya-4309a30dfeed2913b06ee4e699daae678764c528.tar.gz
Add opBinary for the other math operations on Integer
-rw-r--r--.travis.yml (renamed from .travis)0
-rw-r--r--source/tanya/math/mp.d23
2 files changed, 14 insertions, 9 deletions
diff --git a/.travis b/.travis.yml
index 07d22bf..07d22bf 100644
--- a/.travis
+++ b/.travis.yml
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;
+ }
}