value · System

Int256

public value Int256 : ISignedNumber<i256>, IHashable<i256>, IComparable<i256>, IToString
Kind
value
Namespace
System
Assembly
System.Core
Access
public, members of i256
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

static i256 Zero { get; }
#

static read-only

static i256 One { get; }
#

static read-only

static i256 NegativeOne { get; }
#

static read-only

Methods

static FromF64(f64 value) : i256
#

static

static ToF64(i256 value) : f64
#

static

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

static

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

static TryParse(str text) : i256?
#

static

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

Constants

const i256 MinValue = -57896044618658097711785492504343953926634992332820282019728792003956564819968
#

The smallest i256.

const i256 MaxValue = 57896044618658097711785492504343953926634992332820282019728792003956564819967
#

The largest i256.

Source

Int256 as Antril, decompiled from its Larva HIR.

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