Fixed Point Integer Encoder

Encode exact decimal text on a binary fixed-point grid; rejects values requiring rounding.

Description

Encode exact decimal text on a binary fixed-point grid; rejects values requiring rounding.

Encoding a decimal exactly on a binary grid requires divisibility, not merely an approximate nearby value.

When to use this tool

Encode exact decimal text on a binary fixed-point grid; rejects values requiring rounding.

  • Prepare the supplied decimal, fractionalBits fields for this operation.
  • Compare the complete example with the representation used by your own input before carrying the result into another step.

How to use the tool and how it works

  1. Enter decimal, fractionalBits. Use the exact text syntax, units and index conventions explained below.
  2. Run the tool. If input validation fails, correct the supplied fields before interpreting any result.
  3. Read result.integer. Interpret false, null and empty lists using the distinctions below; they can be valid outputs.

Parse decimal as an exact fraction and multiply its numerator by 2^fractionalBits. Require divisibility by denominator, then return the exact quotient as integer text.1

Input fieldMeaning and representationAccepted input
decimaldecimal.Text; at most 8,192 UTF-16 code units, subject to the grammar above
fractionalBitsfractional bits.Integer from 0 to 128 inclusive
Output fieldInterpretation
resultObject containing the named outputs below.
result.integerExact decimal integer text under the operation described above.
json
{
  "input": {
    "decimal": "1.25",
    "fractionalBits": 3
  },
  "output": {
    "result": {
      "integer": "10"
    }
  }
}

Limitations and assumptions

  • Nonrepresentable values are input errors instead of being rounded. No signed/unsigned storage width is imposed.
  • Exact decimal-spelling operations require digits before the optional decimal point and allow a signed exponent. Decimal text is bounded to 256 code units and effective scale to minus 256 through 256; integer-string fields allow a sign and up to 256 digits.
  • Every declared top-level field is required and unexpected fields are rejected. Numeric inputs must be finite; ordinary text fields are bounded to 8,192 UTF-16 code units, with tighter operation-specific limits where stated.
  • Lists are limited to 128 entries. JSON text must meet bounded size and depth checks, and numeric outputs beyond the safe finite magnitude are rejected. Exact large integers use decimal strings.
  • Indexes are zero-based and spans have an exclusive end unless explicitly stated otherwise. A valid false, null or empty-list result is distinct from malformed input.

Alternative or Complementary methods

Preserve decimal and integer strings when exact comparisons matter. Select signedness, scale, rounding and overflow policies separately, and use the matching encoder/decoder rather than a floating-point approximation.

References

  1. Tool behavior and example: Fixed Point Integer Encoder — tool.io

Similar or alternative tools

Don't forget to set a bookmark for tool.io!
Privacy | Imprint | Cookies