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
a local clone.
std.int128
Implements a signed 128 bit integer type.
Author Walter Bright
License:
Source std/int128.d
- struct
Int128
; - 128 bit signed integer type.
- Cent
data
; - core.int128.Cent
- pure nothrow @nogc @safe this(long
lo
); - Construct an Int128 from a long value. The upper 64 bits are formed by sign extension.Parameters:
long lo
signed lower 64 bits - pure nothrow @nogc @safe this(ulong
lo
); - Construct an Int128 from a ulong value. The upper 64 bits are set to zero.Parameters:
ulong lo
unsigned lower 64 bits - pure nothrow @nogc @safe this(long
hi
, longlo
); - Construct an Int128 from a long value.Parameters:
long hi
upper 64 bits long lo
lower 64 bits - pure nothrow @nogc @safe this(Cent
data
); - Construct an Int128 from a Cent.Parameters:
Cent data
Cent data - const pure nothrow @nogc @safe size_t
toHash
(); - Returns:hash value for Int128
- const pure nothrow @nogc @safe bool
opEquals
(longlo
); - Compare for equalityParameters:
long lo
signed value to compare with Returns:true if Int128 equals value - const pure nothrow @nogc @safe bool
opEquals
(ulonglo
); - Compare for equalityParameters:
ulong lo
unsigned value to compare with Returns:true if Int128 equals value - const pure nothrow @nogc @safe bool
opEquals
(Int128op2
); - Compare for equalityParameters:
Int128 op2
value to compare with Returns:true if Int128 equals value - const Int128
opUnary
(string op)()
if (op == "+"); - Support unary arithmentic operator +Parameters:
op "+" Returns:lvalue of result - const Int128
opUnary
(string op)()
if (op == "-" || op == "~"); - Support unary arithmentic operator - ~Parameters:
op "-", "~" Returns:lvalue of result - Int128
opUnary
(string op)()
if (op == "++" || op == "--"); - Support unary arithmentic operator ++ --Parameters:
op "++", "--" Returns:lvalue of result - const bool
opCast
(T : bool)(); - Support casting to a boolParameters:
T bool Returns:true if value is not zero - const T
opCast
(T : long)()
if (is(byte : T)); - Support casting to an integral typeParameters:
T integral type Returns:low bits of value reinterpreted as TExamples:const Int128 a = Int128(0xffff_ffff_ffff_ffffL, 0x0123_4567_89ab_cdefL); writeln(cast(long)a); // 0x0123_4567_89ab_cdefL writeln(cast(int)a); // 0x89ab_cdef writeln(cast(byte)a); // cast(byte)0xef
- const T
opCast
(T : real)(); - Support casting to floating point typeParameters:
T floating point type Returns:value cast to floating point with environment-dependent rounding if the value is not exactly representableExamples:const Int128 a = Int128(-1L << 60); writeln(cast(double)a); // -(2.0^^60) writeln(cast(double)(a * a)); // 2.0^^120
- const Int128
opBinary
(string op)(Int128op2
)
if (op == "+" || op == "-" || op == "*" || op == "/" || op == "%" || op == "&" || op == "|" || op == "^");
const Int128opBinary
(string op, Int)(const Intop2
)
if ((op == "+" || op == "-" || op == "*" || op == "/" || op == "%" || op == "&" || op == "|" || op == "^") && is(Int : long) && __traits(isIntegral, Int));
const Int128opBinary
(string op, IntLike)(auto ref IntLikeop2
)
if ((op == "+" || op == "-" || op == "*" || op == "/" || op == "%" || op == "&" || op == "|" || op == "^") && is(IntLike : long) && !__traits(isIntegral, IntLike));
const Int128opBinaryRight
(string op, Int)(const Intop2
)
if ((op == "+" || op == "-" || op == "*" || op == "/" || op == "%" || op == "&" || op == "|" || op == "^") && is(Int : long) && __traits(isIntegral, Int));
const Int128opBinaryRight
(string op, IntLike)(auto ref IntLikeop2
)
if ((op == "+" || op == "-" || op == "*" || op == "/" || op == "%" || op == "&" || op == "|" || op == "^") && is(IntLike : long) && !__traits(isIntegral, IntLike));
const Int128opBinary
(string op)(longop2
)
if (op == "<<");
const Int128opBinary
(string op)(longop2
)
if (op == ">>");
const Int128opBinary
(string op)(longop2
)
if (op == ">>>"); - Support binary arithmetic operators + - * / % & | ^ << >> >>>Parameters:
op one of the arithmetic binary operators Int128 op2
second operand Returns:value after the operation is applied - ref Int128
opOpAssign
(string op)(Int128op2
)
if (op == "+" || op == "-" || op == "*" || op == "/" || op == "%" || op == "&" || op == "|" || op == "^" || op == "<<" || op == ">>" || op == ">>>");
ref Int128opOpAssign
(string op, Int)(auto ref Intop2
)
if ((op == "+" || op == "-" || op == "*" || op == "/" || op == "%" || op == "&" || op == "|" || op == "^" || op == "<<" || op == ">>" || op == ">>>") && is(Int : long)); - arithmetic assignment operators += -= *= /= %= &= |= ^= <<= >>= >>>=Parameters:
op one of +, -, etc. Int128 op2
second operand Returns:lvalue of updated left operand - const pure nothrow @nogc @safe int
opCmp
(Int128op2
);
const pure nothrow @nogc @safe intopCmp
(Int)(const Intop2
)
if (is(Int : long) && __traits(isIntegral, Int));
const intopCmp
(IntLike)(auto ref IntLikeop2
)
if (is(IntLike : long) && !__traits(isIntegral, IntLike)); - support arithmentic comparison operators < <= > >=Parameters:
Int128 op2
right hand operand Returns:-1 for less than, 0 for equals, 1 for greater than - const void
toString
(Writer, FormatSpec)(ref scope Writersink
, ref scope const FormatSpecfmt
); - Formats Int128 with either %d, %x, %X, or %s (same as %d).Parameters:
Writer sink
Output range to write to. FormatSpec fmt
A std.format.FormatSpec which controls how the number is displayed. Throws:std.format.FormatException if the format specifier is not one of 'd', 'x', 'X', 's'.See Also:Examples:toString
is rarely directly invoked; the usual way of using it is via std.format.format:import std.format : format; writeln(format("%s", Int128.max)); // "170141183460469231731687303715884105727" writeln(format("%s", Int128.min)); // "-170141183460469231731687303715884105728" writeln(format("%x", Int128.max)); // "7fffffffffffffffffffffffffffffff" writeln(format("%X", Int128.max)); // "7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" writeln(format("%032X", Int128(123L))); // "0000000000000000000000000000007B" writeln(format("%+ 40d", Int128(123L))); // " +123" writeln(format("%+-40d", Int128(123L))); // "+123 "
Examples:Also can format as wchar or dchar.import std.conv : to; writeln(to!wstring(Int128.max)); // "170141183460469231731687303715884105727"w writeln(to!dstring(Int128.max)); // "170141183460469231731687303715884105727"d
- enum Int128
min
; - minimum value
- enum Int128
max
; - maximum value
Copyright © 1999-2024 by the D Language Foundation | Page generated by
Ddoc on Sun Nov 17 01:08:36 2024