Add opBinary for the other math operations on Integer
This commit is contained in:
parent
9362287938
commit
4309a30dfe
@ -993,18 +993,12 @@ struct Integer
|
|||||||
|
|
||||||
/// Ditto.
|
/// Ditto.
|
||||||
Integer opBinary(string op)(in size_t n) nothrow @safe @nogc
|
Integer opBinary(string op)(in size_t n) nothrow @safe @nogc
|
||||||
if (op == "<<" || op == ">>")
|
if (op == "<<" || op == ">>" || op == "+" || op == "-" || op == "/"
|
||||||
|
|| op == "*" || op == "^^" || op == "%")
|
||||||
{
|
{
|
||||||
checkAllocator();
|
checkAllocator();
|
||||||
auto ret = Integer(this, allocator);
|
auto ret = Integer(this, allocator);
|
||||||
static if (op == "<<")
|
mixin("ret " ~ op ~ "= n;");
|
||||||
{
|
|
||||||
ret <<= n;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ret >>= n;
|
|
||||||
}
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1018,4 +1012,15 @@ struct Integer
|
|||||||
h2 = h1 >> 1;
|
h2 = h1 >> 1;
|
||||||
assert(cast(long) h2 == 212);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user