nx_q14_format.nx
buildroot/runtime/nx_q14_format.nx
about
nx_q14_format.nx -- Q14 fixed-point i64 -> decimal ASCII string.
Required by:
- nx_gcode_emit (every X/Y/Z/E coordinate is a decimal text token)
- audit dashboards + debug logs (Q14 coords must be human-readable)
- operator-facing print summaries ("305.250mm × 305.250mm × ...")
Two entry points:
nx_int_to_decimal(value, buf, cap)
basic signed i64 -> ASCII (no fractional part)
nx_q14_to_decimal(value_q14, buf, cap, frac_digits)
signed Q14 i64 -> "<int>.<frac>" with frac_digits decimals
Behaviour:
- Both write to caller-owned buf; do NOT NUL-terminate; return
byte count written.
- Negative inputs prefix "-".
- frac_digits = 0 produces no decimal point.
- Capacity check: returns -1 if buf would overflow.
- Round-toward-zero on the fractional part (no rounding).
Slicer + G-code use canonical Q14 representation throughout;
rounding policy lives in the slicer, not the formatter.
Q14 1 unit = 1/16384 = ~0.000061. Three fractional digits captures
most operator-relevant precision (0.001 mm = 16.384 Q14 units; well
above the formatter's truncation error).
license_tier: ORIGINAL
dependencies 1 imports · 2 importers
imports: nx_syscalls.nx
imported by: nx_gcode_emit.nxnx_q14_format_test.nx
structs
| none |
consts
| 32 | const NX_Q14_ONE: i64 = 16384 |
functions
| 35 | func nx_fmt_reverse(buf: *u8, lo: i64, hi: i64) -> i64 called by 1: nx_int_to_decimal |
| 49 | func nx_int_to_decimal(value: i64, buf: *u8, capacity: i64) -> i64 |
| 81 | func nx_q14_to_decimal(value_q14: i64, buf: *u8, capacity: i64, |