Function encodedNumber

  • Return a boxed number encoded in the desired (often non-optimal) format. This might be used for APIs that have strict encoding requirements where the normal JS number does not always create the correct encoding. NOTES: -0 is always encoded as -0, without simplification, as long as the selected encoding is floating point. Otherwise, -0 causes an error. You MUST NOT use the ignoreOriginalEncoding option when encoding these numbers, or the encoding that is stored along with the boxed number will be ignored. The cde and dcbor options turn on ignoreOriginalEncoding by default, so it must be exlicitly disabled.

    Parameters

    • value: number | bigint

      Number to be encoded later

    • encoding: "bigint"

      Desired encoding. Default: 'f', which uses the preferred float encoding, even for integers.

    Returns BigInt

    Boxed number or bigint object with hidden property set containing the desired encoding.

    const num = encodedNumber(2, 'i32');
    // [Number: 2]
    const enc = encode(num, {cde: true, ignoreOriginalEncoding: false});
    // Uint8Array(3) [ 25, 0, 2 ]
  • Return a boxed number encoded in the desired (often non-optimal) format. This might be used for APIs that have strict encoding requirements where the normal JS number does not always create the correct encoding. NOTES: -0 is always encoded as -0, without simplification, as long as the selected encoding is floating point. Otherwise, -0 causes an error. You MUST NOT use the ignoreOriginalEncoding option when encoding these numbers, or the encoding that is stored along with the boxed number will be ignored. The cde and dcbor options turn on ignoreOriginalEncoding by default, so it must be exlicitly disabled.

    Parameters

    • value: number | bigint

      Number to be encoded later

    • encoding: "i" | "i64"

      Desired encoding. Default: 'f', which uses the preferred float encoding, even for integers.

    • OptionalmajorType: number

    Returns Number | BigInt

    Boxed number or bigint object with hidden property set containing the desired encoding.

    const num = encodedNumber(2, 'i32');
    // [Number: 2]
    const enc = encode(num, {cde: true, ignoreOriginalEncoding: false});
    // Uint8Array(3) [ 25, 0, 2 ]
  • Return a boxed number encoded in the desired (often non-optimal) format. This might be used for APIs that have strict encoding requirements where the normal JS number does not always create the correct encoding. NOTES: -0 is always encoded as -0, without simplification, as long as the selected encoding is floating point. Otherwise, -0 causes an error. You MUST NOT use the ignoreOriginalEncoding option when encoding these numbers, or the encoding that is stored along with the boxed number will be ignored. The cde and dcbor options turn on ignoreOriginalEncoding by default, so it must be exlicitly disabled.

    Parameters

    • value: number | bigint

      Number to be encoded later

    • encoding: "i0" | "i8" | "i16" | "i32"

      Desired encoding. Default: 'f', which uses the preferred float encoding, even for integers.

    • OptionalmajorType: number

    Returns Number

    Boxed number or bigint object with hidden property set containing the desired encoding.

    const num = encodedNumber(2, 'i32');
    // [Number: 2]
    const enc = encode(num, {cde: true, ignoreOriginalEncoding: false});
    // Uint8Array(3) [ 25, 0, 2 ]
  • Return a boxed number encoded in the desired (often non-optimal) format. This might be used for APIs that have strict encoding requirements where the normal JS number does not always create the correct encoding. NOTES: -0 is always encoded as -0, without simplification, as long as the selected encoding is floating point. Otherwise, -0 causes an error. You MUST NOT use the ignoreOriginalEncoding option when encoding these numbers, or the encoding that is stored along with the boxed number will be ignored. The cde and dcbor options turn on ignoreOriginalEncoding by default, so it must be exlicitly disabled.

    Parameters

    • value: number | bigint

      Number to be encoded later

    • Optionalencoding: "f" | "f16" | "f32" | "f64"

      Desired encoding. Default: 'f', which uses the preferred float encoding, even for integers.

    Returns Number

    Boxed number or bigint object with hidden property set containing the desired encoding.

    const num = encodedNumber(2, 'i32');
    // [Number: 2]
    const enc = encode(num, {cde: true, ignoreOriginalEncoding: false});
    // Uint8Array(3) [ 25, 0, 2 ]