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#ifdef _ALLBSD_SOURCE
28#include <machine/endian.h>
29#elif __linux__
30#define __USE_BSD 1
31#include <endian.h>
32#endif
33//#include "jfdlibm.h"
34
35#ifdef __NEWVALID       /* special setup for Sun test regime */
36#if defined(i386) || defined(i486) || \
37    defined(intel) || defined(x86) || defined(arm) || \
38    defined(i86pc) || defined(_M_IA64) || defined(ia64)
39#define _LITTLE_ENDIAN
40#endif
41#endif
42
43#ifdef _LITTLE_ENDIAN
44#define __HI(x) *(1+(int*)&x)
45#define __LO(x) *(int*)&x
46#define __HIp(x) *(1+(int*)x)
47#define __LOp(x) *(int*)x
48#else
49#define __HI(x) *(int*)&x
50#define __LO(x) *(1+(int*)&x)
51#define __HIp(x) *(int*)x
52#define __LOp(x) *(1+(int*)x)
53#endif
54
55#ifndef __P
56#ifdef __STDC__
57#define __P(p)  p
58#else
59#define __P(p)  ()
60#endif
61#endif
62
63/*
64 * ANSI/POSIX
65 */
66
67extern int signgam;
68
69#define MAXFLOAT        ((float)3.40282346638528860e+38)
70
71enum fdversion {fdlibm_ieee = -1, fdlibm_svid, fdlibm_xopen, fdlibm_posix};
72
73#define _LIB_VERSION_TYPE enum fdversion
74#define _LIB_VERSION _fdlib_version
75
76/* if global variable _LIB_VERSION is not desirable, one may
77 * change the following to be a constant by:
78 *      #define _LIB_VERSION_TYPE const enum version
79 * In that case, after one initializes the value _LIB_VERSION (see
80 * s_lib_version.c) during compile time, it cannot be modified
81 * in the middle of a program
82 */
83extern  _LIB_VERSION_TYPE  _LIB_VERSION;
84
85#define _IEEE_  fdlibm_ieee
86#define _SVID_  fdlibm_svid
87#define _XOPEN_ fdlibm_xopen
88#define _POSIX_ fdlibm_posix
89
90struct exception {
91        int type;
92        char *name;
93        double arg1;
94        double arg2;
95        double retval;
96};
97
98#define HUGE            MAXFLOAT
99
100/*
101 * set X_TLOSS = pi*2**52, which is possibly defined in <values.h>
102 * (one may replace the following line by "#include <values.h>")
103 */
104
105#define X_TLOSS         1.41484755040568800000e+16
106
107#define DOMAIN          1
108#define SING            2
109#define OVERFLOW        3
110#define UNDERFLOW       4
111#define TLOSS           5
112#define PLOSS           6
113
114/*
115 * ANSI/POSIX
116 */
117extern double acos __P((double));
118extern double asin __P((double));
119extern double atan __P((double));
120extern double atan2 __P((double, double));
121extern double cos __P((double));
122extern double sin __P((double));
123extern double tan __P((double));
124
125extern double cosh __P((double));
126extern double sinh __P((double));
127extern double tanh __P((double));
128
129extern double exp __P((double));
130extern double frexp __P((double, int *));
131extern double ldexp __P((double, int));
132extern double log __P((double));
133extern double log10 __P((double));
134extern double modf __P((double, double *));
135
136extern double pow __P((double, double));
137extern double sqrt __P((double));
138
139extern double ceil __P((double));
140extern double fabs __P((double));
141extern double floor __P((double));
142extern double fmod __P((double, double));
143
144extern double erf __P((double));
145extern double erfc __P((double));
146extern double gamma __P((double));
147extern double hypot __P((double, double));
148extern int isnan __P((double));
149extern int finite __P((double));
150extern double j0 __P((double));
151extern double j1 __P((double));
152extern double jn __P((int, double));
153extern double lgamma __P((double));
154extern double y0 __P((double));
155extern double y1 __P((double));
156extern double yn __P((int, double));
157
158extern double acosh __P((double));
159extern double asinh __P((double));
160extern double atanh __P((double));
161extern double cbrt __P((double));
162extern double logb __P((double));
163extern double nextafter __P((double, double));
164extern double remainder __P((double, double));
165#ifdef _SCALB_INT
166extern double scalb __P((double, int));
167#else
168extern double scalb __P((double, double));
169#endif
170
171extern int matherr __P((struct exception *));
172
173/*
174 * IEEE Test Vector
175 */
176extern double significand __P((double));
177
178/*
179 * Functions callable from C, intended to support IEEE arithmetic.
180 */
181extern double copysign __P((double, double));
182extern int ilogb __P((double));
183extern double rint __P((double));
184extern double scalbn __P((double, int));
185
186/*
187 * BSD math library entry points
188 */
189extern double expm1 __P((double));
190extern double log1p __P((double));
191
192/*
193 * Reentrant version of gamma & lgamma; passes signgam back by reference
194 * as the second argument; user must allocate space for signgam.
195 */
196#ifdef _REENTRANT
197extern double gamma_r __P((double, int *));
198extern double lgamma_r __P((double, int *));
199#endif  /* _REENTRANT */
200
201/* ieee style elementary functions */
202extern double __ieee754_sqrt __P((double));
203extern double __ieee754_acos __P((double));
204extern double __ieee754_acosh __P((double));
205extern double __ieee754_log __P((double));
206extern double __ieee754_atanh __P((double));
207extern double __ieee754_asin __P((double));
208extern double __ieee754_atan2 __P((double,double));
209extern double __ieee754_exp __P((double));
210extern double __ieee754_cosh __P((double));
211extern double __ieee754_fmod __P((double,double));
212extern double __ieee754_pow __P((double,double));
213extern double __ieee754_lgamma_r __P((double,int *));
214extern double __ieee754_gamma_r __P((double,int *));
215extern double __ieee754_lgamma __P((double));
216extern double __ieee754_gamma __P((double));
217extern double __ieee754_log10 __P((double));
218extern double __ieee754_sinh __P((double));
219extern double __ieee754_hypot __P((double,double));
220extern double __ieee754_j0 __P((double));
221extern double __ieee754_j1 __P((double));
222extern double __ieee754_y0 __P((double));
223extern double __ieee754_y1 __P((double));
224extern double __ieee754_jn __P((int,double));
225extern double __ieee754_yn __P((int,double));
226extern double __ieee754_remainder __P((double,double));
227extern int    __ieee754_rem_pio2 __P((double,double*));
228#ifdef _SCALB_INT
229extern double __ieee754_scalb __P((double,int));
230#else
231extern double __ieee754_scalb __P((double,double));
232#endif
233
234/* fdlibm kernel function */
235extern double __kernel_standard __P((double,double,int));
236extern double __kernel_sin __P((double,double,int));
237extern double __kernel_cos __P((double,double));
238extern double __kernel_tan __P((double,double,int));
239extern int    __kernel_rem_pio2 __P((double*,double*,int,int,int,const int*));
240