Class/Object

com.stripe.agate.tensor

BFloat16

Related Docs: object BFloat16 | package tensor

Permalink

final class BFloat16 extends AnyVal

BFloat16 represents 16-bit floating-point values.

This type does not actually support arithmetic directly. The expected use case is to convert to Float to perform any actual arithmetic, then convert back to a BFloat16 if needed.

Binary representation:

sign (1 bit) | | exponent (8 bits) | | | | mantissa (7 bits) | | | x xxxxxxxx xxxxxxx

Value interpretation (in order of precedence, with _ wild):

0 00000000 0000000 (positive) zero 1 00000000 0000000 negative zero _ 00000000 _ subnormal number _ 11111111 0000000 +/- infinity _ 11111111 _ not-a-number _ _ normal number

An exponent of all 1s signals a sentinel (NaN or infinity), and all 0s signals a subnormal number. So the working "real" range of exponents we can express is [-126, +127].

For non-zero exponents, the mantissa has an implied leading 1 bit, so 7 bits of data provide 8 bits of precision for normal numbers.

For normal numbers:

x = (1 - sign*2) * 2^exponent * (1 + mantissa/128)

For subnormal numbers, the implied leading 1 bit is absent. Thus, subnormal numbers have the same exponent as the smallest normal numbers, but without an implied 1 bit.

So for subnormal numbers:

x = (1 - sign*2) * 2^(-127) * (mantissa/128)

Self Type
BFloat16
Linear Supertypes
AnyVal, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. BFloat16
  2. AnyVal
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new BFloat16(raw: Short)

    Permalink

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    Any
  3. def *(rhs: BFloat16): BFloat16

    Permalink
  4. def **(rhs: Int): BFloat16

    Permalink
  5. def +(rhs: BFloat16): BFloat16

    Permalink
  6. def -(rhs: BFloat16): BFloat16

    Permalink
  7. def /(rhs: BFloat16): BFloat16

    Permalink
  8. def <(rhs: BFloat16): Boolean

    Permalink
  9. def <=(rhs: BFloat16): Boolean

    Permalink
  10. def ==(rhs: BFloat16): Boolean

    Permalink
  11. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    Any
  12. def >(rhs: BFloat16): Boolean

    Permalink
  13. def >=(rhs: BFloat16): Boolean

    Permalink
  14. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  15. def compare(rhs: BFloat16): Int

    Permalink
  16. def getClass(): Class[_ <: AnyVal]

    Permalink
    Definition Classes
    AnyVal → Any
  17. def isFinite: Boolean

    Permalink

    Whether this BFloat16 value is finite or not.

    Whether this BFloat16 value is finite or not.

    For the purposes of this method, infinities and NaNs are considered non-finite. For those values it returns false and for all other values it returns true.

  18. def isInfinite: Boolean

    Permalink
  19. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  20. def isNaN: Boolean

    Permalink
  21. def isNegativeInfinity: Boolean

    Permalink
  22. def isNegativeZero: Boolean

    Permalink
  23. def isPositiveInfinity: Boolean

    Permalink
  24. def isPositiveZero: Boolean

    Permalink
  25. def isSubnormal: Boolean

    Permalink
  26. def isZero: Boolean

    Permalink

    Returns if this is a zero value (positive or negative).

  27. def nonNaN: Boolean

    Permalink
  28. def nonZero: Boolean

    Permalink
  29. val raw: Short

    Permalink
  30. def signum: Float

    Permalink

    Return the sign of a BFloat16 value as a Float.

    Return the sign of a BFloat16 value as a Float.

    There are five possible return values:

    * NaN: the value is BFloat16.NaN (and has no sign) * -1F: the value is a non-zero negative number * -0F: the value is BFloat16.NegativeZero * 0F: the value is BFloat16.Zero * 1F: the value is a non-zero positive number

    PositiveInfinity and NegativeInfinity return their expected signs.

  31. def toDouble: Double

    Permalink
  32. def toFloat: Float

    Permalink

    Convert this BFloat16 value to the nearest Float.

    Convert this BFloat16 value to the nearest Float.

    Unlike Float16, since BFloat16 has the same size exponents as Float32 it means that all we have to do is add some extra zeros to the mantissa.

  33. def toString(): String

    Permalink

    String representation of this BFloat16 value.

    String representation of this BFloat16 value.

    Definition Classes
    BFloat16 → Any
  34. def unary_-: BFloat16

    Permalink

    Reverse the sign of this BFloat16 value.

    Reverse the sign of this BFloat16 value.

    This just involves toggling the sign bit with XOR.

    -BFloat16.NaN has no meaningful effect. -BFloat16.Zero returns BFloat16.NegativeZero.

Inherited from AnyVal

Inherited from Any

Ungrouped