File: [cvs.NetBSD.org] / src / include / tgmath.h (download)
Revision 1.1, Sun Sep 28 14:57:41 2008 UTC (15 years, 6 months ago) by matt
Branch: MAIN
CVS Tags: yamt-pagecache-tag8, yamt-pagecache-base9, yamt-pagecache-base8, yamt-pagecache-base7, yamt-pagecache-base6, yamt-pagecache-base5, yamt-pagecache-base4, yamt-pagecache-base3, yamt-pagecache-base2, yamt-pagecache-base, yamt-pagecache, uebayasi-xip-base7, uebayasi-xip-base6, uebayasi-xip-base5, uebayasi-xip-base4, uebayasi-xip-base3, uebayasi-xip-base2, uebayasi-xip-base1, uebayasi-xip-base, uebayasi-xip, tls-maxphys-base, tls-maxphys, tls-earlyentropy-base, tls-earlyentropy, riastradh-xf86-video-intel-2-7-1-pre-2-21-15, riastradh-drm2-base3, riastradh-drm2-base2, riastradh-drm2-base1, riastradh-drm2-base, riastradh-drm2, pgoyette-localcount-base, pgoyette-localcount-20170320, pgoyette-localcount-20170107, pgoyette-localcount-20161104, pgoyette-localcount-20160806, pgoyette-localcount-20160726, netbsd-7-nhusb-base-20170116, netbsd-7-nhusb-base, netbsd-7-nhusb, netbsd-7-base, netbsd-7-2-RELEASE, netbsd-7-1-RELEASE, netbsd-7-1-RC2, netbsd-7-1-RC1, netbsd-7-1-2-RELEASE, netbsd-7-1-1-RELEASE, netbsd-7-1, netbsd-7-0-RELEASE, netbsd-7-0-RC3, netbsd-7-0-RC2, netbsd-7-0-RC1, netbsd-7-0-2-RELEASE, netbsd-7-0-1-RELEASE, netbsd-7-0, netbsd-7, netbsd-6-base, netbsd-6-1-RELEASE, netbsd-6-1-RC4, netbsd-6-1-RC3, netbsd-6-1-RC2, netbsd-6-1-RC1, netbsd-6-1-5-RELEASE, netbsd-6-1-4-RELEASE, netbsd-6-1-3-RELEASE, netbsd-6-1-2-RELEASE, netbsd-6-1-1-RELEASE, netbsd-6-1, netbsd-6-0-RELEASE, netbsd-6-0-RC2, netbsd-6-0-RC1, netbsd-6-0-6-RELEASE, netbsd-6-0-5-RELEASE, netbsd-6-0-4-RELEASE, netbsd-6-0-3-RELEASE, netbsd-6-0-2-RELEASE, netbsd-6-0-1-RELEASE, netbsd-6-0, netbsd-6, netbsd-5-base, netbsd-5-2-RELEASE, netbsd-5-2-RC1, netbsd-5-2-3-RELEASE, netbsd-5-2-2-RELEASE, netbsd-5-2-1-RELEASE, netbsd-5-2, netbsd-5-1-RELEASE, netbsd-5-1-RC4, netbsd-5-1-RC3, netbsd-5-1-RC2, netbsd-5-1-RC1, netbsd-5-1-5-RELEASE, netbsd-5-1-4-RELEASE, netbsd-5-1-3-RELEASE, netbsd-5-1-2-RELEASE, netbsd-5-1-1-RELEASE, netbsd-5-1, netbsd-5-0-RELEASE, netbsd-5-0-RC4, netbsd-5-0-RC3, netbsd-5-0-RC2, netbsd-5-0-RC1, netbsd-5-0-2-RELEASE, netbsd-5-0-1-RELEASE, netbsd-5-0, netbsd-5, matt-premerge-20091211, matt-nb6-plus-nbase, matt-nb6-plus-base, matt-nb6-plus, matt-nb5-pq3-base, matt-nb5-pq3, matt-nb5-mips64-u2-k2-k4-k7-k8-k9, matt-nb5-mips64-u1-k1-k5, matt-nb5-mips64-premerge-20101231, matt-nb5-mips64-premerge-20091211, matt-nb5-mips64-k15, matt-nb5-mips64, matt-nb4-mips64-k7-u2a-k9b, matt-mips64-premerge-20101231, matt-mips64-base2, localcount-20160914, jym-xensuspend-nbase, jym-xensuspend-base, jym-xensuspend, christos-time_t-nbase, christos-time_t-base, cherry-xenmp-base, cherry-xenmp, bouyer-socketcan-base, bouyer-quota2-nbase, bouyer-quota2-base, bouyer-quota2, agc-symver-base, agc-symver Branch point for: pgoyette-localcount, christos-time_t, bouyer-socketcan
Add the C99 header <tgmath.h> (Type-generic math.h)
Until IEEE libm support *l (long double) we can't install it.
|
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Matt Thomas <matt@3am-software.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _TGMATH_H_
#define _TGMATH_H_
#include <math.h>
#include <complex.h>
/*
* C99 Type-generic math (7.22)
*/
#ifdef __GNUC__
#define __TG_CHOOSE(p, a, b) __builtin_choose_expr((p), (a), (b))
#define __TG_IS_EQUIV_TYPE_P(v, t) \
__builtin_types_compatible_p(__typeof__(v), t)
#else
#error how does this compler do type-generic macros?
#endif
#define __TG_IS_FCOMPLEX_P(t) __TG_IS_EQUIV_TYPE_P(t, float complex)
#define __TG_IS_DCOMPLEX_P(t) __TG_IS_EQUIV_TYPE_P(t, double complex)
#define __TG_IS_LCOMPLEX_P(t) __TG_IS_EQUIV_TYPE_P(t, long double complex)
#define __TG_IS_FLOAT_P(t) __TG_IS_EQUIV_TYPE_P(t, float)
#define __TG_IS_LDOUBLE_P(t) __TG_IS_EQUIV_TYPE_P(t, long double)
#define __TG_IS_FREAL_P(t) (__TG_IS_FLOAT_P(t) || __TG_IS_FCOMPLEX_P(t))
#define __TG_IS_LREAL_P(t) (__TG_IS_LDOUBLE_P(t) || __TG_IS_LCOMPLEX_P(t))
#define __TG_IS_COMPLEX_P(t) \
(__TG_IS_FCOMPLEX_P(t) \
|| __TG_IS_DCOMPLEX_P(t) \
|| __TG_IS_LCOMPLEX_P(t))
#define __TG_GFN1(fn, a, ftype, ltype) \
__TG_CHOOSE(__TG_IS_##ftype##_P(a), \
fn##f(a), \
__TG_CHOOSE(__TG_IS_##ltype##_P(a), \
fn##l(a), \
fn(a)))
#define __TG_GFN1x(fn, a, b, ftype, ltype) \
__TG_CHOOSE(__TG_IS_##ftype##_P(a), \
fn##f((a), (b)), \
__TG_CHOOSE(__TG_IS_##ltype##_P(a), \
fn##l((a), (b)), \
fn((a), (b))))
#define __TG_GFN2(fn, a, b, ftype, ltype) \
__TG_CHOOSE(__TG_IS_##ftype##_P(a) \
&& __TG_IS_##ftype##_P(b), \
fn##f((a), (b)), \
__TG_CHOOSE(__TG_IS_##ltype##_P(a) \
|| __TG_IS_##ltype##_P(b), \
fn##l((a), (b)), \
fn((a), (b))))
#define __TG_GFN2x(fn, a, b, c, ftype, ltype) \
__TG_CHOOSE(__TG_IS_##ftype##_P(a) \
&& __TG_IS_##ftype##_P(b), \
fn##f((a), (b), (c)), \
__TG_CHOOSE(__TG_IS_##ltype##_P(a) \
|| __TG_IS_##ltype##_P(b), \
fn##l((a), (b), (c)), \
fn((a), (b), (c))))
#define __TG_GFN3(fn, a, b, c, ftype, ltype) \
__TG_CHOOSE(__TG_IS_##ftype##_P(a) \
&& __TG_IS_##ftype##_P(b) \
&& __TG_IS_##ftype##_P(c), \
fn##f((a), (b), (c)), \
__TG_CHOOSE(__TG_IS_##ltype##_P(a) \
|| __TG_IS_##ltype##_P(b) \
|| __TG_IS_##ltype##_P(c), \
fn##l((a), (b), (c)), \
fn((a), (b), (c))))
#define __TG_CFN1(cfn, a) __TG_GFN1(cfn, a, FREAL, LREAL)
#define __TG_CFN2(cfn, a, b) __TG_GFN2(cfn, a, b, FREAL, LREAL)
#define __TG_FN1(fn, a) __TG_GFN1(fn, a, FLOAT, LDOUBLE)
#define __TG_FN1x(fn, a, b) __TG_GFN1x(fn, a, b, FLOAT, LDOUBLE)
#define __TG_FN2(fn, a, b) __TG_GFN2(fn, a, b, FLOAT, LDOUBLE)
#define __TG_FN2x(fn, a, b, c) __TG_GFN2x(fn, a, b, c, FLOAT, LDOUBLE)
#define __TG_FN3(fn, a, b, c) __TG_GFN3(fn, a, b, c, FLOAT, LDOUBLE)
#define __TG_COMPLEX(a, fn) \
__TG_CHOOSE(__TG_IS_COMPLEX_P(a), \
__TG_CFN1(c##fn, (a)), \
__TG_FN1(fn, (a)))
#define __TG_COMPLEX1(a, cfn, fn) \
__TG_CHOOSE(__TG_IS_COMPLEX_P(a), \
__TG_CFN1(cfn, (a)), \
__TG_FN1(fn, (a)))
#define __TG_COMPLEX2(a, b, fn) \
__TG_CHOOSE(__TG_IS_COMPLEX_P(a) \
|| __TG_IS_COMPLEX_P(b), \
__TG_CFN2(c##fn, (a), (b)), \
__TG_FN2(fn, (a), (b)))
#define acos(a) __TG_COMPLEX((a), acos)
#define asin(a) __TG_COMPLEX((a), asin)
#define atan(a) __TG_COMPLEX((a), atan)
#define acosh(a) __TG_COMPLEX((a), acosh)
#define asinh(a) __TG_COMPLEX((a), asinh)
#define atanh(a) __TG_COMPLEX((a), atanh)
#define cos(a) __TG_COMPLEX((a), cos)
#define sin(a) __TG_COMPLEX((a), sin)
#define tan(a) __TG_COMPLEX((a), tan)
#define cosh(a) __TG_COMPLEX((a), cosh)
#define sinh(a) __TG_COMPLEX((a), sinh)
#define tanh(a) __TG_COMPLEX((a), tanh)
#define exp(a) __TG_COMPLEX((a), exp)
#define log(a) __TG_COMPLEX((a), log)
#define pow(a,b) __TG_COMPLEX2((a), (b), pow)
#define sqrt(a) __TG_COMPLEX((a), sqrt)
#define fabs(a) __TG_COMPLEX1((a), cabs, fabs)
#define atan2(a,b) __TG_FN2(atan2, (a), (b))
#define cbrt(a) __TG_FN1(cbrt, (a))
#define ceil(a) __TG_FN1(ceil, (a))
#define copysign(a,b) __TG_FN2(copysign, (a), (b))
#define erf(a) __TG_FN1(erf, (a))
#define erfc(a) __TG_FN1(erfc, (a))
#define exp2(a) __TG_FN1(exp2, (a))
#define expm1(a) __TG_FN1(expm1, (a))
#define fdim(a,b) __TG_FN2(fdim, (a), (b))
#define floor(a) __TG_FN1(floor, (a))
#define fma(a,b,c) __TG_FN3(fma, (a), (b), (c))
#define fmax(a,b) __TG_FN2(fmax, (a), (b))
#define fmin(a,b) __TG_FN2(fmin, (a), (b))
#define fmod(a,b) __TG_FN2(fmod, (a), (b))
#define frexp(a,b) __TG_FN1x(frexp, (a), (b))
#define hypot(a,b) __TG_FN2(hypot, (a), (b))
#define ilogb(a) __TG_FN1(ilogb, (a))
#define ldexp(a,b) __TG_FN1x(ldexp, (a), (b))
#define lgamma(a) __TG_FN1(lgamma, (a))
#define llrint(a) __TG_FN1(llrint, (a))
#define llround(a) __TG_FN1(llround, (a))
#define log10(a) __TG_FN1(log10, (a))
#define log1p(a) __TG_FN1(log1p, (a))
#define log2(a) __TG_FN1(log2, (a))
#define logb(a) __TG_FN1(logb, (a))
#define lrint(a) __TG_FN1(lrint, (a))
#define lround(a) __TG_FN1(lround, (a))
#define nearbyint(a) __TG_FN1(nearbyint, (a))
#define nextafter(a,b) __TG_FN2(nextafter, (a), (b))
#define nexttoward(a,b) __TG_FN2(nexttoward, (a), (b))
#define remainder(a,b) __TG_FN2(remainder, (a), (b))
#define remquo(a,b,c) __TG_FN2x(remquo, (a), (b), (c))
#define rint(a) __TG_FN1(rint, (a))
#define round(a) __TG_FN1(round, (a))
#define scalbn(a,b) __TG_FN1x(scalbn, (a), (b))
#define scalb1n(a,b) __TG_FN1x(scalb1n, (a), (b))
#define tgamma(a) __TG_FN1(tgamma, (a))
#define trunc(a) __TG_FN1(trunc, (a))
#define carg(a) __TG_CFN1(carg, (a))
#define cimag(a) __TG_CFN1(cimag, (a))
#define conj(a) __TG_CFN1(conj, (a))
#define cproj(a) __TG_CFN1(cproj, (a))
#define creal(a) __TG_CFN1(creal, (a))
#endif /* !_TGMATH_H_ */