---
name: "Q_NORMPREC"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/Q_NORMPREC"
---

# Q\_NORMPREC(3)

fixed-point math functions which operate on two Q numbers

## 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

The **Q\_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)](/qmath/3.md).

## 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

[errno(2)](/errno/2.md), [qmath(3)](/qmath/3.md), [stdint(7)](/stdint/7.md)

## HISTORY

The [qmath(3)](/qmath/3.md) functions first appeared in FreeBSD 13.0.

## AUTHORS

The [qmath(3)](/qmath/3.md) functions and this manual page were written by Lawrence Stewart ⟨*lstewart@FreeBSD.org*⟩ and sponsored by Netflix, Inc.
