value · System

Float16

public value Float16 : ISignedNumber<f16>, IComparable<f16>, IToString
Kind
value
Namespace
System
Assembly
System.Core
Access
public, members of f16
Source file
Primitives.ant

Inheritance

Interfaces
ISignedNumber<TSelf> IComparable<TSelf> IToString
All interfaces
IComparable<TSelf> INumber<TSelf> ISignedNumber<TSelf> IToString

Properties

static f16 Zero { get; }
#

static read-only

static f16 One { get; }
#

static read-only

static f16 NegativeOne { get; }
#

static read-only

Methods

static FromF64(f64 value) : f16
#

static

static ToF64(f16 value) : f64
#

static

ToString(str format) : str
#

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

ToString() : str
#

The shortest text that reads back as the same number.

CompareTo(f16 other) : i32
#

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

Equals(f16 other) : bool
#
Hash() : u64
#
static unsafe Bits(f16 value) : u16
#

static

The IEEE 754 bits of the number, and back.

static unsafe FromBits(u16 bits) : f16
#

static

static IsNaN(f16 x) : bool
#

static

static IsInfinity(f16 x) : bool
#

static

static IsFinite(f16 x) : bool
#

static

static Parse(str text) : f16
#

static

The number text writes (digits, a point, an exponent), read as an f64 and rounded; a FormatError otherwise.

static TryParse(str text) : f16?
#

static

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

Constants

const f16 MaxValue = 65504.0f16
#

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

const f16 MinValue = -65504.0f16
#
const f16 Epsilon = 5.960464477539063E-08f16
#

The smallest f16 above zero (a subnormal).

const f16 NaN = (0.0f16 / 0.0f16)
#

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

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

Source

Float16 as Antril, decompiled from its Larva HIR.

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

into namespace System
{
	[Primitive("f16")]
	public value Float16 : ISignedNumber<f16>, IComparable<f16>, IToString
	{
		public:
			/// The largest finite f16, and the smallest (its negative).
			const f16 MaxValue = 65504.0f16;
			const f16 MinValue = -65504.0f16;

			/// The smallest f16 above zero (a subnormal).
			const f16 Epsilon = 5.960464477539063E-08f16;

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

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

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

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

			/// The shortest text that reads back as the same number.
			ToString() : str => NumberFormat.FormatHalf(this, "G");

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

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

			Hash() : u64 => Bits(this == 0.0f16 ? 0.0f16 : this);

			/// The IEEE 754 bits of the number, and back.
			static unsafe Bits(f16 value) : u16
			{
				f16 local = value;
				return *(u16*)&local;
			}

			static unsafe FromBits(u16 bits) : f16
			{
				u16 local = bits;
				return *(f16*)&local;
			}

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

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

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

			/// The number `text` writes (digits, a point, an exponent), read as an f64 and rounded; a FormatError otherwise.
			static Parse(str text) : f16 => (f16)Float64.Parse(text);

			/// The number `text` writes, or null when it writes none.
			static TryParse(str text) : f16?
			{
				f64? value = Float64.TryParse(text);
				if (value == null)
					return null;
				return (f16)value.Value;
			}

			static f16 Zero
			{
				get => 0.0f16;
			}

			static f16 One
			{
				get => 1.0f16;
			}

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