1 
   2 /*
   3  * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.  Oracle designates this
   9  * particular file as subject to the "Classpath" exception as provided
  10  * by Oracle in the LICENSE file that accompanied this code.
  11  *
  12  * This code is distributed in the hope that it will be useful, but WITHOUT
  13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15  * version 2 for more details (a copy is included in the LICENSE file that
  16  * accompanied this code).
  17  *
  18  * You should have received a copy of the GNU General Public License version
  19  * 2 along with this work; if not, write to the Free Software Foundation,
  20  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  21  *
  22  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  23  * or visit www.oracle.com if you need additional information or have any
  24  * questions.
  25  */
  26 
  27 #include "jfdlibm.h"
  28 
  29 #ifdef __NEWVALID       /* special setup for Sun test regime */
  30 #if defined(i386) || defined(i486) || \
  31     defined(intel) || defined(x86) || defined(arm) || \
  32     defined(i86pc) || defined(_M_IA64) || defined(ia64)
  33 #define _LITTLE_ENDIAN
  34 #endif
  35 #endif
  36 
  37 #ifdef _LITTLE_ENDIAN
  38 #define __HI(x) *(1+(int*)&x)
  39 #define __LO(x) *(int*)&x
  40 #define __HIp(x) *(1+(int*)x)
  41 #define __LOp(x) *(int*)x
  42 #else
  43 #define __HI(x) *(int*)&x
  44 #define __LO(x) *(1+(int*)&x)
  45 #define __HIp(x) *(int*)x
  46 #define __LOp(x) *(1+(int*)x)
  47 #endif
  48 
  49 #ifndef __P
  50 #ifdef __STDC__
  51 #define __P(p)  p
  52 #else
  53 #define __P(p)  ()
  54 #endif
  55 #endif
  56 
  57 /*
  58  * ANSI/POSIX
  59  */
  60 
  61 extern int signgam;
  62 
  63 #define MAXFLOAT        ((float)3.40282346638528860e+38)
  64 
  65 enum fdversion {fdlibm_ieee = -1, fdlibm_svid, fdlibm_xopen, fdlibm_posix};
  66 
  67 #define _LIB_VERSION_TYPE enum fdversion
  68 #define _LIB_VERSION _fdlib_version
  69 
  70 /* if global variable _LIB_VERSION is not desirable, one may
  71  * change the following to be a constant by:
  72  *      #define _LIB_VERSION_TYPE const enum version
  73  * In that case, after one initializes the value _LIB_VERSION (see
  74  * s_lib_version.c) during compile time, it cannot be modified
  75  * in the middle of a program
  76  */
  77 extern  _LIB_VERSION_TYPE  _LIB_VERSION;
  78 
  79 #define _IEEE_  fdlibm_ieee
  80 #define _SVID_  fdlibm_svid
  81 #define _XOPEN_ fdlibm_xopen
  82 #define _POSIX_ fdlibm_posix
  83 
  84 struct exception {
  85         int type;
  86         char *name;
  87         double arg1;
  88         double arg2;
  89         double retval;
  90 };
  91 
  92 #define HUGE            MAXFLOAT
  93 
  94 /*
  95  * set X_TLOSS = pi*2**52, which is possibly defined in <values.h>
  96  * (one may replace the following line by "#include <values.h>")
  97  */
  98 
  99 #define X_TLOSS         1.41484755040568800000e+16
 100 
 101 #define DOMAIN          1
 102 #define SING            2
 103 #define OVERFLOW        3
 104 #define UNDERFLOW       4
 105 #define TLOSS           5
 106 #define PLOSS           6
 107 
 108 /*
 109  * ANSI/POSIX
 110  */
 111 extern double acos __P((double));
 112 extern double asin __P((double));
 113 extern double atan __P((double));
 114 extern double atan2 __P((double, double));
 115 extern double cos __P((double));
 116 extern double sin __P((double));
 117 extern double tan __P((double));
 118 
 119 extern double cosh __P((double));
 120 extern double sinh __P((double));
 121 extern double tanh __P((double));
 122 
 123 extern double exp __P((double));
 124 extern double frexp __P((double, int *));
 125 extern double ldexp __P((double, int));
 126 extern double log __P((double));
 127 extern double log10 __P((double));
 128 extern double modf __P((double, double *));
 129 
 130 extern double pow __P((double, double));
 131 extern double sqrt __P((double));
 132 
 133 extern double ceil __P((double));
 134 extern double fabs __P((double));
 135 extern double floor __P((double));
 136 extern double fmod __P((double, double));
 137 
 138 extern double erf __P((double));
 139 extern double erfc __P((double));
 140 extern double gamma __P((double));
 141 extern double hypot __P((double, double));
 142 extern int isnan __P((double));
 143 extern int finite __P((double));
 144 extern double j0 __P((double));
 145 extern double j1 __P((double));
 146 extern double jn __P((int, double));
 147 extern double lgamma __P((double));
 148 extern double y0 __P((double));
 149 extern double y1 __P((double));
 150 extern double yn __P((int, double));
 151 
 152 extern double acosh __P((double));
 153 extern double asinh __P((double));
 154 extern double atanh __P((double));
 155 extern double cbrt __P((double));
 156 extern double logb __P((double));
 157 extern double nextafter __P((double, double));
 158 extern double remainder __P((double, double));
 159 #ifdef _SCALB_INT
 160 extern double scalb __P((double, int));
 161 #else
 162 extern double scalb __P((double, double));
 163 #endif
 164 
 165 extern int matherr __P((struct exception *));
 166 
 167 /*
 168  * IEEE Test Vector
 169  */
 170 extern double significand __P((double));
 171 
 172 /*
 173  * Functions callable from C, intended to support IEEE arithmetic.
 174  */
 175 extern double copysign __P((double, double));
 176 extern int ilogb __P((double));
 177 extern double rint __P((double));
 178 extern double scalbn __P((double, int));
 179 
 180 /*
 181  * BSD math library entry points
 182  */
 183 extern double expm1 __P((double));
 184 extern double log1p __P((double));
 185 
 186 /*
 187  * Reentrant version of gamma & lgamma; passes signgam back by reference
 188  * as the second argument; user must allocate space for signgam.
 189  */
 190 #ifdef _REENTRANT
 191 extern double gamma_r __P((double, int *));
 192 extern double lgamma_r __P((double, int *));
 193 #endif  /* _REENTRANT */
 194 
 195 /* ieee style elementary functions */
 196 extern double __ieee754_sqrt __P((double));
 197 extern double __ieee754_acos __P((double));
 198 extern double __ieee754_acosh __P((double));
 199 extern double __ieee754_log __P((double));
 200 extern double __ieee754_atanh __P((double));
 201 extern double __ieee754_asin __P((double));
 202 extern double __ieee754_atan2 __P((double,double));
 203 extern double __ieee754_exp __P((double));
 204 extern double __ieee754_cosh __P((double));
 205 extern double __ieee754_fmod __P((double,double));
 206 extern double __ieee754_pow __P((double,double));
 207 extern double __ieee754_lgamma_r __P((double,int *));
 208 extern double __ieee754_gamma_r __P((double,int *));
 209 extern double __ieee754_lgamma __P((double));
 210 extern double __ieee754_gamma __P((double));
 211 extern double __ieee754_log10 __P((double));
 212 extern double __ieee754_sinh __P((double));
 213 extern double __ieee754_hypot __P((double,double));
 214 extern double __ieee754_j0 __P((double));
 215 extern double __ieee754_j1 __P((double));
 216 extern double __ieee754_y0 __P((double));
 217 extern double __ieee754_y1 __P((double));
 218 extern double __ieee754_jn __P((int,double));
 219 extern double __ieee754_yn __P((int,double));
 220 extern double __ieee754_remainder __P((double,double));
 221 extern int    __ieee754_rem_pio2 __P((double,double*));
 222 #ifdef _SCALB_INT
 223 extern double __ieee754_scalb __P((double,int));
 224 #else
 225 extern double __ieee754_scalb __P((double,double));
 226 #endif
 227 
 228 /* fdlibm kernel function */
 229 extern double __kernel_standard __P((double,double,int));
 230 extern double __kernel_sin __P((double,double,int));
 231 extern double __kernel_cos __P((double,double));
 232 extern double __kernel_tan __P((double,double,int));
 233 extern int    __kernel_rem_pio2 __P((double*,double*,int,int,int,const int*));