---
name: "Q_QDIVI"
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_QADDI"
---

# Q\_QDIVI(3)

fixed-point math functions which apply integers to a Q number

Part of [Q\_QADDI(3)](/Q_QADDI/3.md).

## NAME

**Q\_QADDI**, **Q\_QDIVI**, **Q\_QMULI**, **Q\_QSUBI**, **Q\_QFRACI**, **Q\_QCPYVALI** – fixed-point math functions which apply integers to a Q number

## SYNOPSIS

**#include \<sys/qmath.h\>**

*int*\

**Q\_QADDI**(*QTYPE \*a*, *ITYPE b*);

*int*\

**Q\_QDIVI**(*QTYPE \*a*, *ITYPE b*);

*int*\

**Q\_QMULI**(*QTYPE \*a*, *ITYPE b*);

*int*\

**Q\_QSUBI**(*QTYPE \*a*, *ITYPE b*);

*int*\

**Q\_QFRACI**(*QTYPE \*q*, *ITYPE n*, *ITYPE d*);

*int*\

**Q\_QCPYVALI**(*QTYPE \*q*, *ITYPE i*);

## DESCRIPTION

The **Q\_QADDI**(), **Q\_QDIVI**(), **Q\_QMULI**() and **Q\_QSUBI**() functions add, divide, multiply or subtract *b* to/by/from *a* respectively, storing the result in *a*.

The **Q\_QFRACI**() function computes the fraction *n* divided by *d* and stores the fixed-point result in *q*.

The **Q\_QCPYVALI**() function overwrites *q*'s integer and fractional bits with the Q representation of integer value *i*.

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)](/stdint/7.md) integer types.

For more details, see [qmath(3)](/qmath/3.md).

## RETURN VALUES

**Q\_QADDI**(), **Q\_QDIVI**(), **Q\_QMULI**(), **Q\_QSUBI**(), **Q\_QFRACI**() and **Q\_QCPYVALI**() 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.

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