value · System

Float32

public value Float32 : ISignedNumber<f32>, IComparable<f32>, IToString
Tipo
value
Espacio de nombres
System
Ensamblado
System.Core
Acceso
public, miembros de f32
Archivo fuente
Primitives.ant

Herencia

Interfaces
ISignedNumber<TSelf> IComparable<TSelf> IToString
Todas las interfaces
IComparable<TSelf> INumber<TSelf> ISignedNumber<TSelf> IToString

Propiedades

static f32 Zero { get; }
#

static read-only

static f32 One { get; }
#

static read-only

static f32 NegativeOne { get; }
#

static read-only

Métodos

static FromF64(f64 value) : f32
#

static

static ToF64(f32 value) : f64
#

static

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
#
CompareTo(f32 other) : i32
#

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

static Bits(f32 value) : u32
#

static

The IEEE 754 bits of value (an f32 is exact as an f64: its bits are rebuilt from those).

static FromBits(u32 bits) : f32
#

static

The f32 with these IEEE 754 bits.

Constantes

const f32 MaxValue = 3.4028234663852886E+38
#

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

const f32 MinValue = -3.4028234663852886E+38
#
const f32 Epsilon = 1.401298464324817E-45
#

The smallest f32 above zero (a subnormal).

const f32 NaN = (0.0 / 0.0)
#

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

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

Código fuente

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

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

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

			/// The smallest f32 above zero (a subnormal).
			const f32 Epsilon = 1.401298464324817E-45;

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

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

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

			/// 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.FormatSingle(this, format);

			ToString() : str => NumberFormat.FormatSingle(this, "R");

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

			/// The IEEE 754 bits of `value` (an f32 is exact as an f64: its bits are rebuilt from those).
			static Bits(f32 value) : u32
			{
				i64 wide = Float64.Bits(value);
				u32 sign = (u32)(wide >> 32) & 2147483648;
				i32 exponent = (i32)(wide >> 52) & 2047;
				i64 mantissa = wide & 4503599627370495;
				if (exponent == 2047)
					return sign | 2139095040 | (u32)(mantissa >> 29) | (mantissa != 0 ? 4194304 : 0);
				if (exponent == 0)
					return sign;
				i32 biased = exponent - 1023 + 127;
				if (biased >= 1)
					return sign | (u32)biased << 23 | (u32)(mantissa >> 29);
				return sign | (u32)((mantissa | 4503599627370496) >> 30 - (i64)biased);
			}

			/// The f32 with these IEEE 754 bits.
			static FromBits(u32 bits) : f32
			{
				i64 sign = ((i64)bits & 2147483648) << 32;
				i32 exponent = (i32)(bits >> 23) & 255;
				i64 mantissa = (i64)bits & 8388607;
				if (exponent == 255)
					return (f32)Float64.FromBits(sign | 9218868437227405312 | mantissa << 29);
				if (exponent == 0)
				{
					if (mantissa == 0)
						return (f32)Float64.FromBits(sign);
					i32 shift = 0;
					loop ((mantissa & 8388608) == 0)
					{
						mantissa = mantissa << 1;
						shift++;
					}
					return (f32)Float64.FromBits(sign | -126 - (i64)shift + 1023 << 52 | (mantissa & 8388607) << 29);
				}
				return (f32)Float64.FromBits(sign | (i64)exponent - 127 + 1023 << 52 | mantissa << 29);
			}

			static f32 Zero
			{
				get => 0.0;
			}

			static f32 One
			{
				get => 1.0;
			}

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