XFL Visualizer

The XFL (eXtended Financial Ledger) format is a proposed representation for numbers within the XRP Ledger (XRPL) that aims to simplify the handling of different types of balances, namely native XRP balances and IOU/Token trustline balances. The XFL format is designed to be easy to use and compatible across various processors and platforms.

The XFL format encodes numbers into a signed 64-bit integer, which includes a sign bit, an exponent, and a mantissa. This format allows for a unified way to represent both native XRP balances and trustline balances, making it easier for developers to perform computations between these two number formats.

Here's a breakdown of the XFL format:

  • Enclosing Sign Bit (bit 63): Always 0 for a valid XFL number.
  • Internal Sign Bit (bit 62): Indicates the sign of the number (0 for negative, 1 for positive).
  • Exponent (bits 61-53): A biased exponent where 0b000000000 represents 10^(-97).
  • Mantissa (bits 52-0): A normalized value between 10^15 and 10^16 - 1.

The XFL Tools would include functions to convert decimal numbers to the XFL format and vice versa. Below is a conceptual explanation of how these tools might work:

Converting a Decimal to XFL

  1. Normalization: The decimal number is normalized such that the mantissa is between 10^15 and 10^16 - 1. This may involve adjusting the exponent accordingly.
  2. Encoding: The normalized mantissa and exponent are encoded into the 64-bit integer format, taking care to set the internal sign bit based on the sign of the decimal number.
  3. Error Handling: If the number cannot be represented due to underflow or overflow, an error code (an invalid XFL value) is returned.
export function xflToHex(value: XFL): string {
  if (value === 0) {
    return '0000000000000000'
  }
  return floatToLEXfl(String(value))
}

Converting XFL to Decimal

  1. Decoding: The 64-bit integer is decoded to extract the sign, exponent, and mantissa.
  2. Denormalization: The mantissa is adjusted by the exponent to convert it back to a decimal number.
  3. Applying Sign: The sign bit is used to determine if the resulting decimal should be negative or positive.
export function hexToXfl(hex: string): XFL {
  if (hex === '0000000000000000') {
    return 0
  }
  const value = flipHex(hex)
  const xfl = hexToUInt64(value.slice(0, 16))
  return parseFloat(toString(xfl))
}

Was this page helpful?