xref: /freebsd/share/man/man3/Q_QADDI.3 (revision 02e9120893770924227138ba49df1edb3896112a)
1.\"
2.\" Copyright (c) 2018 Netflix, Inc.
3.\" All rights reserved.
4.\"
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
8.\" 1. Redistributions of source code must retain the above copyright
9.\"    notice, this list of conditions, and the following disclaimer,
10.\"    without modification, immediately at the beginning of the file.
11.\" 2. The name of the author may not be used to endorse or promote products
12.\"    derived from this software without specific prior written permission.
13.\"
14.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
18.\" ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24.\" SUCH DAMAGE.
25.\"
26.Dd July 8, 2018
27.Dt Q_QADDI 3
28.Os
29.Sh NAME
30.Nm Q_QADDI ,
31.Nm Q_QDIVI ,
32.Nm Q_QMULI ,
33.Nm Q_QSUBI ,
34.Nm Q_QFRACI ,
35.Nm Q_QCPYVALI
36.Nd fixed-point math functions which apply integers to a Q number
37.Sh SYNOPSIS
38.In sys/qmath.h
39.Ft int
40.Fn Q_QADDI "QTYPE *a" "ITYPE b"
41.Ft int
42.Fn Q_QDIVI "QTYPE *a" "ITYPE b"
43.Ft int
44.Fn Q_QMULI "QTYPE *a" "ITYPE b"
45.Ft int
46.Fn Q_QSUBI "QTYPE *a" "ITYPE b"
47.Ft int
48.Fn Q_QFRACI "QTYPE *q" "ITYPE n" "ITYPE d"
49.Ft int
50.Fn Q_QCPYVALI "QTYPE *q" "ITYPE i"
51.Sh DESCRIPTION
52The
53.Fn Q_QADDI ,
54.Fn Q_QDIVI ,
55.Fn Q_QMULI
56and
57.Fn Q_QSUBI
58functions add, divide, multiply or subtract
59.Fa b
60to/by/from
61.Fa a
62respectively, storing the result in
63.Fa a .
64.Pp
65The
66.Fn Q_QFRACI
67function computes the fraction
68.Fa n
69divided by
70.Fa d
71and stores the fixed-point result in
72.Fa q .
73.Pp
74The
75.Fn Q_QCPYVALI
76function overwrites
77.Fa q Ap s
78integer and fractional bits with the Q representation of integer value
79.Fa i .
80.Pp
81All of those functions operate on
82the following data types:
83.Vt s8q_t ,
84.Vt u8q_t ,
85.Vt s16q_t ,
86.Vt u16q_t ,
87.Vt s32q_t ,
88.Vt u32q_t ,
89.Vt s64q_t ,
90and
91.Vt u64q_t ,
92which are referred to generically as
93.Fa QTYPE .
94The
95.Fa ITYPE
96refers to the
97.Xr stdint 7
98integer types.
99.Pp
100For more details, see
101.Xr qmath 3 .
102.Sh RETURN VALUES
103.Fn Q_QADDI ,
104.Fn Q_QDIVI ,
105.Fn Q_QMULI ,
106.Fn Q_QSUBI ,
107.Fn Q_QFRACI
108and
109.Fn Q_QCPYVALI
110functions return 0 on success, or an errno on failure.
111.Er EINVAL
112is returned for divide-by-zero.
113.Er EOVERFLOW
114and
115.Er ERANGE
116are returned for overflow and underflow respectively.
117.Sh SEE ALSO
118.Xr errno 2 ,
119.Xr qmath 3 ,
120.Xr stdint 7
121.Sh HISTORY
122The
123.Xr qmath 3
124functions first appeared in
125.Fx 13.0 .
126.Sh AUTHORS
127.An -nosplit
128The
129.Xr qmath 3
130functions and this manual page were written by
131.An Lawrence Stewart Aq Mt lstewart@FreeBSD.org
132and sponsored by Netflix, Inc.
133