NAME
Q_QADDQ
, Q_QDIVQ
,
Q_QMULQ
, Q_QSUBQ
,
Q_NORMPREC
, Q_QMAXQ
,
Q_QMINQ
, Q_QCLONEQ
,
Q_CPYVALQ
—
fixed-point math functions which
operate on two Q numbers
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
TheQ_QADDQ
(),
Q_QDIVQ
(),
Q_QMULQ
(),
and
Q_QSUBQ
()
functions add, divide, multiply or subtract b to/by/from
a respectively, storing the result in
a. Both arguments must be initialized with the same
fractional radix point.
The
Q_NORMPREC
()
function attempts to normalise the precision of a and
b if they differ. 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.
The
Q_QMAXQ
()
and
Q_QMINQ
()
functions 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. 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 are referred 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
is returned for divide-by-zero.
EOVERFLOW
and ERANGE
are
returned for overflow and underflow respectively. ERANGE is
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
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.