Movatterモバイル変換


[0]ホーム

URL:


D Logo
Menu
Search

Library Reference

version 2.112.0

overview

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 usinga local clone.

std.int128

Implements a signed 128 bit integer type.

AuthorWalter Bright

License:
Boost License 1.0

Sourcestd/int128.d

structInt128;
128 bit signed integer type.
Centdata;
core.int128.Cent
pure nothrow @nogc @safe this(longlo);
Construct anInt128 from along value. The upper 64 bits are formed by sign extension.
Parameters:
longlosigned lower 64 bits
pure nothrow @nogc @safe this(ulonglo);
Construct anInt128 from aulong value. The upper 64 bits are set to zero.
Parameters:
ulonglounsigned lower 64 bits
pure nothrow @nogc @safe this(longhi, longlo);
Construct anInt128 from along value.
Parameters:
longhiupper 64 bits
longlolower 64 bits
pure nothrow @nogc @safe this(Centdata);
Construct anInt128 from aCent.
Parameters:
CentdataCent data
pure nothrow @nogc @safe size_ttoHash() const;
Returns:
hash value for Int128
pure nothrow @nogc @safe boolopEquals(longlo) const;
Compare for equality
Parameters:
longlosigned value to compare with
Returns:
true if Int128 equals value
pure nothrow @nogc @safe boolopEquals(ulonglo) const;
Compare for equality
Parameters:
ulonglounsigned value to compare with
Returns:
true if Int128 equals value
pure nothrow @nogc @safe boolopEquals(Int128op2) const;
Compare for equality
Parameters:
Int128op2value to compare with
Returns:
true if Int128 equals value
Int128opUnary(string op)() const
if (op == "+");
Support unary arithmentic operator +
Parameters:
op"+"
Returns:
lvalue of result
Int128opUnary(string op)() const
if (op == "-" || op == "~");
Support unary arithmentic operator - ~
Parameters:
op"-", "~"
Returns:
lvalue of result
Int128opUnary(string op)()
if (op == "++" || op == "--");
Support unary arithmentic operator ++ --
Parameters:
op"++", "--"
Returns:
lvalue of result
boolopCast(T : bool)() const;
Support casting to a bool
Parameters:
Tbool
Returns:
true if value is not zero
TopCast(T : long)() const
if (is(byte : T));
Support casting to an integral type
Parameters:
Tintegral type
Returns:
low bits of value reinterpreted as T
Examples:
const Int128 a = Int128(0xffff_ffff_ffff_ffffL, 0x0123_4567_89ab_cdefL);writeln(cast(long)a);// 0x0123_4567_89ab_cdefLwriteln(cast(int)a);// 0x89ab_cdefwriteln(cast(byte)a);// cast(byte)0xef
TopCast(T : real)() const;
Support casting to floating point type
Parameters:
Tfloating point type
Returns:
value cast to floating point with environment-dependent rounding if the value is not exactly representable
Examples:
const Int128 a = Int128(-1L << 60);writeln(cast(double)a);// -(2.0^^60)writeln(cast(double)(a * a));// 2.0^^120
Int128opBinary(string op)(Int128op2) const
if (op == "+" || op == "-" || op == "*" || op == "/" || op == "%" || op == "&" || op == "|" || op == "^");

Int128opBinary(string op, Int)(const Intop2) const
if ((op == "+" || op == "-" || op == "*" || op == "/" || op == "%" || op == "&" || op == "|" || op == "^") && is(Int : long) && __traits(isIntegral, Int));

Int128opBinary(string op, IntLike)(auto ref IntLikeop2) const
if ((op == "+" || op == "-" || op == "*" || op == "/" || op == "%" || op == "&" || op == "|" || op == "^") && is(IntLike : long) && !__traits(isIntegral, IntLike));

Int128opBinaryRight(string op, Int)(const Intop2) const
if ((op == "+" || op == "-" || op == "*" || op == "/" || op == "%" || op == "&" || op == "|" || op == "^") && is(Int : long) && __traits(isIntegral, Int));

Int128opBinaryRight(string op, IntLike)(auto ref IntLikeop2) const
if ((op == "+" || op == "-" || op == "*" || op == "/" || op == "%" || op == "&" || op == "|" || op == "^") && is(IntLike : long) && !__traits(isIntegral, IntLike));

Int128opBinary(string op)(longop2) const
if (op == "<<");

Int128opBinary(string op)(longop2) const
if (op == ">>");

Int128opBinary(string op)(longop2) const
if (op == ">>>");
Support binary arithmetic operators + - * / % & | ^ << >> >>>
Parameters:
opone of the arithmetic binary operators
Int128op2second operand
Returns:
value after the operation is applied
ref Int128opOpAssign(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:
opone of +, -, etc.
Int128op2second operand
Returns:
lvalue of updated left operand
pure nothrow @nogc @safe intopCmp(Int128op2) const;

pure nothrow @nogc @safe intopCmp(Int)(const Intop2) const
if (is(Int : long) && __traits(isIntegral, Int));

intopCmp(IntLike)(auto ref IntLikeop2) const
if (is(IntLike : long) && !__traits(isIntegral, IntLike));
support arithmentic comparison operators < <= > >=
Parameters:
Int128op2right hand operand
Returns:
-1 for less than, 0 for equals, 1 for greater than
voidtoString(Writer, FormatSpec)(ref scope Writersink, ref scope const FormatSpecfmt) const;
FormatsInt128 with either%d,%x,%X, or%s (same as%d).
Parameters:
WritersinkOutput range to write to.
FormatSpecfmtAstd.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'.
Examples:
toString is rarely directly invoked; the usual way of using it is viastd.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 aswchar ordchar.
import std.conv : to;writeln(to!wstring(Int128.max));// "170141183460469231731687303715884105727"wwriteln(to!dstring(Int128.max));// "170141183460469231731687303715884105727"d
enum Int128min;
minimum value
enum Int128max;
maximum value
Copyright © 1999-2026 by theD Language Foundation | Page generated byDdoc on Fri Feb 20 00:53:25 2026

[8]ページ先頭

©2009-2026 Movatter.jp