[BACK]Return to math.h CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / include

Annotation of src/include/math.h, Revision 1.45

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

CVSweb <webmaster@jp.NetBSD.org>