Q_QADDQ(3)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1

πŸ’… 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 per l'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