value · System

Int128

public value Int128 : ISignedNumber<i128>, IHashable<i128>, IComparable<i128>, IToString
Tipo
value
Espacio de nombres
System
Ensamblado
System.Core
Acceso
public, miembros de i128
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

static i128 Zero { get; }
#

static read-only

static i128 One { get; }
#

static read-only

static i128 NegativeOne { get; }
#

static read-only

Métodos

static FromF64(f64 value) : i128
#

static

static ToF64(i128 value) : f64
#

static

ToString() : str
#
Hash() : u64
#
Equals(i128 other) : bool
#
CompareTo(i128 other) : i32
#
static Parse(str text) : i128
#

static

The integer text writes (an optional '-', then decimal digits); a FormatError otherwise.

static TryParse(str text) : i128?
#

static

The number text writes, or null when it writes none.

Constantes

const i128 MinValue = -170141183460469231731687303715884105728
#

The smallest i128.

const i128 MaxValue = 170141183460469231731687303715884105727
#

The largest i128.

Código fuente

Int128 en Antril, descompilado a partir de su Larva HIR.

System.Int128.ant
// 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;
			}
	}
}
Esc