value · System

Float64

public value Float64 : ISignedNumber<f64>, IHashable<f64>, IComparable<f64>, IToString
Tipo
value
Espacio de nombres
System
Ensamblado
System.Core
Acceso
public, miembros de f64
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 f64 Zero { get; }
#

static read-only

static f64 One { get; }
#

static read-only

static f64 NegativeOne { get; }
#

static read-only

Métodos

static FromF64(f64 value) : f64
#

static

static ToF64(f64 value) : f64
#

static

static extern("format.f64") FormatInto(f64 value) : i64
#

static

static extern("format.unit") FormattedUnit(i64 index) : i64
#

static

static extern("parse.f64") ParseBits(u16[] text) : i64
#

static

static extern("f64.bits") BitsOf(f64 value) : i64
#

static

static extern("f64.from_bits") FromBitsOf(i64 bits) : f64
#

static

static IsNumber(str text) : bool
#

static

Digits, an optional point and more digits, an optional exponent: what ParseBits reads.

static Special(str trimmed) : i32
#

static

What a trimmed text names besides a number: 1 for nan (nan, NaN), 2 for +inf (inf, +inf, Infinity, +Infinity), 3 for -inf (-inf, -Infinity), 0 otherwise.

static ReadNumber(str text) : f64
#

static

The value of a text IsNumber accepts, read in place: up to 15 significant digits times a power of ten up to 10^22 are both exact in an f64, so one multiplication or division rounds the result correctly; the other texts go to ParseBits.

static ReadBits(str text) : f64
#

static

What ParseBits reads from a text IsNumber accepts (ASCII: its units widened as they are).

ToString(str format) : str
#

As text by a format: F, N, E, P, G, R and a precision ((2.5).ToString("F2") is "2.50").

ToString() : str
#

The shortest text that reads back as the same number, as print writes it (15 significant digits when they are enough, else 16 or 17); nan, inf and -inf for the values that are no number.

CompareTo(f64 other) : i32
#

A total order: the usual one, nan above every number and equal to itself, -0 equal to +0 (what sorting uses).

Equals(f64 other) : bool
#
Hash() : u64
#
static Bits(f64 value) : i64
#

static

The IEEE 754 bits of the number, and back.

static FromBits(i64 bits) : f64
#

static

static IsNaN(f64 x) : bool
#

static

static IsInfinity(f64 x) : bool
#

static

static IsFinite(f64 x) : bool
#

static

static Parse(str text) : f64
#

static

The number text writes (digits, a point, an exponent; nan, inf, -inf as ToString writes them, or NaN, Infinity, -Infinity); a FormatError otherwise.

static TryParse(str text) : f64?
#

static

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

Constantes

const f64 MaxValue = 1.7976931348623157E+308
#

The largest finite f64, and the smallest (its negative).

const f64 MinValue = -1.7976931348623157E+308
#
const f64 Epsilon = 5E-324
#

The smallest f64 above zero (a subnormal).

const f64 NaN = (0.0 / 0.0)
#

Not a number (quiet, positive), and the infinities.

const f64 PositiveInfinity = (1.0 / 0.0)
#
const f64 NegativeInfinity = (-1.0 / 0.0)
#

Código fuente

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

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

into namespace System
{
	[Primitive("f64")]
	public value Float64 : ISignedNumber<f64>, IHashable<f64>, IComparable<f64>, IToString
	{
		public:
			/// The largest finite f64, and the smallest (its negative).
			const f64 MaxValue = 1.7976931348623157E+308;
			const f64 MinValue = -1.7976931348623157E+308;

			/// The smallest f64 above zero (a subnormal).
			const f64 Epsilon = 5E-324;

			/// Not a number (quiet, positive), and the infinities.
			const f64 NaN = (0.0 / 0.0);
			const f64 PositiveInfinity = (1.0 / 0.0);
			const f64 NegativeInfinity = (-1.0 / 0.0);

			[Inline]
			static FromF64(f64 value) : f64 => value;

			[Inline]
			static ToF64(f64 value) : f64 => value;

			static extern("format.f64") FormatInto(f64 value) : i64;

			static extern("format.unit") FormattedUnit(i64 index) : i64;

			static extern("parse.f64") ParseBits(u16[] text) : i64;

			static extern("f64.bits") BitsOf(f64 value) : i64;

			static extern("f64.from_bits") FromBitsOf(i64 bits) : f64;

			/// Digits, an optional point and more digits, an optional exponent: what ParseBits reads.
			static IsNumber(str text) : bool
			{
				i32 i = 0;
				i32 n = text.Length;
				if (i < n && (text[i] == 45 || text[i] == 43))
					i++;
				i32 digits = 0;
				loop (i < n && text[i] >= 48 && text[i] <= 57)
				{
					i++;
					digits++;
				}
				if (i < n && text[i] == 46)
				{
					i++;
					loop (i < n && text[i] >= 48 && text[i] <= 57)
					{
						i++;
						digits++;
					}
				}
				if (digits == 0)
					return false;
				if (i < n && (text[i] == 101 || text[i] == 69))
				{
					i++;
					if (i < n && (text[i] == 45 || text[i] == 43))
						i++;
					i32 exponent = 0;
					loop (i < n && text[i] >= 48 && text[i] <= 57)
					{
						i++;
						exponent++;
					}
					if (exponent == 0)
						return false;
				}
				return i == n;
			}

			/// What a trimmed text names besides a number: 1 for nan (`nan`, `NaN`), 2 for +inf (`inf`, `+inf`,
			/// `Infinity`, `+Infinity`), 3 for -inf (`-inf`, `-Infinity`), 0 otherwise.
			static Special(str trimmed) : i32
			{
				if (trimmed == "nan" || trimmed == "NaN" || trimmed == "-nan")
					return 1;
				if (trimmed == "inf" || trimmed == "+inf" || trimmed == "Infinity" || trimmed == "+Infinity")
					return 2;
				if (trimmed == "-inf" || trimmed == "-Infinity")
					return 3;
				return 0;
			}

			/// The value of a text IsNumber accepts, read in place: up to 15 significant digits times a power of ten up
			/// to 10^22 are both exact in an f64, so one multiplication or division rounds the result correctly; the
			/// other texts go to ParseBits.
			static ReadNumber(str text) : f64
			{
				i32 n = text.Length;
				i32 i = 0;
				bool negative = text[0] == 45;
				if (negative || text[0] == 43)
					i++;
				u64 digits = 0;
				i32 significant = 0;
				i32 exponent = 0;
				bool point = false;
				loop (i < n)
				{
					u32 c = text[i];
					if (c == 46)
						point = true;
					else if (c >= 48 && c <= 57)
					{
						if (digits != 0 || c != 48)
						{
							significant++;
							if (significant > 15)
								return ReadBits(text);
							digits = digits * 10 + ((u64)c - 48);
						}
						if (point)
							exponent--;
					}
					else
						break;
					i++;
				}
				if (i < n)
				{
					i++;
					bool below = text[i] == 45;
					if (below || text[i] == 43)
						i++;
					if (n - i > 4)
						return ReadBits(text);
					i32 power = 0;
					loop (i < n)
					{
						power = power * 10 + ((i32)text[i] - 48);
						i++;
					}
					exponent += below ? -power : power;
				}
				if (digits == 0)
					return negative ? ReadBits(text) : 0.0;
				if (exponent < -22 || exponent > 22)
					return ReadBits(text);
				f64 scale = 1.0;
				loop (i32 k = 0..(exponent < 0 ? -exponent : exponent))
					scale = scale * 10.0;
				f64 value = exponent < 0 ? (f64)digits / scale : (f64)digits * scale;
				return negative ? -value : value;
			}

			/// What ParseBits reads from a text IsNumber accepts (ASCII: its units widened as they are).
			static ReadBits(str text) : f64
			{
				u16[] wide = new u16[text.Length];
				loop (i32 i = 0..wide.Length)
					wide[i] = text[i];
				return FromBitsOf(ParseBits(wide));
			}

			/// As text by a format: F, N, E, P, G, R and a precision (`(2.5).ToString("F2")` is "2.50").
			ToString(str format) : str => NumberFormat.FormatDouble(this, format);

			/// The shortest text that reads back as the same number, as `print` writes it (15 significant digits when
			/// they are enough, else 16 or 17); `nan`, `inf` and `-inf` for the values that are no number.
			ToString() : str
			{
				if (this != this)
					return "nan";
				if (this - this != 0.0)
					return this > 0.0 ? "inf" : "-inf";
				i64 count = FormatInto(this);
				u8[] digits = new u8[(i32)count];
				u16[] wide = new u16[(i32)count];
				loop (i32 i = 0..digits.Length)
				{
					digits[i] = (u8)FormattedUnit(i);
					wide[i] = digits[i];
				}
				if (ParseBits(wide) == BitsOf(this))
					return new str(digits);
				return NumberFormat.ShortestDouble(this);
			}

			/// A total order: the usual one, nan above every number and equal to itself, -0 equal to +0 (what sorting uses).
			CompareTo(f64 other) : i32
			{
				return this < other ? -1 : this > other ? 1 : this == other ? 0 : this != this ? other != other ? 0 : 1 : -1;
			}

			Equals(f64 other) : bool => this == other || IsNaN(this) && IsNaN(other);

			Hash() : u64 => (u64)BitsOf(this == 0.0 ? 0.0 : this);

			/// The IEEE 754 bits of the number, and back.
			static Bits(f64 value) : i64 => BitsOf(value);

			static FromBits(i64 bits) : f64 => FromBitsOf(bits);

			static IsNaN(f64 x) : bool => x != x;

			static IsInfinity(f64 x) : bool => x - x != 0.0 && x == x;

			static IsFinite(f64 x) : bool => x - x == 0.0;

			/// The number `text` writes (digits, a point, an exponent; `nan`, `inf`, `-inf` as ToString writes them, or
			/// `NaN`, `Infinity`, `-Infinity`); a FormatError otherwise.
			static Parse(str text) : f64
			{
				str trimmed = text.Trim();
				if (IsNumber(trimmed))
					return ReadNumber(trimmed);
				i32 special = Special(trimmed);
				if (special != 0)
					return special == 1 ? (0.0 / 0.0) : special == 2 ? (1.0 / 0.0) : (-1.0 / 0.0);
				throw new FormatError("not a number: " + text);
			}

			/// The number `text` writes, or null when it writes none.
			static TryParse(str text) : f64?
			{
				str trimmed = text.Trim();
				if (IsNumber(trimmed))
					return ReadNumber(trimmed);
				if (Special(trimmed) != 0)
					return Parse(trimmed);
				return null;
			}

			static f64 Zero
			{
				get => 0.0;
			}

			static f64 One
			{
				get => 1.0;
			}

			static f64 NegativeOne
			{
				get => -1.0;
			}
	}
}
Esc