Q_INI(3)
π NAME π
okay bestie, this is the Q_INI(3) page from the Library Functions Manual, and itβs giving fixed-point math miscellaneous functions/variables. The whole squad is: Q_INI, Q_NCBITS, Q_BT, Q_TC, Q_NTBITS, Q_NFCBITS, Q_MAXNFBITS, Q_NFBITS, Q_NIBITS, Q_RPSHFT, Q_ABS, Q_MAXSTRLEN, Q_TOSTR, Q_SHL, Q_SHR, Q_DEBUG.
β¨ SYNOPSIS β¨
Hereβs the cast in code form, no edits, periodt:
#include <sys/qmath.h>
QTYPE
Q_INI(QTYPE *q, ITYPE iv, ITYPE dfv, int rpshft);
Q_NCBITS
__typeof(q)
Q_BT(QTYPE q);
ITYPE
Q_TC(QTYPE q, ITYPE v);
uint32_t
Q_NTBITS(QTYPE q);
uint32_t
Q_NFCBITS(QTYPE q);
uint32_t
Q_MAXNFBITS(QTYPE q);
uint32_t
Q_NFBITS(QTYPE q);
uint32_t
Q_NIBITS(QTYPE q);
uint32_t
Q_RPSHFT(QTYPE q);
NTYPE
Q_ABS(NTYPE n);
uint32_t
Q_MAXSTRLEN(QTYPE q, int base);
char *
Q_TOSTR(QTYPE q, int prec, int base, char *s, int slen);
ITYPE
Q_SHL(QTYPE q, ITYPE iv);
ITYPE
Q_SHR(QTYPE q, ITYPE iv);
char *, ...
Q_DEBUG(QTYPE q, char *prefmt, char *postfmt, incfmt);
ITYPE
Q_DFV2BFV(ITYPE dfv, int nfbits);
π DESCRIPTION π
Q_INI()β initialises a Q number with the integral valueivand decimal fractional valuedfv, and sets appropriate control bits based on the requested radix shift pointrpshft. Tiny but crucial detail:dfvmust be passed as a preprocessor literal to preserve leading zeroes. no cap, it matters.Q_NCBITSβ this defined constant is the number of reserved control bits, and currently itβs3. slay.Q_NTBITS(),Q_NFCBITS(),Q_MAXNFBITS(),Q_NFBITS(), andQ_NIBITS()β return the q-specific count of total, control-encoded fractional, maximum fractional, effective fractional, and integer bits applicable toq, respectively. yes, that whole lineup, each with its own job.Q_BT()β returns the C data type ofq.Q_TC()β returnsvtype casted to the C data type ofq.Q_RPSHFT()β returns the bit position ofqβs binary radix point relative to bit zero.Q_ABS()β returns the absolute value of any standard numeric type passed in asnβ one of those types that uses the MSB as a sign bit, but not Q numbers. This function is signed/unsigned type safe.Q_SHL()andQ_SHR()β return the integral valuev(theivargument) left or right shifted by the appropriate amount forq.Q_MAXSTRLEN()β calculates the maximum number of characters that may be required to render the C-string representation ofqwith numeric basebase.Q_TOSTR()β renders the C-string representation ofqwith numeric basebaseand fractional precisionprecintos, which has an available capacity ofslencharacters.basemust be in range[2,16]. Specifyingprecas-1renders the numberβs fractional component with maximum precision. Ifslenis greater than zero but insufficient to hold the complete C-string, the'\0'C-string terminator will be written to*s, thereby returning a zero length C-string.Q_DEBUG()β returns a format string and associated data suitable for printf-like rendering of debugging information pertaining toq. If eitherprefmtand/orpostfmtare specified, they are prepended and appended to the resulting format string respectively. Theincfmtboolean specifies whether to include (true) or exclude (false) the raw format string itself in the debugging output.Q_DFV2BFV()β converts decimal fractional valuedfvto its binary-encoded representation withnfbitsof binary precision. Again,dfvmust be passed as a preprocessor literal to preserve leading zeroes. The returned value can be used to set a Q numberβs fractional bits, for example usingQ_SFVAL().
All of those functions operate on the following data types: s8q_t, u8q_t, s16q_t, u16q_t, s32q_t, u32q_t, s64q_t, and u64q_t, which are referred to generically as QTYPE. The ITYPE refers to the stdint(7) integer types. NTYPE is used to refer to any numeric type and is therefore a superset of QTYPE and ITYPE.
For more details, see qmath(3). π«Ά
π RETURN VALUES π
Q_INI()β returns the initialised Q number, which can be used to chain initialise additional Q numbers. cute, efficient, iconic.Q_TOSTR()β returns a pointer to the'\0'C-string terminator appended tosafter the rendered numeric data, orNULLon buffer overflow.Q_DFV2BFV()β returns the binary-encoded representation of decimal fractional valuedfvwithnfbitsof binary precision.
π¦ SEE ALSO π¦
errno(2), qmath(3), stdint(7) β go peek, bestie.
β HISTORY β
The qmath(3) functions first appeared in FreeBSD 13.0. a moment of silence for the lore.
π AUTHORS π
The qmath(3) functions and this manual page were written by Lawrence Stewart <lstewart@FreeBSD.org> and sponsored by Netflix, Inc.
and thatβs the whole vibe β footer says Debian, July 8, 2018, Q_INI(3). youβre so welcome, bestie π
β¨
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright (c) 2018 Netflix, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms