type.c
April 3, 2026 ยท View on GitHub
Purpose
Small conversion helpers for float bits, printable checks and human-readable size formatting.
API Reference
uint32_t XFloatToU32(float fValue)
- Arguments:
- floating-point value.
- Does:
- reinterprets the float bits through a shared global union.
- Returns:
- raw
uint32_tbit pattern.
- raw
float XU32ToFloat(uint32_t nValue)
- Arguments:
- raw 32-bit bit pattern.
- Does:
- reinterprets the bits as
float.
- reinterprets the bits as
- Returns:
- floating-point value.
xbool_t XTypeIsPrint(const uint8_t *pData, size_t nSize)
- Arguments:
- byte buffer and max length.
- Does:
- checks bytes until either
nSizeis exhausted or the first NUL byte is seen. - fails on the first non-printable byte.
- checks bytes until either
- Returns:
XTRUEwhen all examined bytes are printable.XFALSEotherwise.
size_t XBytesToUnit(char *pDst, size_t nSize, size_t nBytes, xbool_t bShort)
- Arguments:
- destination buffer, size, byte count and short-format flag.
- Does:
- formats bytes as
B,KB,MBorGB. - uses one decimal in short mode, two decimals in long mode, except GB which is formatted without decimals.
- formats bytes as
- Returns:
- written length.
size_t XKBToUnit(char *pDst, size_t nSize, size_t nKB, xbool_t bShort)
- Arguments:
- destination buffer, size, kilobyte count and short-format flag.
- Does:
- formats values as
K,M,GorT/KB,MB,GB,TB.
- formats values as
- Returns:
- written length.
Important Notes
XFloatToU32()/XU32ToFloat()use one shared global union, so they are not independently thread-safe storage primitives.- These helpers are for display and quick conversions, not stable serialization formats.