Q_QADDI(3)
π Q_QADDI(3) β bestie's guide to the qmath integer-math squad π
ok so real talk: this is from the Library Functions Manual, and it's about the fixed-point math functions that apply plain integers to a Q number. yes, plural, there's a whole little friend group of them and we're meeting all six. sit down, hydrate, let's go β¨
πΈ NAME πΈ
Q_QADDI, Q_QDIVI, Q_QMULI, Q_QSUBI, Q_QFRACI, Q_QCPYVALI β the fixed-point math functions which apply integers to a Q number. that's the whole vibe. six functions, one mission, zero cap π
β¨ SYNOPSIS β¨
ok here's the lineup, and yes you include the header first, always:
#include <sys/qmath.h>
int
Q_QADDI(QTYPE *a, ITYPE b);
int
Q_QDIVI(QTYPE *a, ITYPE b);
int
Q_QMULI(QTYPE *a, ITYPE b);
int
Q_QSUBI(QTYPE *a, ITYPE b);
int
Q_QFRACI(QTYPE *q, ITYPE n, ITYPE d);
int
Q_QCPYVALI(QTYPE *q, ITYPE i);
every single one of them returns an int, and the args are exactly as shown β QTYPE pointer first, ITYPE after. don't go rearranging them, they're not that kind of function π«Ά
π¦ DESCRIPTION π¦
ok so the first four are the classic arithmetic girlies. Q_QADDI(), Q_QDIVI(), Q_QMULI() and Q_QSUBI() will add, divide, multiply or subtract b to/by/from a respectively β and the result gets stored right back in a. in place. main character energy, it's all about a π
(quick read of that: Q_QADDI() does a + b, Q_QDIVI() does a / b, Q_QMULI() does a * b, Q_QSUBI() does a - b. all landing back in a. iconic.)
then there's Q_QFRACI(), our fraction specialist π β it computes the fraction n divided by d and stores the fixed-point result in q. so like, numerator over denominator, but the answer's fixed-point and it lives in q. periodt.
and finally Q_QCPYVALI(), the glow-up function π β it overwrites q's integer and fractional bits with the Q representation of the integer value i. both sets of bits. gone, replaced, reborn. not me being dramatic about a copy operation π
now, the types. all of those functions operate on the following data types, and honestly this is the part you screenshot for later:
s8q_tu8q_ts16q_tu16q_ts32q_tu32q_ts64q_tu64q_t
which are all referred to generically as QTYPE. and the ITYPE? that one refers to the stdint(7) integer types. yes there's a whole other manpage for those, iykyk.
for more details (and there ARE more details, bestie), go see qmath(3). π§
π₯ RETURN VALUES π₯
ok the vibe check on what comes back:
Q_QADDI(),Q_QDIVI(),Q_QMULI(),Q_QSUBI(),Q_QFRACI()andQ_QCPYVALI()all return0on success β¨- or an
errnoon failure. yeah. not vibes. EINVALgets returned for divide-by-zero β like, obviously, you cannot do that, and the function WILL call you out πEOVERFLOWcomes back for overflowERANGEcomes back for underflow
so 0 = slay, everything else = read the errno and figure out your life π
π SEE ALSO π
go touch these for more lore:
β HISTORY β
the qmath(3) functions first appeared in FreeBSD 13.0. a whole era. we stan a documented origin story π
π AUTHORS π
the qmath(3) functions and this manual page were written by Lawrence Stewart <lstewart@FreeBSD.org> and sponsored by Netflix, Inc. β so yes, your fixed-point math is brought to you by the same people who brought you the "are you still watching?" jump scare π sponsorship slays though, fr fr π«Ά
and that's the page! this lil drop was from the Debian edition, dated July 8, 2018 β shoutout to the footer, we remembered you πβ¨ no cap, now go do some fixed-point math responsibly. πΈπ¦π
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- 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