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.opCast
- multiple declarations
Function BigInt.opCast
Implements casting to bool
.
T opCast(T)() const pure nothrow @nogc;
Example
// Non-zero values are regarded as true
auto x = BigInt("1");
auto y = BigInt("10");
assert(x);
assert(y);
// Zero value is regarded as false
auto z = BigInt("0");
assert(!z);
Function BigInt.opCast
Implements casting to integer types.
T opCast(T)() const pure;
Throws
ConvOverflowException
if the number exceeds
the target type's range.
Example
import std .conv : to, ConvOverflowException;
import std .exception : assertThrown;
writeln(BigInt("0") .to!int); // 0
writeln(BigInt("0") .to!ubyte); // 0
writeln(BigInt("255") .to!ubyte); // 255
assertThrown!ConvOverflowException(BigInt("256") .to!ubyte);
assertThrown!ConvOverflowException(BigInt("-1") .to!ubyte);
Function BigInt.opCast
Implements casting to/from qualified BigInt
's.
T opCast(T)() const pure nothrow @nogc
if (is(Unqual!T == BigInt));
Warning
Casting to/from const
or immutable
may break type
system guarantees. Use with care.
Example
const(BigInt) x = BigInt("123");
BigInt y = cast() x; // cast away const
writeln(y); // x
Authors
Don Clugston
License
Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.