xref: /dflybsd-src/share/man/man3/tgmath.3 (revision 31524921f01f28c9bd1362a5c1f73d2d3432d975)
1f619ff77SPeter Avalos.\" Copyright (c) 2004 Stefan Farfeleder
2f619ff77SPeter Avalos.\" All rights reserved.
3f619ff77SPeter Avalos.\"
4f619ff77SPeter Avalos.\" Redistribution and use in source and binary forms, with or without
5f619ff77SPeter Avalos.\" modification, are permitted provided that the following conditions
6f619ff77SPeter Avalos.\" are met:
7f619ff77SPeter Avalos.\" 1. Redistributions of source code must retain the above copyright
8f619ff77SPeter Avalos.\"    notice, this list of conditions and the following disclaimer.
9f619ff77SPeter Avalos.\" 2. Redistributions in binary form must reproduce the above copyright
10f619ff77SPeter Avalos.\"    notice, this list of conditions and the following disclaimer in the
11f619ff77SPeter Avalos.\"    documentation and/or other materials provided with the distribution.
12f619ff77SPeter Avalos.\"
13f619ff77SPeter Avalos.\" THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14f619ff77SPeter Avalos.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15f619ff77SPeter Avalos.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16f619ff77SPeter Avalos.\" ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
17f619ff77SPeter Avalos.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18f619ff77SPeter Avalos.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19f619ff77SPeter Avalos.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20f619ff77SPeter Avalos.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21f619ff77SPeter Avalos.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22f619ff77SPeter Avalos.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23f619ff77SPeter Avalos.\" SUCH DAMAGE.
24f619ff77SPeter Avalos.\"
25f619ff77SPeter Avalos.\" $FreeBSD: head/share/man/man3/tgmath.3 233992 2012-04-07 09:05:30Z joel $
26f619ff77SPeter Avalos.\"
27f22b35d4SSascha Wildner.Dd June 2, 2013
28f619ff77SPeter Avalos.Dt TGMATH 3
29f619ff77SPeter Avalos.Os
30f619ff77SPeter Avalos.Sh NAME
31f619ff77SPeter Avalos.Nm tgmath
32f619ff77SPeter Avalos.Nd "type-generic macros"
33f619ff77SPeter Avalos.Sh SYNOPSIS
34f619ff77SPeter Avalos.In tgmath.h
35f619ff77SPeter Avalos.Sh DESCRIPTION
36f619ff77SPeter AvalosThe header
37f619ff77SPeter Avalos.In tgmath.h
38f619ff77SPeter Avalosprovides type-generic macros
39f619ff77SPeter Avalosfor
40f619ff77SPeter Avalos.In math.h
41f619ff77SPeter Avalosand
42f619ff77SPeter Avalos.In complex.h
43f619ff77SPeter Avalosfunctions that have
44f619ff77SPeter Avalos.Vt float
45f619ff77SPeter Avalos(suffixed with
46f619ff77SPeter Avalos.Sy f ) ,
47f619ff77SPeter Avalos.Vt double
48f619ff77SPeter Avalosand
49f619ff77SPeter Avalos.Vt "long double"
50f619ff77SPeter Avalos(suffixed with
51f619ff77SPeter Avalos.Sy l )
52f619ff77SPeter Avalosversions.
53f619ff77SPeter AvalosThe arguments that vary across the three functions and have type
54f619ff77SPeter Avalos.Vt float , double
55f619ff77SPeter Avalosand
56f619ff77SPeter Avalos.Vt "long double" ,
57f619ff77SPeter Avalosrespectively, are called
58f619ff77SPeter Avalos.Em "generic arguments" .
59f619ff77SPeter Avalos.Pp
60f619ff77SPeter AvalosThe following rules describe which function is actually called if a
61f619ff77SPeter Avalostype-generic macro is invoked.
62f619ff77SPeter AvalosIf any generic argument has type
63f619ff77SPeter Avalos.Vt "long double"
64f619ff77SPeter Avalosor
65f619ff77SPeter Avalos.Vt "long double complex" ,
66f619ff77SPeter Avalosthe
67f619ff77SPeter Avalos.Vt "long double"
68f619ff77SPeter Avalosfunction is called.
69f619ff77SPeter AvalosElse, if any generic argument has type
70f619ff77SPeter Avalos.Vt double , "double complex"
71f619ff77SPeter Avalosor an integer type, the
72f619ff77SPeter Avalos.Vt double
73f619ff77SPeter Avalosversion is invoked.
74f619ff77SPeter AvalosOtherwise, the macro expands to the
75f619ff77SPeter Avalos.Vt float
76f619ff77SPeter Avalosimplementation.
77f619ff77SPeter Avalos.Pp
78f619ff77SPeter AvalosFor the macros in the following table, both real and complex functions
79f619ff77SPeter Avalosexist.
80f619ff77SPeter AvalosThe real functions are prototyped in
81f619ff77SPeter Avalos.In math.h
82f619ff77SPeter Avalosand the complex equivalents in
83f619ff77SPeter Avalos.In complex.h .
84f619ff77SPeter AvalosThe complex function is called if any of the generic arguments is a
85f619ff77SPeter Avaloscomplex value.
86f619ff77SPeter AvalosOtherwise, the real equivalent is called.
87f619ff77SPeter Avalos.Bl -column -offset indent ".Fn acosh" "Sy real function" ".Sy complex function"
88f619ff77SPeter Avalos.It Sy Macro Ta Sy real function Ta Sy complex function
89f619ff77SPeter Avalos.It Fn acos Ta Fn acos Ta Fn cacos
90f619ff77SPeter Avalos.It Fn asin Ta Fn asin Ta Fn casin
91f619ff77SPeter Avalos.It Fn atan Ta Fn atan Ta Fn catan
92f619ff77SPeter Avalos.It Fn acosh Ta Fn acosh Ta Fn cacosh
93f619ff77SPeter Avalos.It Fn asinh Ta Fn asinh Ta Fn casinh
94f619ff77SPeter Avalos.It Fn atanh Ta Fn atanh Ta Fn catanh
95f619ff77SPeter Avalos.It Fn cos Ta Fn cos Ta Fn ccos
96f619ff77SPeter Avalos.It Fn sin Ta Fn sin Ta Fn csin
97f619ff77SPeter Avalos.It Fn tan Ta Fn tan Ta Fn ctan
98f619ff77SPeter Avalos.It Fn cosh Ta Fn cosh Ta Fn ccosh
99f619ff77SPeter Avalos.It Fn sinh Ta Fn sinh Ta Fn csinh
100f619ff77SPeter Avalos.It Fn tanh Ta Fn tanh Ta Fn ctanh
101f619ff77SPeter Avalos.It Fn exp Ta Fn exp Ta Fn cexp
102f619ff77SPeter Avalos.It Fn log Ta Fn log Ta Fn clog
103f619ff77SPeter Avalos.It Fn pow Ta Fn pow Ta Fn cpow
104f619ff77SPeter Avalos.It Fn sqrt Ta Fn sqrt Ta Fn csqrt
105f619ff77SPeter Avalos.It Fn fabs Ta Fn fabs Ta Fn cabs
106f619ff77SPeter Avalos.El
107f619ff77SPeter Avalos.Pp
108f619ff77SPeter AvalosNo complex functions exist for the following macros, so passing a
109f619ff77SPeter Avaloscomplex value to a generic argument invokes undefined behaviour:
110f619ff77SPeter Avalos.Bl -column -offset indent ".Fn nexttoward" ".Fn nexttoward" ".Fn nexttoward" ".Fn nexttoward"
111f619ff77SPeter Avalos.It Fn atan2 Ta Fn fma Ta Fn llround Ta Fn remainder
112f619ff77SPeter Avalos.It Fn cbrt Ta Fn fmax Ta Fn log10 Ta Fn remquo
113f619ff77SPeter Avalos.It Fn ceil Ta Fn fmin Ta Fn log1p Ta Fn rint
114f619ff77SPeter Avalos.It Fn copysign Ta Fn fmod Ta Fn log2 Ta Fn round
115f619ff77SPeter Avalos.It Fn erf Ta Fn frexp Ta Fn logb Ta Fn scalbn
116f619ff77SPeter Avalos.It Fn erfc Ta Fn hypot Ta Fn lrint Ta Fn scalbln
117f619ff77SPeter Avalos.It Fn exp2 Ta Fn ilogb Ta Fn lround Ta Fn tgamma
118*4dbc9169SSascha Wildner.It Fn expm1 Ta Fn ldexp Ta Fn nearbyint Ta Fn trunc
119f619ff77SPeter Avalos.It Fn fdim Ta Fn lgamma Ta Fn nextafter Ta \&
120f619ff77SPeter Avalos.It Fn floor Ta Fn llrint Ta Fn nexttoward Ta \&
121f619ff77SPeter Avalos.El
122f619ff77SPeter Avalos.Pp
123f619ff77SPeter AvalosThe following macros always expand to a complex function:
124f619ff77SPeter Avalos.Bl -column -offset indent ".Fn cimag" ".Fn cimag" ".Fn cimag" ".Fn cimag" ".Fn cimag"
125f619ff77SPeter Avalos.It Fn carg Ta Fn cimag Ta Fn conj Ta Fn cproj Ta Fn creal
126f619ff77SPeter Avalos.El
127f619ff77SPeter Avalos.Pp
128f619ff77SPeter AvalosThis header includes
129f619ff77SPeter Avalos.In complex.h
130f619ff77SPeter Avalosand
131f619ff77SPeter Avalos.In math.h .
132f619ff77SPeter Avalos.Sh STANDARDS
133f619ff77SPeter AvalosThe header
134f619ff77SPeter Avalos.In tgmath.h
135f619ff77SPeter Avalosconforms to
136f619ff77SPeter Avalos.St -isoC-99 .
137f619ff77SPeter Avalos.Sh HISTORY
138f619ff77SPeter AvalosThe header
139f619ff77SPeter Avalos.In tgmath.h
140f619ff77SPeter Avalosfirst appeared in
141f619ff77SPeter Avalos.Fx 5.3 .
142f619ff77SPeter Avalos.Sh COMPILER SUPPORT
143f619ff77SPeter AvalosBefore
144f619ff77SPeter Avalos.St -isoC-2011 ,
145f619ff77SPeter Avalosthe header
146f619ff77SPeter Avalos.In tgmath.h
147f619ff77SPeter Avaloscould not be implemented with strictly conforming C code and needed
148f619ff77SPeter Avalosspecial compiler support.
149f619ff77SPeter AvalosAs of
150f619ff77SPeter Avalos.St -isoC-2011 ,
151f619ff77SPeter Avalosthis header file can be implemented using the
152f619ff77SPeter Avalos.Fn _Generic
153f619ff77SPeter Avaloslanguage keyword.
154f619ff77SPeter AvalosIn addition to compilers that support this keyword, this header file
155f619ff77SPeter Avalosworks with GCC.
156f619ff77SPeter Avalos.Sh BUGS
157f619ff77SPeter AvalosMany of the functions mentioned here are not prototyped in
158f619ff77SPeter Avalos.In math.h
159f619ff77SPeter Avalosor
160f619ff77SPeter Avalos.In complex.h
161f619ff77SPeter Avalosas they are not yet implemented.
162f619ff77SPeter AvalosThis prevents the corresponding type-generic macro from working at all.
163