final class · System

DecimalDigits

final class DecimalDigits

A number's exact decimal digits: value = 0.d1 d2 … × 10^Point (digits 0..9, no leading zero; Count 0: zero).

Kind
final class
Namespace
System
Assembly
System.Core
Access
internal, final
Source file
Format.ant

Inheritance

Base classes
Any DecimalDigits

Constructors

new(u8[] digits, i32 count, i32 point, bool negative)
#

Methods

At(i32 i) : u8
#

Digit i (0 past the ones it has).

Round(i32 keep)
#

Rounded to its first keep digits; an exact half goes to the even digit (as .NET does).

Trim()
#

Fields

u8[] Digits
#
i32 Count
#
i32 Point
#
bool Negative
#

Inherited members (5)

Source

DecimalDigits as Antril, decompiled from its Larva HIR.

System.DecimalDigits.ant
// System.DecimalDigits — System.Core (decompiled from Larva HIR)

into namespace System
{
	/// A number's exact decimal digits: value = 0.d1 d2 … × 10^Point (digits 0..9, no leading zero; Count 0: zero).
	final class DecimalDigits
	{
		public:
			u8[] Digits;
			i32 Count;
			i32 Point;
			bool Negative;

			new(u8[] digits, i32 count, i32 point, bool negative)
			{
				Digits = digits;
				Count = count;
				Point = point;
				Negative = negative;
			}

			/// Digit `i` (0 past the ones it has).
			At(i32 i) : u8 => i >= 0 && i < Count ? Digits[i] : 0;

			/// Rounded to its first `keep` digits; an exact half goes to the even digit (as .NET does).
			Round(i32 keep)
			{
				if (keep >= Count)
					return;
				if (keep < 0)
				{
					Count = 0;
					return;
				}
				u8 next = Digits[keep];
				bool up = next > 5 || next == 5 && (keep + 1 < Count || keep > 0 && Digits[keep - 1] % 2 == 1);
				Count = keep;
				if (!up)
				{
					Trim();
					return;
				}
				i32 i = keep - 1;
				loop (i >= 0 && Digits[i] == 9)
				{
					Digits[i] = 0;
					i--;
				}
				if (i >= 0)
				{
					Digits[i] = Digits[i] + 1;
					Trim();
					return;
				}
				if (Digits.Length == 0)
					Digits = new u8[1];
				Digits[0] = 1;
				Count = 1;
				Point++;
			}

			Trim()
			{
				loop (Count > 0 && Digits[Count - 1] == 0)
					Count--;
			}
	}
}
Esc