xref: /freebsd/share/man/man3/tgmath.3 (revision 74bf4e164ba5851606a27d4feff27717452583e5)
1.\" Copyright (c) 2004 Stefan Farfeleder
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\"
13.\" THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16.\" ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23.\" SUCH DAMAGE.
24.\"
25.\" $FreeBSD$
26.\"
27.Dd Aug 14, 2004
28.Os
29.Dt TGMATH 3
30.Sh NAME
31.Nm tgmath
32.Nd type-generic macros
33.Sh SYNOPSIS
34.In tgmath.h
35.Sh DESCRIPTION
36The header
37.In tgmath.h
38provides type-generic macros
39for
40.In math.h
41and
42.In complex.h
43functions that have
44.Vt float
45(suffixed with
46.Sm off
47.Sy f )
48,
49.Sm on
50.Vt double
51and
52.Vt long double
53(suffixed with
54.Sy l )
55versions.
56The arguments that vary across the three functions and have type
57.Vt float ,
58.Vt double
59and
60.Vt "long double" ,
61respectively, are called
62.Em generic arguments .
63.Pp
64The following rules describe which function is actually called if a
65type-generic macro is invoked.  If any generic argument has type
66.Vt "long double"
67or
68.Vt "long double complex" ,
69the
70.Vt "long double"
71function is called.  Else if any generic argument has type
72.Vt double ,
73.Vt "double complex"
74or an integer type, the
75.Vt double
76version is invoked.  Otherwise the macro expands to the
77.Vt float
78implementation.
79.Pp
80For the macros in the following table, both real and complex functions
81exist.
82The real functions are prototyped in
83.In math.h
84and the complex equivalents in
85.In complex.h .
86The complex function is called if any of the generic arguments is a
87complex value.
88Otherwise the real equivalent is called.
89.Bl -column -offset indent ".Sy Macro" "Sy real function" ".Sy complex function"
90.It Sy Macro Ta Sy real function Ta Sy complex function
91.It Li acos Ta acos Ta cacos
92.It Li asin Ta asin Ta casin
93.It Li atan Ta atan Ta catan
94.It Li acosh Ta acosh Ta cacosh
95.It Li asinh Ta asinh Ta casinh
96.It Li atanh Ta atanh Ta catanh
97.It Li cos Ta cos Ta ccos
98.It Li sin Ta sin Ta csin
99.It Li tan  Ta tan Ta ctan
100.It Li cosh Ta cosh Ta ccosh
101.It Li sinh Ta sinh Ta csinh
102.It Li tanh Ta tanh Ta ctanh
103.It Li exp Ta exp Ta cexp
104.It Li log Ta log Ta clog
105.It Li pow Ta pow Ta cpow
106.It Li fabs Ta fabs Ta cabs
107.El
108.Pp
109No complex functions exist for the following macros, so passing a
110complex value to a generic argument invokes undefined behaviour:
111.Bl -column -offset indent nexttoward nexttoward nexttoward nexttoward
112.It Li atan2 Ta fma Ta llround Ta remainder
113.It Li cbrt Ta fmax Ta log10 Ta remquo
114.It Li ceil Ta fmin Ta log1p Ta rint
115.It Li copysign Ta fmod Ta log2 Ta round
116.It Li erf Ta frexp Ta logb Ta scalbn
117.It Li erfc Ta hypot Ta lrint Ta scalbln
118.It Li exp2 Ta ilogb Ta lround Ta tgamma
119.It Li expm1 Ta ldexp Ta nextbyint Ta trunc
120.It Li fdim Ta lgamma Ta nextafter
121.It Li floor Ta llrint Ta nexttoward
122.El
123.Pp
124The following macros always expand to a complex function:
125.Bl -column -offset indent cimag cimag cimag cimag cimag
126.It Li carg Ta cimag Ta conj Ta cproj Ta creal
127.El
128.Pp
129This header includes
130.In complex.h
131and
132.In math.h .
133.Sh STANDARDS
134.In tgmath.h
135conforms to
136.St -isoC-99 .
137.Sh HISTORY
138The header
139.In tgmath.h
140first appeared in
141.Fx 5.3 .
142.Sh BUGS
143.In tgmath.h
144cannot be implemented with strictly conforming C code and needs
145special compiler support.  The current implementation only works for GCC.
146.Pp
147Many of the functions mentioned here are not prototyped in
148.In math.h
149or
150.In complex.h
151as they are not yet implemented.
152