View source code
Display the source code in std/bigint.d from which this
page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a
Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
std.bigint.BigInt.opBinary
- multiple declarations
Function BigInt.opBinary
Implements binary operators between BigInt
s.
BigInt opBinary(string op, T)
(
T y
) const pure nothrow scope @safe
if ((op == "+" || op == "*" || op == "-" || op == "|" || op == "&" || op == "^" || op == "/" || op == "%") && is(T : BigInt));
Example
auto x = BigInt("123");
auto y = BigInt("456");
BigInt z = x * y;
writeln(z); // BigInt("56088")
Function BigInt.opBinary
Implements binary operators between BigInt
's and built-in integers.
BigInt opBinary(string op, T)
(
T y
) const pure nothrow scope @safe
if ((op == "+" || op == "*" || op == "-" || op == "/" || op == "|" || op == "&" || op == "^" || op == ">>" || op == "<<" || op == "^^") && isIntegral!T);
Example
auto x = BigInt("123");
x *= 300;
writeln(x); // BigInt("36900")
Function BigInt.opBinary
Implements a narrowing remainder operation with built-in integer types.
auto opBinary(string op, T)
(
T y
) const pure nothrow @safe
if (op == "%" && isIntegral!T);
This binary operator returns a narrower, built-in integer type where applicable, according to the following table.
BigInt | % | uint | → | long |
BigInt | % | long | → | long |
BigInt | % | ulong | → | BigInt |
BigInt | % | other type | → | int |
Example
auto x = BigInt("1_000_000_500");
long l = 1_000_000L;
ulong ul = 2_000_000UL;
int i = 500_000;
short s = 30_000;
assert(is(typeof(x % l) == long) && x % l == 500L);
assert(is(typeof(x % ul) == BigInt) && x % ul == BigInt(500));
assert(is(typeof(x % i) == int) && x % i == 500);
assert(is(typeof(x % s) == int) && x % s == 10500);
Authors
Don Clugston
License
Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.