Q_SIGNED, Q_LTZ,
Q_PRECEQ, Q_QLTQ,
Q_QLEQ, Q_QGTQ,
Q_QGEQ, Q_QEQ,
Q_QNEQ, Q_OFLOW,
Q_RELPREC — fixed-point math
comparison and logic functions
#include
<sys/qmath.h>
bool
Q_SIGNED(NTYPE
n);
bool
Q_LTZ(NTYPE
n);
bool
Q_PRECEQ(QTYPE
a, QTYPE b);
bool
Q_QLTQ(QTYPE
a, QTYPE b);
bool
Q_QLEQ(QTYPE
a, QTYPE b);
bool
Q_QGTQ(QTYPE
a, QTYPE b);
bool
Q_QGEQ(QTYPE
a, QTYPE b);
bool
Q_QEQ(QTYPE
a, QTYPE b);
bool
Q_QNEQ(QTYPE
a, QTYPE b);
bool
Q_OFLOW(QTYPE
q, ITYPE iv);
int
Q_RELPREC(QTYPE
a, QTYPE b);
Q_SIGNED()
returns true if the numeric data type passed in as
n is signed, or false
otherwise.
Q_LTZ()
returns true if the numeric value passed in as
n is negative (requires types which use the MSB as the
sign bit), or false otherwise.
Q_PRECEQ()
returns true if the number of a
and b fractional bits is the same,
false otherwise.
The
Q_QLTQ(),
Q_QLEQ(),
Q_QGTQ(),
Q_QGEQ(),
Q_QEQ()
and
Q_QNEQ()
functions compare two Q numbers, returning true if
a is less than, less than or equal to, greater than,
greater than or equal to, equal to, or not equal to b
respectively, or false otherwise. The integral and
fractional values are used to perform the comparison, without explicit
concern for the underlying number of integer versus fractional bits.
Q_OFLOW()
returns true if integer value iv
cannot be stored in q without truncation, or false
otherwise.
Q_RELPREC()
returns the relative precision of a versus
b. In terms of
Qm.n
notation, this function returns the difference between the
n values of
a and b. For example, a return
value of +4 means that a has an additional 4 bits of
fractional precision compared to b.
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).
The Q_SIGNED(),
Q_LTZ(), Q_PRECEQ(),
Q_QLTQ(), Q_QLEQ(),
Q_QGTQ(), Q_QGEQ(),
Q_QEQ(), Q_QNEQ() and
Q_OFLOW() functions return expressions that evaluate
to boolean true or false.
Q_RELPREC() returns the relative precision
difference as a signed integer.
The
qmath(3)
functions first appeared in FreeBSD 13.0.