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