value · System
Int256
public value Int256 : ISignedNumber<i256>, IHashable<i256>, IComparable<i256>, IToString
- Tipo
- value
- Espacio de nombres
- System
- Ensamblado
- System.Core
- Acceso
- public, miembros de i256
- Archivo fuente
Primitives.ant
Herencia
- Interfaces
-
ISignedNumber<TSelf>IHashable<TSelf>IComparable<TSelf>IToString - Todas las interfaces
-
IComparable<TSelf>IHashable<TSelf>INumber<TSelf>ISignedNumber<TSelf>IToString
Propiedades
Métodos
ToString() : str
#
The integer text writes (an optional '-', then decimal digits); a FormatError otherwise.
The number text writes, or null when it writes none.
Constantes
const i256 MinValue = -57896044618658097711785492504343953926634992332820282019728792003956564819968
#
The smallest i256.
const i256 MaxValue = 57896044618658097711785492504343953926634992332820282019728792003956564819967
#
The largest i256.
Código fuente
Int256 en Antril, descompilado a partir de su Larva HIR.
// System.Int256 — System.Core (decompiled from Larva HIR)
into namespace System
{
[Primitive("i256")]
public value Int256 : ISignedNumber<i256>, IHashable<i256>, IComparable<i256>, IToString
{
public:
/// The smallest i256.
const i256 MinValue = -57896044618658097711785492504343953926634992332820282019728792003956564819968;
/// The largest i256.
const i256 MaxValue = 57896044618658097711785492504343953926634992332820282019728792003956564819967;
static FromF64(f64 value) : i256
{
if (value < 0.0)
return -(i256)UInt256.FromF64(-value);
return (i256)UInt256.FromF64(value);
}
static ToF64(i256 value) : f64 => value < 0 ? -UInt256.ToF64((u256)-value) : UInt256.ToF64((u256)value);
ToString() : str
{
if (this >= 0)
return Number.FormatUnsigned((u256)this);
u256 magnitude = (u256)-(this + 1) + 1;
return "-" + Number.FormatUnsigned(magnitude);
}
Hash() : u64 => (u64)this ^ (u64)(this >> 64) ^ (u64)(this >> 128) ^ (u64)(this >> 192);
Equals(i256 other) : bool => this == other;
CompareTo(i256 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) : i256
{
i256? 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) : i256?
{
i32 length = text.Length;
bool negative = length > 0 && text[0] == 45;
i32 start = negative ? 1 : 0;
if (start == length)
return null;
i256 value = 0;
loop (i32 i = start..length)
{
u8 unit = text[i];
if (unit < 48 || unit > 57)
return null;
i256 digit = (i256)unit - 48;
if (value < (-57896044618658097711785492504343953926634992332820282019728792003956564819968 + digit) / 10)
return null;
value = value * 10 - digit;
}
if (!negative && value == -57896044618658097711785492504343953926634992332820282019728792003956564819968)
return null;
return negative ? value : -value;
}
static i256 Zero
{
get => 0;
}
static i256 One
{
get => 1;
}
static i256 NegativeOne
{
get => -1;
}
}
}