math.h revision 1.32
1/* $NetBSD: math.h,v 1.32 2004/01/20 19:52:40 kleink Exp $ */ 2 3/* 4 * ==================================================== 5 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 * 7 * Developed at SunPro, a Sun Microsystems, Inc. business. 8 * Permission to use, copy, modify, and distribute this 9 * software is freely granted, provided that this notice 10 * is preserved. 11 * ==================================================== 12 */ 13 14/* 15 * @(#)fdlibm.h 5.1 93/09/24 16 */ 17 18#ifndef _MATH_H_ 19#define _MATH_H_ 20 21#include <sys/cdefs.h> 22#include <sys/featuretest.h> 23 24union __float_u { 25 unsigned char __dummy[sizeof(float)]; 26 float __val; 27}; 28 29union __double_u { 30 unsigned char __dummy[sizeof(double)]; 31 double __val; 32}; 33 34union __long_double_u { 35 unsigned char __dummy[sizeof(long double)]; 36 long double __val; 37}; 38 39#include <machine/math.h> /* may use __float_u, __double_u, 40 or __long_double_u */ 41 42#ifdef __HAVE_LONG_DOUBLE 43#define __fpmacro_unary_floating(__name, __arg0) \ 44 ((sizeof (__arg0) == sizeof (float)) \ 45 ? __ ## __name ## f (__arg0) \ 46 : (sizeof (__arg0) == sizeof (double)) \ 47 ? __ ## __name ## d (__arg0) \ 48 : __ ## __name ## l (__arg0)) 49#else 50#define __fpmacro_unary_floating(__name, __arg0) \ 51 ((sizeof (__arg0) == sizeof (float)) \ 52 ? __ ## __name ## f (__arg0) \ 53 : __ ## __name ## d (__arg0)) 54#endif /* __HAVE_LONG_DOUBLE */ 55 56/* 57 * ANSI/POSIX 58 */ 59/* 7.12#3 HUGE_VAL, HUGELF, HUGE_VALL */ 60extern __const union __double_u __infinity; 61#define HUGE_VAL __infinity.__val 62 63/* 64 * ISO C99 65 */ 66#if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE) && \ 67 !defined(_XOPEN_SOURCE) || \ 68 ((__STDC_VERSION__ - 0) >= 199901L) || \ 69 ((_POSIX_C_SOURCE - 0) >= 200112L) || \ 70 ((_XOPEN_SOURCE - 0) >= 600) || \ 71 defined(_ISOC99_SOURCE) || defined(_NETBSD_SOURCE) 72/* 7.12#3 HUGE_VAL, HUGELF, HUGE_VALL */ 73extern __const union __float_u __infinityf; 74#define HUGE_VALF __infinityf.__val 75 76extern __const union __long_double_u __infinityl; 77#define HUGE_VALL __infinityl.__val 78 79/* 7.12#4 INFINITY */ 80#ifdef __INFINITY 81#define INFINITY __INFINITY /* float constant which overflows */ 82#else 83#define INFINITY HUGE_VALF /* positive infinity */ 84#endif /* __INFINITY */ 85 86/* 7.12#5 NAN: a quiet NaN, if supported */ 87#ifdef __HAVE_NANF 88extern __const union __float_u __nanf; 89#define NAN __nanf.__val 90#endif /* __HAVE_NANF */ 91 92/* 7.12#6 number classification macros */ 93#define FP_INFINITE 0x00 94#define FP_NAN 0x01 95#define FP_NORMAL 0x02 96#define FP_SUBNORMAL 0x03 97#define FP_ZERO 0x04 98/* NetBSD extensions */ 99#define _FP_LOMD 0x80 /* range for machine-specific classes */ 100#define _FP_HIMD 0xff 101 102#endif /* !_ANSI_SOURCE && ... */ 103 104/* 105 * XOPEN/SVID 106 */ 107#if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE) 108#define M_E 2.7182818284590452354 /* e */ 109#define M_LOG2E 1.4426950408889634074 /* log 2e */ 110#define M_LOG10E 0.43429448190325182765 /* log 10e */ 111#define M_LN2 0.69314718055994530942 /* log e2 */ 112#define M_LN10 2.30258509299404568402 /* log e10 */ 113#define M_PI 3.14159265358979323846 /* pi */ 114#define M_PI_2 1.57079632679489661923 /* pi/2 */ 115#define M_PI_4 0.78539816339744830962 /* pi/4 */ 116#define M_1_PI 0.31830988618379067154 /* 1/pi */ 117#define M_2_PI 0.63661977236758134308 /* 2/pi */ 118#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ 119#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ 120#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ 121 122#define MAXFLOAT ((float)3.40282346638528860e+38) 123extern int signgam; 124#endif /* _XOPEN_SOURCE || _NETBSD_SOURCE */ 125 126#if defined(_NETBSD_SOURCE) 127enum fdversion {fdlibm_ieee = -1, fdlibm_svid, fdlibm_xopen, fdlibm_posix}; 128 129#define _LIB_VERSION_TYPE enum fdversion 130#define _LIB_VERSION _fdlib_version 131 132/* if global variable _LIB_VERSION is not desirable, one may 133 * change the following to be a constant by: 134 * #define _LIB_VERSION_TYPE const enum version 135 * In that case, after one initializes the value _LIB_VERSION (see 136 * s_lib_version.c) during compile time, it cannot be modified 137 * in the middle of a program 138 */ 139extern _LIB_VERSION_TYPE _LIB_VERSION; 140 141#define _IEEE_ fdlibm_ieee 142#define _SVID_ fdlibm_svid 143#define _XOPEN_ fdlibm_xopen 144#define _POSIX_ fdlibm_posix 145 146#ifndef __cplusplus 147struct exception { 148 int type; 149 char *name; 150 double arg1; 151 double arg2; 152 double retval; 153}; 154#endif 155 156#define HUGE MAXFLOAT 157 158/* 159 * set X_TLOSS = pi*2**52, which is possibly defined in <values.h> 160 * (one may replace the following line by "#include <values.h>") 161 */ 162 163#define X_TLOSS 1.41484755040568800000e+16 164 165#define DOMAIN 1 166#define SING 2 167#define OVERFLOW 3 168#define UNDERFLOW 4 169#define TLOSS 5 170#define PLOSS 6 171 172#endif /* _NETBSD_SOURCE */ 173 174__BEGIN_DECLS 175/* 176 * ANSI/POSIX 177 */ 178double acos __P((double)); 179double asin __P((double)); 180double atan __P((double)); 181double atan2 __P((double, double)); 182double cos __P((double)); 183double sin __P((double)); 184double tan __P((double)); 185 186double cosh __P((double)); 187double sinh __P((double)); 188double tanh __P((double)); 189 190double exp __P((double)); 191double frexp __P((double, int *)); 192double ldexp __P((double, int)); 193double log __P((double)); 194double log10 __P((double)); 195double modf __P((double, double *)); 196 197double pow __P((double, double)); 198double sqrt __P((double)); 199 200double ceil __P((double)); 201double fabs __P((double)); 202double floor __P((double)); 203double fmod __P((double, double)); 204 205#if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE) 206double erf __P((double)); 207double erfc __P((double)); 208double gamma __P((double)); 209double hypot __P((double, double)); 210int isnan __P((double)); 211#if defined(_LIBC) 212int isnanl __P((long double)); 213#endif 214int finite __P((double)); 215double j0 __P((double)); 216double j1 __P((double)); 217double jn __P((int, double)); 218double lgamma __P((double)); 219double y0 __P((double)); 220double y1 __P((double)); 221double yn __P((int, double)); 222 223#if (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE) 224double acosh __P((double)); 225double asinh __P((double)); 226double atanh __P((double)); 227double cbrt __P((double)); 228double expm1 __P((double)); 229int ilogb __P((double)); 230double log1p __P((double)); 231double logb __P((double)); 232double nextafter __P((double, double)); 233double remainder __P((double, double)); 234double rint __P((double)); 235double scalb __P((double, double)); 236#endif /* (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE)*/ 237#endif /* _XOPEN_SOURCE || _NETBSD_SOURCE */ 238 239/* 240 * ISO C99 241 */ 242#if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE) && \ 243 !defined(_XOPEN_SOURCE) || \ 244 ((__STDC_VERSION__ - 0) >= 199901L) || \ 245 ((_POSIX_C_SOURCE - 0) >= 200112L) || \ 246 ((_XOPEN_SOURCE - 0) >= 600) || \ 247 defined(_ISOC99_SOURCE) || defined(_NETBSD_SOURCE) 248/* 7.12.3.1 int fpclassify(real-floating x) */ 249#define fpclassify(__x) __fpmacro_unary_floating(fpclassify, __x) 250 251/* 7.12.3.2 int isfinite(real-floating x) */ 252#define isfinite(__x) __fpmacro_unary_floating(isfinite, __x) 253 254/* 7.12.3.5 int isnormal(real-floating x) */ 255#define isnormal(__x) (fpclassify(__x) == FP_NORMAL) 256 257/* 7.12.3.6 int signbit(real-floating x) */ 258#define signbit(__x) __fpmacro_unary_floating(signbit, __x) 259 260#endif /* !_ANSI_SOURCE && ... */ 261 262#if defined(_NETBSD_SOURCE) 263#ifndef __cplusplus 264int matherr __P((struct exception *)); 265#endif 266 267/* 268 * IEEE Test Vector 269 */ 270double significand __P((double)); 271 272/* 273 * Functions callable from C, intended to support IEEE arithmetic. 274 */ 275double copysign __P((double, double)); 276double scalbn __P((double, int)); 277 278/* 279 * BSD math library entry points 280 */ 281#ifndef __MATH_PRIVATE__ 282double cabs __P((/* struct complex { double r; double i; } */)); 283#endif 284double drem __P((double, double)); 285 286#endif /* _NETBSD_SOURCE */ 287 288#if defined(_NETBSD_SOURCE) || defined(_REENTRANT) 289/* 290 * Reentrant version of gamma & lgamma; passes signgam back by reference 291 * as the second argument; user must allocate space for signgam. 292 */ 293double gamma_r __P((double, int *)); 294double lgamma_r __P((double, int *)); 295#endif /* _NETBSD_SOURCE || _REENTRANT */ 296 297 298#if defined(_NETBSD_SOURCE) 299int isinf __P((double)); 300#if defined(_LIBC) 301int isinfl __P((long double)); 302#endif 303 304/* float versions of ANSI/POSIX functions */ 305float acosf __P((float)); 306float asinf __P((float)); 307float atanf __P((float)); 308float atan2f __P((float, float)); 309float cosf __P((float)); 310float sinf __P((float)); 311float tanf __P((float)); 312 313float coshf __P((float)); 314float sinhf __P((float)); 315float tanhf __P((float)); 316 317float expf __P((float)); 318float frexpf __P((float, int *)); 319float ldexpf __P((float, int)); 320float logf __P((float)); 321float log10f __P((float)); 322float modff __P((float, float *)); 323 324float powf __P((float, float)); 325float sqrtf __P((float)); 326 327float ceilf __P((float)); 328float fabsf __P((float)); 329float floorf __P((float)); 330float fmodf __P((float, float)); 331 332float erff __P((float)); 333float erfcf __P((float)); 334float gammaf __P((float)); 335float hypotf __P((float, float)); 336int isinff __P((float)); 337int isnanf __P((float)); 338int finitef __P((float)); 339float j0f __P((float)); 340float j1f __P((float)); 341float jnf __P((int, float)); 342float lgammaf __P((float)); 343float y0f __P((float)); 344float y1f __P((float)); 345float ynf __P((int, float)); 346 347float acoshf __P((float)); 348float asinhf __P((float)); 349float atanhf __P((float)); 350float cbrtf __P((float)); 351float logbf __P((float)); 352float nextafterf __P((float, float)); 353float remainderf __P((float, float)); 354float scalbf __P((float, float)); 355 356/* 357 * float version of IEEE Test Vector 358 */ 359float significandf __P((float)); 360 361/* 362 * Float versions of functions callable from C, intended to support 363 * IEEE arithmetic. 364 */ 365float copysignf __P((float, float)); 366int ilogbf __P((float)); 367float rintf __P((float)); 368float scalbnf __P((float, int)); 369 370/* 371 * float versions of BSD math library entry points 372 */ 373#ifndef __MATH_PRIVATE__ 374float cabsf __P((/* struct complex { float r; float i; } */)); 375#endif 376float dremf __P((float, float)); 377float expm1f __P((float)); 378float log1pf __P((float)); 379#endif /* _NETBSD_SOURCE */ 380 381#if defined(_NETBSD_SOURCE) || defined(_REENTRANT) 382/* 383 * Float versions of reentrant version of gamma & lgamma; passes 384 * signgam back by reference as the second argument; user must 385 * allocate space for signgam. 386 */ 387float gammaf_r __P((float, int *)); 388float lgammaf_r __P((float, int *)); 389#endif /* !... || _REENTRANT */ 390 391/* 392 * Library implementation 393 */ 394int __fpclassifyf __P((float)); 395int __fpclassifyd __P((double)); 396int __isfinitef __P((float)); 397int __isfinited __P((double)); 398int __signbitf __P((float)); 399int __signbitd __P((double)); 400 401#ifdef __HAVE_LONG_DOUBLE 402int __fpclassifyl __P((long double)); 403int __isfinitel __P((long double)); 404int __signbitl __P((long double)); 405#endif 406__END_DECLS 407 408#endif /* _MATH_H_ */ 409