Encode number
encode_numberEncode a decimal or special value such as Infinity or NaN into a chosen floating-point or integer format, returning binary, hex, and component breakdown.
Instructions
Encode a decimal number (or special value like Infinity / NaN) into a specified floating-point or integer format. Returns binary, hex, and component breakdown.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| value | Yes | The value to encode. Accepts a number, hex string (e.g. "0xFF"), or keyword ("infinity", "-infinity", "nan"). | |
| format | Yes | Format preset key (e.g. "fp32", "int8") or custom format object. For floating-point: { signBits, exponentBits, mantissaBits, bias?, hasInfinity?, hasNaN?, hasSubnormals? }. For integer: { bits, signed, fractionBits?, symmetric? }. | |
| overflowMode | No | What an out-of-range magnitude becomes. "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 (overflow for formats with Infinity, saturate otherwise). IEEE 754 §7.4 directed rounding still clamps finite overflow regardless of this setting. | |
| roundingMode | No | Rounding mode for encoding the value. Options: "tiesToEven" (default, IEEE 754), "tiesToAway", "towardZero", "towardPositive", "towardNegative". |