value · System
Int128
public value Int128 : ISignedNumber<i128>, IHashable<i128>, IComparable<i128>, IToString
- Kind
- value
- Namespace
- System
- Assembly
- System.Core
- Access
- public, members of i128
- Source file
Primitives.ant
Inheritance
- Interfaces
-
ISignedNumber<TSelf>IHashable<TSelf>IComparable<TSelf>IToString - All interfaces
-
IComparable<TSelf>IHashable<TSelf>INumber<TSelf>ISignedNumber<TSelf>IToString
Properties
Methods
ToString() : str
#
The integer text writes (an optional '-', then decimal digits); a FormatError otherwise.
The number text writes, or null when it writes none.
Constants
The smallest i128.
The largest i128.
Source
Int128 as Antril, decompiled from its Larva HIR.
// System.Int128 — System.Core (decompiled from Larva HIR)
into namespace System
{
[Primitive("i128")]
public value Int128 : ISignedNumber<i128>, IHashable<i128>, IComparable<i128>, IToString
{
public:
/// The smallest i128.
const i128 MinValue = -170141183460469231731687303715884105728;
/// The largest i128.
const i128 MaxValue = 170141183460469231731687303715884105727;
static FromF64(f64 value) : i128
{
if (value < 0.0)
return -(i128)UInt128.FromF64(-value);
return (i128)UInt128.FromF64(value);
}
static ToF64(i128 value) : f64 => value < 0 ? -UInt128.ToF64((u128)-value) : UInt128.ToF64((u128)value);
ToString() : str
{
if (this >= 0)
return Number.FormatUnsigned((u128)this);
u128 magnitude = (u128)-(this + 1) + 1;
return "-" + Number.FormatUnsigned(magnitude);
}
Hash() : u64 => (u64)this ^ (u64)(this >> 64);
Equals(i128 other) : bool => this == other;
CompareTo(i128 other) : i32 => this < other ? -1 : this > other ? 1 : 0;
/// The integer `text` writes (an optional '-', then decimal digits); a FormatError otherwise.
static Parse(str text) : i128
{
i128? value = TryParse(text);
if (value == null)
throw new FormatError("not a number: " + text);
return value.Value;
}
/// The number `text` writes, or null when it writes none.
static TryParse(str text) : i128?
{
i32 length = text.Length;
bool negative = length > 0 && text[0] == 45;
i32 start = negative ? 1 : 0;
if (start == length)
return null;
i128 value = 0;
loop (i32 i = start..length)
{
u8 unit = text[i];
if (unit < 48 || unit > 57)
return null;
i128 digit = (i128)unit - 48;
if (value < (-170141183460469231731687303715884105728 + digit) / 10)
return null;
value = value * 10 - digit;
}
if (!negative && value == -170141183460469231731687303715884105728)
return null;
return negative ? value : -value;
}
static i128 Zero
{
get => 0;
}
static i128 One
{
get => 1;
}
static i128 NegativeOne
{
get => -1;
}
}
}