View source code
Display the source code in std/int128.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.
Struct std.int128.Int128
128 bit signed integer type.
struct Int128
;
Constructors
Name | Description |
---|---|
this
(lo)
|
Construct an Int128 from a long value.
The upper 64 bits are formed by sign extension.
|
this
(lo)
|
Construct an Int128 from a ulong value.
The upper 64 bits are set to zero.
|
this
(hi, lo)
|
Construct an Int128 from a long value.
|
this
(data)
|
Construct an Int128 from a Cent .
|
Fields
Name | Type | Description |
---|---|---|
data
|
core | core.int128.Cent |
Methods
Name | Description |
---|---|
opBinary
(op2)
|
Support binary arithmetic operators + - * / % & | ^ << >> >>> |
opBinaryRight
(op2)
|
Support binary arithmetic operators + - * / % & | ^ << >> >>> |
opCast
()
|
Support casting to a bool |
opCmp
(op2)
|
support signed arithmentic comparison operators < <= > >= |
opEquals
(lo)
|
Compare for equality |
opEquals
(lo)
|
Compare for equality |
opEquals
(op2)
|
Compare for equality |
opOpAssign
(op2)
|
arithmetic assignment operators += -= *= /= %= &= |= ^= <<= >>= >>>= |
opUnary
()
|
Support unary arithmentic operator + |
opUnary
()
|
Support unary arithmentic operator - ~ |
opUnary
()
|
Support unary arithmentic operator ++ -- |
toHash
()
|
Example
Int128 tests
Int128 c = Int128(5, 6);
writeln(c); // c
writeln(c); // +c
writeln(c); // --c
writeln(~c); // Int128(~5, ~6)
++c;
writeln(c); // Int128(5, 7)
writeln(--c); // Int128(5, 6)
assert(!!c);
assert(!Int128());
writeln(c + Int128(10, 20)); // Int128(15, 26)
writeln(c - Int128(1, 2)); // Int128(4, 4)
writeln(c * Int128(100, 2)); // Int128(610, 12)
writeln(c / Int128(3, 2)); // Int128(0, 1)
writeln(c % Int128(3, 2)); // Int128(2, 4)
writeln((c & Int128(3, 2))); // Int128(1, 2)
writeln((c | Int128(3, 2))); // Int128(7, 6)
writeln((c ^ Int128(3, 2))); // Int128(6, 4)
writeln(c + 15); // Int128(5, 21)
writeln(c - 15); // Int128(4, -9)
writeln(c * 15); // Int128(75, 90)
writeln(c / 15); // Int128(0, 6148914691236517205)
writeln(c % 15); // Int128(0, 11)
writeln((c & 15)); // Int128(0, 6)
writeln((c | 15)); // Int128(5, 15)
writeln((c ^ 15)); // Int128(5, 9)
writeln(15 + c); // Int128(5, 21)
writeln(15 - c); // Int128(-5, 9)
writeln(15 * c); // Int128(75, 90)
writeln(15 / c); // Int128(0, 0)
writeln(15 % c); // Int128(0, 15)
writeln((15 & c)); // Int128(0, 6)
writeln((15 | c)); // Int128(5, 15)
writeln((15 ^ c)); // Int128(5, 9)
writeln(c << 1); // Int128(10, 12)
writeln(-c >> 1); // Int128(-3, 9223372036854775805)
writeln(-c >>> 1); // Int128(9223372036854775805, 9223372036854775805)
writeln((c += 1)); // Int128(5, 7)
writeln((c -= 1)); // Int128(5, 6)
writeln((c += Int128(0, 1))); // Int128(5, 7)
writeln((c -= Int128(0, 1))); // Int128(5, 6)
writeln((c *= 2)); // Int128(10, 12)
writeln((c /= 2)); // Int128(5, 6)
writeln((c %= 2)); // Int128()
c += Int128(5, 6);
writeln((c *= Int128(10, 20))); // Int128(160, 120)
writeln((c /= Int128(10, 20))); // Int128(0, 15)
c += Int128(72, 0);
writeln((c %= Int128(10, 20))); // Int128(1, -125)
writeln((c &= Int128(3, 20))); // Int128(1, 0)
writeln((c |= Int128(8, 2))); // Int128(9, 2)
writeln((c ^= Int128(8, 2))); // Int128(1, 0)
c |= Int128(10, 5);
writeln((c <<= 1)); // Int128(11 * 2, 5 * 2)
writeln((c >>>= 1)); // Int128(11, 5)
c = Int128(long .min, long .min);
writeln((c >>= 1)); // Int128(long.min >> 1, cast(ulong)long.min >> 1)
writeln(-Int128 .min); // Int128.min
writeln(Int128 .max + 1); // Int128.min
c = Int128(5, 6);
assert(c < Int128(6, 5));
assert(c > 10);
c = Int128(-1UL);
writeln(c); // -1UL
c = Int128(-1L);
writeln(c); // -1L
Authors
License
Copyright © 1999-2024 by the D Language Foundation | Page generated by ddox.