Convert format
convert_formatConverts values or bit patterns between floating-point and integer formats, returning encoding details and precision-loss analysis for each representation.
Instructions
Convert a value or bit pattern from one floating-point or integer format to another. Returns full encoding details for both formats and precision loss analysis.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| bits | No | The source as a bit pattern in the input format, binary (e.g. "0011110000000000") or hex with 0x prefix (e.g. "0x3C00"), read as decode_bits reads it and converted exactly as given. Use it to convert an exact encoding such as a NaN with a sign and payload. Exactly one of "value" and "bits" is required. | |
| value | No | The value to convert. Accepts a number, hex string (read as an integer, e.g. "0xFF" is 255), or keyword. Exactly one of "value" and "bits" is required. | |
| nanMode | No | What a NaN source operand becomes; it has no effect on any other input. "canonical" gives the output format's canonical quiet NaN. "preserve" keeps the sign and as many high-order payload bits as fit, and quiets the result (IEEE 754-2019 §6.2.3). Default "canonical". Only a "bits" source has a payload to keep. | |
| inputFormat | Yes | Source format preset key or custom format object. | |
| outputFormat | Yes | Target format preset key or custom format object. | |
| overflowMode | No | What an out-of-range output magnitude becomes; the source operand is built with the input format's defaults. "overflow" produces Infinity (or NaN when the format has no Infinity); "saturate" clamps to the largest finite value. Omit to use the per-format default. IEEE 754 §7.4 directed rounding still clamps finite overflow regardless. | |
| roundingMode | No | Rounding mode for encoding into the output format; the source operand is built with the input format's defaults. Options: "tiesToEven" (default, IEEE 754), "tiesToAway", "towardZero", "towardPositive", "towardNegative". |