Q_QADDQ(3)
π Q_QADDQ(3) β the fixed-point girlies' manual π
ok so bestie, welcome to qmath.h's greatest hits π this is the crew of fixed-point math functions that all work on two Q numbers at once, and no cap, they're lowkey iconic. (the manual name is right there in the title btw, Q_QADDQ(3), iykyk π)
β¨ SYNOPSIS β¨
#include <sys/qmath.h>
int
Q_QADDQ(QTYPE *a, QTYPE b);
int
Q_QDIVQ(QTYPE *a, QTYPE b);
int
Q_QMULQ(QTYPE *a, QTYPE b);
int
Q_QSUBQ(QTYPE *a, QTYPE b);
int
Q_NORMPREC(QTYPE *a, QTYPE *b);
QTYPE
Q_QMAXQ(QTYPE a, QTYPE b);
QTYPE
Q_QMINQ(QTYPE a, QTYPE b);
int
Q_QCLONEQ(QTYPE *l, QTYPE r);
int
Q_QCPYVALQ(QTYPE *l, QTYPE r);
πΈ DESCRIPTION πΈ
okay so first up: Q_QADDQ(), Q_QDIVQ(), Q_QMULQ(), and Q_QSUBQ() are your basic math besties β they add, divide, multiply or subtract b to/by/from a respectively, and the result gets stored right back in a π«Ά. Important though: both arguments have to be initialized with the same fractional radix point. fr fr, that's not a vibe check you wanna fail π.
Then there's Q_NORMPREC(), which attempts to normalise the precision of a and b if they differ β¨. The tea: the greater of the two precisions is preferred if possible, unless that would truncate integer component data for the other operand β in which case the highest precision that preserves the integer component of both a and b is selected. she's diplomatic like that π
Q_QMAXQ() and Q_QMINQ() are literally just vibes: they return the larger or smaller of a and b respectively π₯.
The Q_QCLONEQ() and Q_QCPYVALQ() functions attempt to store identical or representational copies of r, in l respectively π. So, what's the difference?
- An identical Q number produced by cloning copies the control bits as well as the verbatim integer/fractional bits π―
- A representational copy only copies the values of
r's integer and fractional bits, representing them in the bits available perl's Q format π
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 we refer to generically as QTYPE π.
For more details, see qmath(3) π¦.
β RETURN VALUES β
The Q_QADDQ(), Q_QDIVQ(), Q_QMULQ(), Q_QSUBQ(), Q_NORMPREC(), Q_QCLONEQ() and Q_QCPYVALQ() functions return 0 on success, or an errno on failure:
EINVALβ returned for divide-by-zero π (bestie. don't.)EOVERFLOWβ returned for overflow πERANGEβ returned for underflow, and also returned when the precision of arguments does not match π
The Q_QMAXQ() and Q_QMINQ() functions return the numerically larger or smaller of their two inputs respectively β¨.
π¦ SEE ALSO π¦
errno(2), qmath(3), stdint(7) β go read 'em, they're giving required reading π
π§ HISTORY π§
The qmath(3) functions first appeared in FreeBSD 13.0 β
π 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 page, bestie β no crumbs left behind π mwah!
this lil bundle of joy ships with Debian, last touched July 8, 2018 β like, the date is literally right there in the footer, so jot it down π
π¦ 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