Float8E5M2

Structs · AiDotNet.MixedPrecision

Represents an 8-bit floating point number in E5M2 format (5 exponent bits, 2 mantissa bits).

Inheritance: ValueType → Float8E5M2

Implements: IComparable<Float8E5M2>, IEquatable<Float8E5M2>

For Beginners

E5M2 is an 8-bit format with a larger range but less precision than E4M3. It’s designed for gradients during backpropagation, which can have a wider range of values.

How It Works

Format Details:

  • 1 sign bit
  • 5 exponent bits (bias = 15)
  • 2 mantissa bits
  • Range: ±57344
  • Smallest positive (subnormal): ~0.0000152588 (2^-16)

Use Cases: Best for gradients in neural network backward passes where the larger dynamic range helps prevent gradient underflow/overflow.

Best Practice: Use E5M2 for gradients with dynamic loss scaling to handle the reduced precision while leveraging the larger dynamic range.

Properties

Property Summary
bool IsInfinity { get; } Returns true if this value is infinity (positive or negative).
bool IsNaN { get; } Returns true if this value is NaN.
bool IsNegative { get; } Returns true if this value is negative.
bool IsZero { get; } Returns true if this value is zero.
byte RawValue { get; } Gets the raw byte value.

Methods

Method Summary
Float8E5M2 FromFloat(float value) Creates a Float8E5M2 from a single-precision float.
Float8E5M2 op_Explicit(float value)
bool Equals(Float8E5M2 other)
bool Equals(object obj)
bool op_Equality(Float8E5M2 left, Float8E5M2 right)
bool op_GreaterThan(Float8E5M2 left, Float8E5M2 right)
bool op_GreaterThanOrEqual(Float8E5M2 left, Float8E5M2 right)
bool op_Inequality(Float8E5M2 left, Float8E5M2 right)
bool op_LessThan(Float8E5M2 left, Float8E5M2 right)
bool op_LessThanOrEqual(Float8E5M2 left, Float8E5M2 right)
float ToFloat() Converts this Float8E5M2 to a single-precision float.
float op_Explicit(Float8E5M2 value)
int CompareTo(Float8E5M2 other)
int GetHashCode()
string ToString()

Fields

Field Summary
Float8E5M2 MaxValue Maximum representable value in E5M2 format (57344).
Float8E5M2 MinPositive Minimum representable positive value in E5M2 format (smallest subnormal: 2^-16).
Float8E5M2 NaN Represents NaN (Not a Number).
Float8E5M2 NegativeInfinity Represents negative infinity.
Float8E5M2 One Represents positive one.
Float8E5M2 PositiveInfinity Represents positive infinity.
Float8E5M2 Zero Represents positive zero.