Dash:
[t2.git] / package / base / dietlibc / 0-libm.patch
blobb43e82ab5b9980312a978ce1b024b4e1944efe2c
1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
3 #
4 # T2 SDE: package/.../dietlibc/0-libm.patch
5 # Copyright (C) 2018 The T2 SDE Project
6 #
7 # More information can be found in the files COPYING and README.
8 #
9 # This patch file is dual-licensed. It is available under the license the
10 # patched project is licensed under, as long as it is an OpenSource license
11 # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
12 # of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
14 # version.
15 # --- T2-COPYRIGHT-NOTE-END ---
17 diff -urN dietlibc-0.30/include/math.h dietlibc-0.30-libm/include/math.h
18 --- dietlibc-0.30/include/math.h 2004-08-03 22:28:46.000000000 +0000
19 +++ dietlibc-0.30-libm/include/math.h 2006-06-25 11:25:32.000000000 +0000
20 @@ -5,6 +5,75 @@
22 __BEGIN_DECLS
24 +/* All floating-point numbers can be put in one of these categories. */
25 +enum
26 + {
27 + FP_NAN,
28 +# define FP_NAN FP_NAN
29 + FP_INFINITE,
30 +# define FP_INFINITE FP_INFINITE
31 + FP_ZERO,
32 +# define FP_ZERO FP_ZERO
33 + FP_SUBNORMAL,
34 +# define FP_SUBNORMAL FP_SUBNORMAL
35 + FP_NORMAL
36 +# define FP_NORMAL FP_NORMAL
37 + };
39 +# if __BYTE_ORDER == __BIG_ENDIAN
40 +# define __nan_bytes { 0x7f, 0xc0, 0, 0 }
41 +# endif
42 +# if __BYTE_ORDER == __LITTLE_ENDIAN
43 +# define __nan_bytes { 0, 0, 0xc0, 0x7f }
44 +# endif
46 +static union { unsigned char __c[4]; float __d; } __nan_union = { __nan_bytes };
47 +# define NAN (__nan_union.__d)
49 +# define X_TLOSS 1.41484755040568800000e+16
51 +/* Types of exceptions in the `type' field. */
52 +# define DOMAIN 1
53 +# define SING 2
54 +# define OVERFLOW 3
55 +# define UNDERFLOW 4
56 +# define TLOSS 5
57 +# define PLOSS 6
59 +/* SVID mode specifies returning this large value instead of infinity. */
60 +# define HUGE 3.40282347e+38F
62 +# ifdef __cplusplus
63 +struct __exception
64 +# else
65 +struct exception
66 +# endif
67 + {
68 + int type;
69 + char *name;
70 + double arg1;
71 + double arg2;
72 + double retval;
73 + };
75 +/* Support for various different standard error handling behaviors. */
76 +typedef enum
78 + _IEEE_ = -1, /* According to IEEE 754/IEEE 854. */
79 + _SVID_, /* According to System V, release 4. */
80 + _XOPEN_, /* Nowadays also Unix98. */
81 + _POSIX_,
82 + _ISOC_ /* Actually this is ISO C99. */
83 +} _LIB_VERSION_TYPE;
85 +#define _LIB_VERSION _POSIX_
87 +# ifdef __cplusplus
88 +extern int matherr (struct __exception *__exc) throw ();
89 +# else
90 +extern int matherr (struct exception *__exc);
91 +# endif
93 #define M_E 2.7182818284590452354 /* e */
94 #define M_LOG2E 1.4426950408889634074 /* log_2 e */
95 #define M_LOG10E 0.43429448190325182765 /* log_10 e */
96 --- dietlibc-0.30/libm/README 1970-01-01 00:00:00.000000000 +0000
97 +++ dietlibc-0.30-libm/libm/README 2006-06-25 11:20:06.000000000 +0000
98 @@ -0,0 +1,16 @@
99 +The routines included in this math library are derived from the
100 +math library for Apple's MacOS X/Darwin math library, which was
101 +itself swiped from FreeBSD. The original copyright information
102 +is as follows:
104 + Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
106 + Developed at SunPro, a Sun Microsystems, Inc. business.
107 + Permission to use, copy, modify, and distribute this
108 + software is freely granted, provided that this notice
109 + is preserved.
111 +It has been ported to work with uClibc and generally behave
112 +by Erik Andersen <andersen@codepoet.org>
113 + 22 May, 2001
114 +Adapted for dietlibc by Rene Rebe <rene@exactcode.de>, 2006
115 diff -urN dietlibc-0.30/libm/acosh.c dietlibc-0.30-libm/libm/acosh.c
116 --- dietlibc-0.30/libm/acosh.c 2001-07-27 20:30:34.000000000 +0000
117 +++ dietlibc-0.30-libm/libm/acosh.c 1970-01-01 00:00:00.000000000 +0000
118 @@ -1,6 +0,0 @@
119 -#include <math.h>
121 -double acosh ( double x )
123 - return log ( x + sqrt (x*x - 1.) );
125 diff -urN dietlibc-0.30/libm/asinh.c dietlibc-0.30-libm/libm/asinh.c
126 --- dietlibc-0.30/libm/asinh.c 2001-07-27 20:30:34.000000000 +0000
127 +++ dietlibc-0.30-libm/libm/asinh.c 1970-01-01 00:00:00.000000000 +0000
128 @@ -1,6 +0,0 @@
129 -#include <math.h>
131 -double asinh ( double x )
133 - return log ( x + sqrt (x*x + 1.) );
135 diff -urN dietlibc-0.30/libm/atanh.c dietlibc-0.30-libm/libm/atanh.c
136 --- dietlibc-0.30/libm/atanh.c 2001-07-27 20:30:34.000000000 +0000
137 +++ dietlibc-0.30-libm/libm/atanh.c 1970-01-01 00:00:00.000000000 +0000
138 @@ -1,8 +0,0 @@
139 -#include <math.h>
141 -extern const float __half;
143 -double atanh ( double x )
145 - return __half * log ( (1.+x) / (1.-x) );
147 diff -urN dietlibc-0.30/libm/bessel.c dietlibc-0.30-libm/libm/bessel.c
148 --- dietlibc-0.30/libm/bessel.c 2005-03-15 08:51:23.000000000 +0000
149 +++ dietlibc-0.30-libm/libm/bessel.c 1970-01-01 00:00:00.000000000 +0000
150 @@ -1,171 +0,0 @@
151 -/*--------------------------------------------------------------------------*
153 -Name j0, j1, jn - Bessel functions
154 - y0, y1, yn - Weber functions
156 -Usage double j0 (double x);
157 - double j1 (double x);
158 - double jn (int n, double x);
159 - double y0 (double x);
160 - double y1 (double x);
161 - double yn (int n, double x);
163 -Prototype in math.h
165 -Description j0, j1 and jn calculate the Bessel function.
166 - y0, y1 and yn calcualte the Weber function.
168 -Return value return their return values as doubles.
170 -*---------------------------------------------------------------------------*/
172 -#include <math.h>
174 -#define M_C 0.5772156649015328
175 -#if 0
176 -#define M_1_PI 0.318309886183790671538
177 -#define M_2_PI 0.636619772367581343076
178 -#define M_PI 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148
179 -#endif
182 -#define EXPL(x) ((((short *)(void *)&x)[4] & 0x7FFF) >> 0)
183 -#define EXPD(x) ((((short *)(void *)&x)[3] & 0x7FF0) >> 4)
184 -#define EXPF(x) ((((short *)(void *)&x)[1] & 0x7F80) >> 7)
186 -#define SQUARE(x) (long) (My - (x) * (x) )
189 -static long double P ( int My, double* x )
191 - long double Sum = 0.;
192 - long double Fact = 1.;
193 - long double z182 = -0.015625 / (x[0] * x[0]);
194 - register int i;
196 - for ( i = 1; ; i += 2 ) {
197 - Fact *= SQUARE(i+i-1) * SQUARE(i+i+1) * z182 / (i*(i+1));
198 - if ( EXPL (Fact) < 0x3FFF-53 )
199 - break;
200 - Sum += Fact;
202 - return 1. + Sum;
205 -static long double Q ( int My, double* x )
207 - long double Fact = (My-1) / x[0] * 0.125;
208 - long double Sum = Fact;
209 - long double z182 = -0.015625 / (x[0]*x[0]);
210 - register int i;
212 - for ( i = 2; ; i += 2 ) {
213 - Fact *= SQUARE(i+i-1) * SQUARE(i+i+1) * z182 / (i*(i+1));
214 - if ( EXPL (Fact) < 0x3FFF-53 )
215 - break;
216 - Sum += Fact;
218 - return Sum;
222 -static long double ___jn ( int n, double* x )
224 - long double Sum;
225 - long double Fact;
226 - long double y;
227 - register int i;
228 - double xx;
229 - long double Xi;
230 - int My;
232 - if ( n < 0 )
233 - return n & 1 ? ___jn (-n, x) : -___jn (-n, x);
235 - if ((x[0] >= 17.7+0.0144*(n*n))) {
236 - Xi = x[0] - M_PI * (n*0.5 + 0.25);
237 - My = n*n << 2;
239 - return sqrt ( M_2_PI/x[0] ) * ( P(My,x) * cos(Xi) - Q(My,x) * sin(Xi) );
241 - xx = x[0] * 0.5;
242 - Sum = 0.;
243 - Fact = 1.;
244 - y = -xx * xx;
246 - for ( i = 1; i <= n; i++ )
247 - Fact *= xx/i;
248 - for ( i = 1; ; i++ ) {
249 - Sum += Fact;
250 - Fact *= y / (i*(n+i));
251 - if ( EXPL (Sum) - EXPL(Fact) > 53 || !EXPL(Fact) )
252 - break;
254 - return Sum;
258 -static long double ___yn ( int n, double* x )
260 - long double Sum1;
261 - long double Sum2;
262 - long double Fact1;
263 - long double Fact2;
264 - long double F1;
265 - long double F2;
266 - long double y;
267 - register int i;
268 - double xx;
269 - long double Xi;
270 - unsigned int My;
272 - if ( EXPD (x[0]) == 0 )
273 - return -1./0.; /* ignore the gcc warning, this is intentional */
275 - if ( (x[0] >= (n>=32 ? 25.8 : (n<8 ? 17.4+0.1*n : 16.2+0.3*n))) ) {
276 - Xi = x[0] - M_PI * (n*0.5+0.25);
277 - My = n*n << 2;
279 - return sqrt ( M_2_PI / x[0] ) * ( P(My,x) * sin(Xi) + Q(My,x) * cos(Xi) );
282 - Sum1 = Sum2 = F1 = F2 = 0;
283 - Fact1 = 1. / (xx = x[0] * 0.5 );
284 - Fact2 = 1.;
285 - y = xx*xx;
287 - for ( i = 1; i < n; i++ )
288 - Fact1 *= (n-i) / xx;
290 - for ( i = 1; i <= n; i++ ) {
291 - Sum1 += Fact1;
292 - if ( i == n )
293 - break;
294 - Fact1 *= y/(i*(n-i));
297 - for (i=1; i<=n; i++) {
298 - Fact2 *= xx / i;
299 - F1 += 1. / i;
302 - for ( i = 1; ; i++ ) {
303 - Sum2 += Fact2 * (F1+F2);
304 - Fact2 *= -y / (i*(n+i));
305 - if ( EXPL (Sum2) - EXPL (Fact2) > 53 || !EXPL (Fact2) )
306 - break;
307 - F1 += 1. / (n+i);
308 - F2 += 1. / i;
311 - return M_1_PI * (2. * (M_C + log(xx)) * ___jn (n, x) - Sum1 - Sum2);
315 -double j0 ( double x ) { return ___jn ( 0,&x ); }
316 -double j1 ( double x ) { return ___jn ( 1,&x ); }
317 -double jn ( int n, double x ) { return ___jn ( n,&x ); }
318 -double y0 ( double x ) { return ___yn ( 0,&x ); }
319 -double y1 ( double x ) { return ___yn ( 1,&x ); }
320 -double yn ( int n, double x ) { return ___yn ( n,&x ); }
322 diff -urN dietlibc-0.30/libm/cosh.c dietlibc-0.30-libm/libm/cosh.c
323 --- dietlibc-0.30/libm/cosh.c 2001-07-27 20:30:34.000000000 +0000
324 +++ dietlibc-0.30-libm/libm/cosh.c 1970-01-01 00:00:00.000000000 +0000
325 @@ -1,9 +0,0 @@
326 -#include <math.h>
328 -extern const float __half;
330 -double cosh ( double x )
332 - long double y = exp (x);
333 - return (y + 1./y) * __half;
335 diff -urN dietlibc-0.30/libm/e_acos.c dietlibc-0.30-libm/libm/e_acos.c
336 --- dietlibc-0.30/libm/e_acos.c 1970-01-01 00:00:00.000000000 +0000
337 +++ dietlibc-0.30-libm/libm/e_acos.c 2006-06-25 11:20:05.000000000 +0000
338 @@ -0,0 +1,111 @@
339 +/* @(#)e_acos.c 5.1 93/09/24 */
341 + * ====================================================
342 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
344 + * Developed at SunPro, a Sun Microsystems, Inc. business.
345 + * Permission to use, copy, modify, and distribute this
346 + * software is freely granted, provided that this notice
347 + * is preserved.
348 + * ====================================================
349 + */
351 +#if defined(LIBM_SCCS) && !defined(lint)
352 +static char rcsid[] = "$NetBSD: e_acos.c,v 1.9 1995/05/12 04:57:13 jtc Exp $";
353 +#endif
355 +/* __ieee754_acos(x)
356 + * Method :
357 + * acos(x) = pi/2 - asin(x)
358 + * acos(-x) = pi/2 + asin(x)
359 + * For |x|<=0.5
360 + * acos(x) = pi/2 - (x + x*x^2*R(x^2)) (see asin.c)
361 + * For x>0.5
362 + * acos(x) = pi/2 - (pi/2 - 2asin(sqrt((1-x)/2)))
363 + * = 2asin(sqrt((1-x)/2))
364 + * = 2s + 2s*z*R(z) ...z=(1-x)/2, s=sqrt(z)
365 + * = 2f + (2c + 2s*z*R(z))
366 + * where f=hi part of s, and c = (z-f*f)/(s+f) is the correction term
367 + * for f so that f+c ~ sqrt(z).
368 + * For x<-0.5
369 + * acos(x) = pi - 2asin(sqrt((1-|x|)/2))
370 + * = pi - 0.5*(s+s*z*R(z)), where z=(1-|x|)/2,s=sqrt(z)
372 + * Special cases:
373 + * if x is NaN, return x itself;
374 + * if |x|>1, return NaN with invalid signal.
376 + * Function needed: __ieee754_sqrt
377 + */
379 +#include "math.h"
380 +#include "math_private.h"
382 +#ifdef __STDC__
383 +static const double
384 +#else
385 +static double
386 +#endif
387 +one= 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
388 +pi = 3.14159265358979311600e+00, /* 0x400921FB, 0x54442D18 */
389 +pio2_hi = 1.57079632679489655800e+00, /* 0x3FF921FB, 0x54442D18 */
390 +pio2_lo = 6.12323399573676603587e-17, /* 0x3C91A626, 0x33145C07 */
391 +pS0 = 1.66666666666666657415e-01, /* 0x3FC55555, 0x55555555 */
392 +pS1 = -3.25565818622400915405e-01, /* 0xBFD4D612, 0x03EB6F7D */
393 +pS2 = 2.01212532134862925881e-01, /* 0x3FC9C155, 0x0E884455 */
394 +pS3 = -4.00555345006794114027e-02, /* 0xBFA48228, 0xB5688F3B */
395 +pS4 = 7.91534994289814532176e-04, /* 0x3F49EFE0, 0x7501B288 */
396 +pS5 = 3.47933107596021167570e-05, /* 0x3F023DE1, 0x0DFDF709 */
397 +qS1 = -2.40339491173441421878e+00, /* 0xC0033A27, 0x1C8A2D4B */
398 +qS2 = 2.02094576023350569471e+00, /* 0x40002AE5, 0x9C598AC8 */
399 +qS3 = -6.88283971605453293030e-01, /* 0xBFE6066C, 0x1B8D0159 */
400 +qS4 = 7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */
402 +#ifdef __STDC__
403 + double __ieee754_acos(double x)
404 +#else
405 + double __ieee754_acos(x)
406 + double x;
407 +#endif
409 + double z,p,q,r,w,s,c,df;
410 + int32_t hx,ix;
411 + GET_HIGH_WORD(hx,x);
412 + ix = hx&0x7fffffff;
413 + if(ix>=0x3ff00000) { /* |x| >= 1 */
414 + u_int32_t lx;
415 + GET_LOW_WORD(lx,x);
416 + if(((ix-0x3ff00000)|lx)==0) { /* |x|==1 */
417 + if(hx>0) return 0.0; /* acos(1) = 0 */
418 + else return pi+2.0*pio2_lo; /* acos(-1)= pi */
420 + return (x-x)/(x-x); /* acos(|x|>1) is NaN */
422 + if(ix<0x3fe00000) { /* |x| < 0.5 */
423 + if(ix<=0x3c600000) return pio2_hi+pio2_lo;/*if|x|<2**-57*/
424 + z = x*x;
425 + p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
426 + q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
427 + r = p/q;
428 + return pio2_hi - (x - (pio2_lo-x*r));
429 + } else if (hx<0) { /* x < -0.5 */
430 + z = (one+x)*0.5;
431 + p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
432 + q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
433 + s = __ieee754_sqrt(z);
434 + r = p/q;
435 + w = r*s-pio2_lo;
436 + return pi - 2.0*(s+w);
437 + } else { /* x > 0.5 */
438 + z = (one-x)*0.5;
439 + s = __ieee754_sqrt(z);
440 + df = s;
441 + SET_LOW_WORD(df,0);
442 + c = (z-df*df)/(s+df);
443 + p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5)))));
444 + q = one+z*(qS1+z*(qS2+z*(qS3+z*qS4)));
445 + r = p/q;
446 + w = r*s+c;
447 + return 2.0*(df+w);
450 diff -urN dietlibc-0.30/libm/e_acosh.c dietlibc-0.30-libm/libm/e_acosh.c
451 --- dietlibc-0.30/libm/e_acosh.c 1970-01-01 00:00:00.000000000 +0000
452 +++ dietlibc-0.30-libm/libm/e_acosh.c 2006-06-25 11:20:21.000000000 +0000
453 @@ -0,0 +1,69 @@
454 +/* @(#)e_acosh.c 5.1 93/09/24 */
456 + * ====================================================
457 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
459 + * Developed at SunPro, a Sun Microsystems, Inc. business.
460 + * Permission to use, copy, modify, and distribute this
461 + * software is freely granted, provided that this notice
462 + * is preserved.
463 + * ====================================================
464 + */
466 +#if defined(LIBM_SCCS) && !defined(lint)
467 +static char rcsid[] = "$NetBSD: e_acosh.c,v 1.9 1995/05/12 04:57:18 jtc Exp $";
468 +#endif
470 +/* __ieee754_acosh(x)
471 + * Method :
472 + * Based on
473 + * acosh(x) = log [ x + sqrt(x*x-1) ]
474 + * we have
475 + * acosh(x) := log(x)+ln2, if x is large; else
476 + * acosh(x) := log(2x-1/(sqrt(x*x-1)+x)) if x>2; else
477 + * acosh(x) := log1p(t+sqrt(2.0*t+t*t)); where t=x-1.
479 + * Special cases:
480 + * acosh(x) is NaN with signal if x<1.
481 + * acosh(NaN) is NaN without signal.
482 + */
484 +#include "math.h"
485 +#include "math_private.h"
487 +#ifdef __STDC__
488 +static const double
489 +#else
490 +static double
491 +#endif
492 +one = 1.0,
493 +ln2 = 6.93147180559945286227e-01; /* 0x3FE62E42, 0xFEFA39EF */
495 +#ifdef __STDC__
496 + double __ieee754_acosh(double x)
497 +#else
498 + double __ieee754_acosh(x)
499 + double x;
500 +#endif
502 + double t;
503 + int32_t hx;
504 + u_int32_t lx;
505 + EXTRACT_WORDS(hx,lx,x);
506 + if(hx<0x3ff00000) { /* x < 1 */
507 + return (x-x)/(x-x);
508 + } else if(hx >=0x41b00000) { /* x > 2**28 */
509 + if(hx >=0x7ff00000) { /* x is inf of NaN */
510 + return x+x;
511 + } else
512 + return __ieee754_log(x)+ln2; /* acosh(huge)=log(2x) */
513 + } else if(((hx-0x3ff00000)|lx)==0) {
514 + return 0.0; /* acosh(1) = 0 */
515 + } else if (hx > 0x40000000) { /* 2**28 > x > 2 */
516 + t=x*x;
517 + return __ieee754_log(2.0*x-one/(x+__ieee754_sqrt(t-one)));
518 + } else { /* 1<x<2 */
519 + t = x-one;
520 + return log1p(t+sqrt(2.0*t+t*t));
523 diff -urN dietlibc-0.30/libm/e_asin.c dietlibc-0.30-libm/libm/e_asin.c
524 --- dietlibc-0.30/libm/e_asin.c 1970-01-01 00:00:00.000000000 +0000
525 +++ dietlibc-0.30-libm/libm/e_asin.c 2006-06-25 11:20:06.000000000 +0000
526 @@ -0,0 +1,121 @@
527 +/* @(#)e_asin.c 5.1 93/09/24 */
529 + * ====================================================
530 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
532 + * Developed at SunPro, a Sun Microsystems, Inc. business.
533 + * Permission to use, copy, modify, and distribute this
534 + * software is freely granted, provided that this notice
535 + * is preserved.
536 + * ====================================================
537 + */
539 +#if defined(LIBM_SCCS) && !defined(lint)
540 +static char rcsid[] = "$NetBSD: e_asin.c,v 1.9 1995/05/12 04:57:22 jtc Exp $";
541 +#endif
543 +/* __ieee754_asin(x)
544 + * Method :
545 + * Since asin(x) = x + x^3/6 + x^5*3/40 + x^7*15/336 + ...
546 + * we approximate asin(x) on [0,0.5] by
547 + * asin(x) = x + x*x^2*R(x^2)
548 + * where
549 + * R(x^2) is a rational approximation of (asin(x)-x)/x^3
550 + * and its remez error is bounded by
551 + * |(asin(x)-x)/x^3 - R(x^2)| < 2^(-58.75)
553 + * For x in [0.5,1]
554 + * asin(x) = pi/2-2*asin(sqrt((1-x)/2))
555 + * Let y = (1-x), z = y/2, s := sqrt(z), and pio2_hi+pio2_lo=pi/2;
556 + * then for x>0.98
557 + * asin(x) = pi/2 - 2*(s+s*z*R(z))
558 + * = pio2_hi - (2*(s+s*z*R(z)) - pio2_lo)
559 + * For x<=0.98, let pio4_hi = pio2_hi/2, then
560 + * f = hi part of s;
561 + * c = sqrt(z) - f = (z-f*f)/(s+f) ...f+c=sqrt(z)
562 + * and
563 + * asin(x) = pi/2 - 2*(s+s*z*R(z))
564 + * = pio4_hi+(pio4-2s)-(2s*z*R(z)-pio2_lo)
565 + * = pio4_hi+(pio4-2f)-(2s*z*R(z)-(pio2_lo+2c))
567 + * Special cases:
568 + * if x is NaN, return x itself;
569 + * if |x|>1, return NaN with invalid signal.
571 + */
574 +#include "math.h"
575 +#include "math_private.h"
577 +#ifdef __STDC__
578 +static const double
579 +#else
580 +static double
581 +#endif
582 +one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
583 +huge = 1.000e+300,
584 +pio2_hi = 1.57079632679489655800e+00, /* 0x3FF921FB, 0x54442D18 */
585 +pio2_lo = 6.12323399573676603587e-17, /* 0x3C91A626, 0x33145C07 */
586 +pio4_hi = 7.85398163397448278999e-01, /* 0x3FE921FB, 0x54442D18 */
587 + /* coefficient for R(x^2) */
588 +pS0 = 1.66666666666666657415e-01, /* 0x3FC55555, 0x55555555 */
589 +pS1 = -3.25565818622400915405e-01, /* 0xBFD4D612, 0x03EB6F7D */
590 +pS2 = 2.01212532134862925881e-01, /* 0x3FC9C155, 0x0E884455 */
591 +pS3 = -4.00555345006794114027e-02, /* 0xBFA48228, 0xB5688F3B */
592 +pS4 = 7.91534994289814532176e-04, /* 0x3F49EFE0, 0x7501B288 */
593 +pS5 = 3.47933107596021167570e-05, /* 0x3F023DE1, 0x0DFDF709 */
594 +qS1 = -2.40339491173441421878e+00, /* 0xC0033A27, 0x1C8A2D4B */
595 +qS2 = 2.02094576023350569471e+00, /* 0x40002AE5, 0x9C598AC8 */
596 +qS3 = -6.88283971605453293030e-01, /* 0xBFE6066C, 0x1B8D0159 */
597 +qS4 = 7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */
599 +#ifdef __STDC__
600 + double __ieee754_asin(double x)
601 +#else
602 + double __ieee754_asin(x)
603 + double x;
604 +#endif
606 + double t=0.0,w,p,q,c,r,s;
607 + int32_t hx,ix;
608 + GET_HIGH_WORD(hx,x);
609 + ix = hx&0x7fffffff;
610 + if(ix>= 0x3ff00000) { /* |x|>= 1 */
611 + u_int32_t lx;
612 + GET_LOW_WORD(lx,x);
613 + if(((ix-0x3ff00000)|lx)==0)
614 + /* asin(1)=+-pi/2 with inexact */
615 + return x*pio2_hi+x*pio2_lo;
616 + return (x-x)/(x-x); /* asin(|x|>1) is NaN */
617 + } else if (ix<0x3fe00000) { /* |x|<0.5 */
618 + if(ix<0x3e400000) { /* if |x| < 2**-27 */
619 + if(huge+x>one) return x;/* return x with inexact if x!=0*/
620 + } else {
621 + t = x*x;
622 + p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5)))));
623 + q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4)));
624 + w = p/q;
625 + return x+x*w;
628 + /* 1> |x|>= 0.5 */
629 + w = one-fabs(x);
630 + t = w*0.5;
631 + p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5)))));
632 + q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4)));
633 + s = __ieee754_sqrt(t);
634 + if(ix>=0x3FEF3333) { /* if |x| > 0.975 */
635 + w = p/q;
636 + t = pio2_hi-(2.0*(s+s*w)-pio2_lo);
637 + } else {
638 + w = s;
639 + SET_LOW_WORD(w,0);
640 + c = (t-w*w)/(s+w);
641 + r = p/q;
642 + p = 2.0*s*r-(pio2_lo-2.0*c);
643 + q = pio4_hi-2.0*w;
644 + t = pio4_hi-(p-q);
646 + if(hx>0) return t; else return -t;
648 diff -urN dietlibc-0.30/libm/e_atan2.c dietlibc-0.30-libm/libm/e_atan2.c
649 --- dietlibc-0.30/libm/e_atan2.c 1970-01-01 00:00:00.000000000 +0000
650 +++ dietlibc-0.30-libm/libm/e_atan2.c 2006-06-25 11:20:24.000000000 +0000
651 @@ -0,0 +1,130 @@
652 +/* @(#)e_atan2.c 5.1 93/09/24 */
654 + * ====================================================
655 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
657 + * Developed at SunPro, a Sun Microsystems, Inc. business.
658 + * Permission to use, copy, modify, and distribute this
659 + * software is freely granted, provided that this notice
660 + * is preserved.
661 + * ====================================================
662 + */
664 +#if defined(LIBM_SCCS) && !defined(lint)
665 +static char rcsid[] = "$NetBSD: e_atan2.c,v 1.8 1995/05/10 20:44:51 jtc Exp $";
666 +#endif
668 +/* __ieee754_atan2(y,x)
669 + * Method :
670 + * 1. Reduce y to positive by atan2(y,x)=-atan2(-y,x).
671 + * 2. Reduce x to positive by (if x and y are unexceptional):
672 + * ARG (x+iy) = arctan(y/x) ... if x > 0,
673 + * ARG (x+iy) = pi - arctan[y/(-x)] ... if x < 0,
675 + * Special cases:
677 + * ATAN2((anything), NaN ) is NaN;
678 + * ATAN2(NAN , (anything) ) is NaN;
679 + * ATAN2(+-0, +(anything but NaN)) is +-0 ;
680 + * ATAN2(+-0, -(anything but NaN)) is +-pi ;
681 + * ATAN2(+-(anything but 0 and NaN), 0) is +-pi/2;
682 + * ATAN2(+-(anything but INF and NaN), +INF) is +-0 ;
683 + * ATAN2(+-(anything but INF and NaN), -INF) is +-pi;
684 + * ATAN2(+-INF,+INF ) is +-pi/4 ;
685 + * ATAN2(+-INF,-INF ) is +-3pi/4;
686 + * ATAN2(+-INF, (anything but,0,NaN, and INF)) is +-pi/2;
688 + * Constants:
689 + * The hexadecimal values are the intended ones for the following
690 + * constants. The decimal values may be used, provided that the
691 + * compiler will convert from decimal to binary accurately enough
692 + * to produce the hexadecimal values shown.
693 + */
695 +#include "math.h"
696 +#include "math_private.h"
698 +#ifdef __STDC__
699 +static const double
700 +#else
701 +static double
702 +#endif
703 +tiny = 1.0e-300,
704 +zero = 0.0,
705 +pi_o_4 = 7.8539816339744827900E-01, /* 0x3FE921FB, 0x54442D18 */
706 +pi_o_2 = 1.5707963267948965580E+00, /* 0x3FF921FB, 0x54442D18 */
707 +pi = 3.1415926535897931160E+00, /* 0x400921FB, 0x54442D18 */
708 +pi_lo = 1.2246467991473531772E-16; /* 0x3CA1A626, 0x33145C07 */
710 +#ifdef __STDC__
711 + double __ieee754_atan2(double y, double x)
712 +#else
713 + double __ieee754_atan2(y,x)
714 + double y,x;
715 +#endif
717 + double z;
718 + int32_t k,m,hx,hy,ix,iy;
719 + u_int32_t lx,ly;
721 + EXTRACT_WORDS(hx,lx,x);
722 + ix = hx&0x7fffffff;
723 + EXTRACT_WORDS(hy,ly,y);
724 + iy = hy&0x7fffffff;
725 + if(((ix|((lx|-lx)>>31))>0x7ff00000)||
726 + ((iy|((ly|-ly)>>31))>0x7ff00000)) /* x or y is NaN */
727 + return x+y;
728 + if(((hx-0x3ff00000)|lx)==0) return atan(y); /* x=1.0 */
729 + m = ((hy>>31)&1)|((hx>>30)&2); /* 2*sign(x)+sign(y) */
731 + /* when y = 0 */
732 + if((iy|ly)==0) {
733 + switch(m) {
734 + case 0:
735 + case 1: return y; /* atan(+-0,+anything)=+-0 */
736 + case 2: return pi+tiny;/* atan(+0,-anything) = pi */
737 + case 3: return -pi-tiny;/* atan(-0,-anything) =-pi */
740 + /* when x = 0 */
741 + if((ix|lx)==0) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny;
743 + /* when x is INF */
744 + if(ix==0x7ff00000) {
745 + if(iy==0x7ff00000) {
746 + switch(m) {
747 + case 0: return pi_o_4+tiny;/* atan(+INF,+INF) */
748 + case 1: return -pi_o_4-tiny;/* atan(-INF,+INF) */
749 + case 2: return 3.0*pi_o_4+tiny;/*atan(+INF,-INF)*/
750 + case 3: return -3.0*pi_o_4-tiny;/*atan(-INF,-INF)*/
752 + } else {
753 + switch(m) {
754 + case 0: return zero ; /* atan(+...,+INF) */
755 + case 1: return -zero ; /* atan(-...,+INF) */
756 + case 2: return pi+tiny ; /* atan(+...,-INF) */
757 + case 3: return -pi-tiny ; /* atan(-...,-INF) */
761 + /* when y is INF */
762 + if(iy==0x7ff00000) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny;
764 + /* compute y/x */
765 + k = (iy-ix)>>20;
766 + if(k > 60) z=pi_o_2+0.5*pi_lo; /* |y/x| > 2**60 */
767 + else if(hx<0&&k<-60) z=0.0; /* |y|/x < -2**60 */
768 + else z=atan(fabs(y/x)); /* safe to do y/x */
769 + switch (m) {
770 + case 0: return z ; /* atan(+,+) */
771 + case 1: {
772 + u_int32_t zh;
773 + GET_HIGH_WORD(zh,z);
774 + SET_HIGH_WORD(z,zh ^ 0x80000000);
776 + return z ; /* atan(-,+) */
777 + case 2: return pi-(z-pi_lo);/* atan(+,-) */
778 + default: /* case 3 */
779 + return (z-pi_lo)-pi;/* atan(-,-) */
782 diff -urN dietlibc-0.30/libm/e_atanh.c dietlibc-0.30-libm/libm/e_atanh.c
783 --- dietlibc-0.30/libm/e_atanh.c 1970-01-01 00:00:00.000000000 +0000
784 +++ dietlibc-0.30-libm/libm/e_atanh.c 2006-06-25 11:20:24.000000000 +0000
785 @@ -0,0 +1,74 @@
786 +/* @(#)e_atanh.c 5.1 93/09/24 */
788 + * ====================================================
789 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
791 + * Developed at SunPro, a Sun Microsystems, Inc. business.
792 + * Permission to use, copy, modify, and distribute this
793 + * software is freely granted, provided that this notice
794 + * is preserved.
795 + * ====================================================
796 + */
798 +#if defined(LIBM_SCCS) && !defined(lint)
799 +static char rcsid[] = "$NetBSD: e_atanh.c,v 1.8 1995/05/10 20:44:55 jtc Exp $";
800 +#endif
802 +/* __ieee754_atanh(x)
803 + * Method :
804 + * 1.Reduced x to positive by atanh(-x) = -atanh(x)
805 + * 2.For x>=0.5
806 + * 1 2x x
807 + * atanh(x) = --- * log(1 + -------) = 0.5 * log1p(2 * --------)
808 + * 2 1 - x 1 - x
810 + * For x<0.5
811 + * atanh(x) = 0.5*log1p(2x+2x*x/(1-x))
813 + * Special cases:
814 + * atanh(x) is NaN if |x| > 1 with signal;
815 + * atanh(NaN) is that NaN with no signal;
816 + * atanh(+-1) is +-INF with signal.
818 + */
820 +#include "math.h"
821 +#include "math_private.h"
823 +#ifdef __STDC__
824 +static const double one = 1.0, huge = 1e300;
825 +#else
826 +static double one = 1.0, huge = 1e300;
827 +#endif
829 +#ifdef __STDC__
830 +static const double zero = 0.0;
831 +#else
832 +static double zero = 0.0;
833 +#endif
835 +#ifdef __STDC__
836 + double __ieee754_atanh(double x)
837 +#else
838 + double __ieee754_atanh(x)
839 + double x;
840 +#endif
842 + double t;
843 + int32_t hx,ix;
844 + u_int32_t lx;
845 + EXTRACT_WORDS(hx,lx,x);
846 + ix = hx&0x7fffffff;
847 + if ((ix|((lx|(-lx))>>31))>0x3ff00000) /* |x|>1 */
848 + return (x-x)/(x-x);
849 + if(ix==0x3ff00000)
850 + return x/zero;
851 + if(ix<0x3e300000&&(huge+x)>zero) return x; /* x<2**-28 */
852 + SET_HIGH_WORD(x,ix);
853 + if(ix<0x3fe00000) { /* x < 0.5 */
854 + t = x+x;
855 + t = 0.5*log1p(t+t*x/(one-x));
856 + } else
857 + t = 0.5*log1p((x+x)/(one-x));
858 + if(hx>=0) return t; else return -t;
860 diff -urN dietlibc-0.30/libm/e_cosh.c dietlibc-0.30-libm/libm/e_cosh.c
861 --- dietlibc-0.30/libm/e_cosh.c 1970-01-01 00:00:00.000000000 +0000
862 +++ dietlibc-0.30-libm/libm/e_cosh.c 2006-06-25 11:20:06.000000000 +0000
863 @@ -0,0 +1,93 @@
864 +/* @(#)e_cosh.c 5.1 93/09/24 */
866 + * ====================================================
867 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
869 + * Developed at SunPro, a Sun Microsystems, Inc. business.
870 + * Permission to use, copy, modify, and distribute this
871 + * software is freely granted, provided that this notice
872 + * is preserved.
873 + * ====================================================
874 + */
876 +#if defined(LIBM_SCCS) && !defined(lint)
877 +static char rcsid[] = "$NetBSD: e_cosh.c,v 1.7 1995/05/10 20:44:58 jtc Exp $";
878 +#endif
880 +/* __ieee754_cosh(x)
881 + * Method :
882 + * mathematically cosh(x) if defined to be (exp(x)+exp(-x))/2
883 + * 1. Replace x by |x| (cosh(x) = cosh(-x)).
884 + * 2.
885 + * [ exp(x) - 1 ]^2
886 + * 0 <= x <= ln2/2 : cosh(x) := 1 + -------------------
887 + * 2*exp(x)
889 + * exp(x) + 1/exp(x)
890 + * ln2/2 <= x <= 22 : cosh(x) := -------------------
891 + * 2
892 + * 22 <= x <= lnovft : cosh(x) := exp(x)/2
893 + * lnovft <= x <= ln2ovft: cosh(x) := exp(x/2)/2 * exp(x/2)
894 + * ln2ovft < x : cosh(x) := huge*huge (overflow)
896 + * Special cases:
897 + * cosh(x) is |x| if x is +INF, -INF, or NaN.
898 + * only cosh(0)=1 is exact for finite x.
899 + */
901 +#include "math.h"
902 +#include "math_private.h"
904 +#ifdef __STDC__
905 +static const double one = 1.0, half=0.5, huge = 1.0e300;
906 +#else
907 +static double one = 1.0, half=0.5, huge = 1.0e300;
908 +#endif
910 +#ifdef __STDC__
911 + double __ieee754_cosh(double x)
912 +#else
913 + double __ieee754_cosh(x)
914 + double x;
915 +#endif
917 + double t,w;
918 + int32_t ix;
919 + u_int32_t lx;
921 + /* High word of |x|. */
922 + GET_HIGH_WORD(ix,x);
923 + ix &= 0x7fffffff;
925 + /* x is INF or NaN */
926 + if(ix>=0x7ff00000) return x*x;
928 + /* |x| in [0,0.5*ln2], return 1+expm1(|x|)^2/(2*exp(|x|)) */
929 + if(ix<0x3fd62e43) {
930 + t = expm1(fabs(x));
931 + w = one+t;
932 + if (ix<0x3c800000) return w; /* cosh(tiny) = 1 */
933 + return one+(t*t)/(w+w);
936 + /* |x| in [0.5*ln2,22], return (exp(|x|)+1/exp(|x|)/2; */
937 + if (ix < 0x40360000) {
938 + t = __ieee754_exp(fabs(x));
939 + return half*t+half/t;
942 + /* |x| in [22, log(maxdouble)] return half*exp(|x|) */
943 + if (ix < 0x40862E42) return half*__ieee754_exp(fabs(x));
945 + /* |x| in [log(maxdouble), overflowthresold] */
946 + GET_LOW_WORD(lx,x);
947 + if (ix<0x408633CE ||
948 + ((ix==0x408633ce)&&(lx<=(u_int32_t)0x8fb9f87d))) {
949 + w = __ieee754_exp(half*fabs(x));
950 + t = half*w;
951 + return t*w;
954 + /* |x| > overflowthresold, cosh(x) overflow */
955 + return huge*huge;
957 diff -urN dietlibc-0.30/libm/e_exp.c dietlibc-0.30-libm/libm/e_exp.c
958 --- dietlibc-0.30/libm/e_exp.c 1970-01-01 00:00:00.000000000 +0000
959 +++ dietlibc-0.30-libm/libm/e_exp.c 2006-06-25 11:20:01.000000000 +0000
960 @@ -0,0 +1,172 @@
961 +/* @(#)e_exp.c 5.1 93/09/24 */
963 + * ====================================================
964 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
966 + * Developed at SunPro, a Sun Microsystems, Inc. business.
967 + * Permission to use, copy, modify, and distribute this
968 + * software is freely granted, provided that this notice
969 + * is preserved.
970 + * ====================================================
971 + */
973 +#if defined(LIBM_SCCS) && !defined(lint)
974 +static char rcsid[] = "$NetBSD: e_exp.c,v 1.8 1995/05/10 20:45:03 jtc Exp $";
975 +#endif
977 +/* __ieee754_exp(x)
978 + * Returns the exponential of x.
980 + * Method
981 + * 1. Argument reduction:
982 + * Reduce x to an r so that |r| <= 0.5*ln2 ~ 0.34658.
983 + * Given x, find r and integer k such that
985 + * x = k*ln2 + r, |r| <= 0.5*ln2.
987 + * Here r will be represented as r = hi-lo for better
988 + * accuracy.
990 + * 2. Approximation of exp(r) by a special rational function on
991 + * the interval [0,0.34658]:
992 + * Write
993 + * R(r**2) = r*(exp(r)+1)/(exp(r)-1) = 2 + r*r/6 - r**4/360 + ...
994 + * We use a special Reme algorithm on [0,0.34658] to generate
995 + * a polynomial of degree 5 to approximate R. The maximum error
996 + * of this polynomial approximation is bounded by 2**-59. In
997 + * other words,
998 + * R(z) ~ 2.0 + P1*z + P2*z**2 + P3*z**3 + P4*z**4 + P5*z**5
999 + * (where z=r*r, and the values of P1 to P5 are listed below)
1000 + * and
1001 + * | 5 | -59
1002 + * | 2.0+P1*z+...+P5*z - R(z) | <= 2
1003 + * | |
1004 + * The computation of exp(r) thus becomes
1005 + * 2*r
1006 + * exp(r) = 1 + -------
1007 + * R - r
1008 + * r*R1(r)
1009 + * = 1 + r + ----------- (for better accuracy)
1010 + * 2 - R1(r)
1011 + * where
1012 + * 2 4 10
1013 + * R1(r) = r - (P1*r + P2*r + ... + P5*r ).
1015 + * 3. Scale back to obtain exp(x):
1016 + * From step 1, we have
1017 + * exp(x) = 2^k * exp(r)
1019 + * Special cases:
1020 + * exp(INF) is INF, exp(NaN) is NaN;
1021 + * exp(-INF) is 0, and
1022 + * for finite argument, only exp(0)=1 is exact.
1024 + * Accuracy:
1025 + * according to an error analysis, the error is always less than
1026 + * 1 ulp (unit in the last place).
1028 + * Misc. info.
1029 + * For IEEE double
1030 + * if x > 7.09782712893383973096e+02 then exp(x) overflow
1031 + * if x < -7.45133219101941108420e+02 then exp(x) underflow
1033 + * Constants:
1034 + * The hexadecimal values are the intended ones for the following
1035 + * constants. The decimal values may be used, provided that the
1036 + * compiler will convert from decimal to binary accurately enough
1037 + * to produce the hexadecimal values shown.
1038 + */
1040 +#include "math.h"
1041 +#include "math_private.h"
1043 +#ifdef __STDC__
1044 +static const double
1045 +#else
1046 +static double
1047 +#endif
1048 +one = 1.0,
1049 +halF[2] = {0.5,-0.5,},
1050 +huge = 1.0e+300,
1051 +twom1000= 9.33263618503218878990e-302, /* 2**-1000=0x01700000,0*/
1052 +o_threshold= 7.09782712893383973096e+02, /* 0x40862E42, 0xFEFA39EF */
1053 +u_threshold= -7.45133219101941108420e+02, /* 0xc0874910, 0xD52D3051 */
1054 +ln2HI[2] ={ 6.93147180369123816490e-01, /* 0x3fe62e42, 0xfee00000 */
1055 + -6.93147180369123816490e-01,},/* 0xbfe62e42, 0xfee00000 */
1056 +ln2LO[2] ={ 1.90821492927058770002e-10, /* 0x3dea39ef, 0x35793c76 */
1057 + -1.90821492927058770002e-10,},/* 0xbdea39ef, 0x35793c76 */
1058 +invln2 = 1.44269504088896338700e+00, /* 0x3ff71547, 0x652b82fe */
1059 +P1 = 1.66666666666666019037e-01, /* 0x3FC55555, 0x5555553E */
1060 +P2 = -2.77777777770155933842e-03, /* 0xBF66C16C, 0x16BEBD93 */
1061 +P3 = 6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */
1062 +P4 = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */
1063 +P5 = 4.13813679705723846039e-08; /* 0x3E663769, 0x72BEA4D0 */
1066 +#ifdef __STDC__
1067 + double __ieee754_exp(double x) /* default IEEE double exp */
1068 +#else
1069 + double __ieee754_exp(x) /* default IEEE double exp */
1070 + double x;
1071 +#endif
1073 + double y;
1074 + double hi = 0.0;
1075 + double lo = 0.0;
1076 + double c;
1077 + double t;
1078 + int32_t k=0;
1079 + int32_t xsb;
1080 + u_int32_t hx;
1082 + GET_HIGH_WORD(hx,x);
1083 + xsb = (hx>>31)&1; /* sign bit of x */
1084 + hx &= 0x7fffffff; /* high word of |x| */
1086 + /* filter out non-finite argument */
1087 + if(hx >= 0x40862E42) { /* if |x|>=709.78... */
1088 + if(hx>=0x7ff00000) {
1089 + u_int32_t lx;
1090 + GET_LOW_WORD(lx,x);
1091 + if(((hx&0xfffff)|lx)!=0)
1092 + return x+x; /* NaN */
1093 + else return (xsb==0)? x:0.0; /* exp(+-inf)={inf,0} */
1095 + if(x > o_threshold) return huge*huge; /* overflow */
1096 + if(x < u_threshold) return twom1000*twom1000; /* underflow */
1099 + /* argument reduction */
1100 + if(hx > 0x3fd62e42) { /* if |x| > 0.5 ln2 */
1101 + if(hx < 0x3FF0A2B2) { /* and |x| < 1.5 ln2 */
1102 + hi = x-ln2HI[xsb]; lo=ln2LO[xsb]; k = 1-xsb-xsb;
1103 + } else {
1104 + k = invln2*x+halF[xsb];
1105 + t = k;
1106 + hi = x - t*ln2HI[0]; /* t*ln2HI is exact here */
1107 + lo = t*ln2LO[0];
1109 + x = hi - lo;
1111 + else if(hx < 0x3e300000) { /* when |x|<2**-28 */
1112 + if(huge+x>one) return one+x;/* trigger inexact */
1114 + else k = 0;
1116 + /* x is now in primary range */
1117 + t = x*x;
1118 + c = x - t*(P1+t*(P2+t*(P3+t*(P4+t*P5))));
1119 + if(k==0) return one-((x*c)/(c-2.0)-x);
1120 + else y = one-((lo-(x*c)/(2.0-c))-hi);
1121 + if(k >= -1021) {
1122 + u_int32_t hy;
1123 + GET_HIGH_WORD(hy,y);
1124 + SET_HIGH_WORD(y,hy+(k<<20)); /* add k to y's exponent */
1125 + return y;
1126 + } else {
1127 + u_int32_t hy;
1128 + GET_HIGH_WORD(hy,y);
1129 + SET_HIGH_WORD(y,hy+((k+1000)<<20)); /* add k to y's exponent */
1130 + return y*twom1000;
1133 diff -urN dietlibc-0.30/libm/e_fmod.c dietlibc-0.30-libm/libm/e_fmod.c
1134 --- dietlibc-0.30/libm/e_fmod.c 1970-01-01 00:00:00.000000000 +0000
1135 +++ dietlibc-0.30-libm/libm/e_fmod.c 2006-06-25 11:20:07.000000000 +0000
1136 @@ -0,0 +1,140 @@
1137 +/* @(#)e_fmod.c 5.1 93/09/24 */
1139 + * ====================================================
1140 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
1142 + * Developed at SunPro, a Sun Microsystems, Inc. business.
1143 + * Permission to use, copy, modify, and distribute this
1144 + * software is freely granted, provided that this notice
1145 + * is preserved.
1146 + * ====================================================
1147 + */
1149 +#if defined(LIBM_SCCS) && !defined(lint)
1150 +static char rcsid[] = "$NetBSD: e_fmod.c,v 1.8 1995/05/10 20:45:07 jtc Exp $";
1151 +#endif
1154 + * __ieee754_fmod(x,y)
1155 + * Return x mod y in exact arithmetic
1156 + * Method: shift and subtract
1157 + */
1159 +#include "math.h"
1160 +#include "math_private.h"
1162 +#ifdef __STDC__
1163 +static const double one = 1.0, Zero[] = {0.0, -0.0,};
1164 +#else
1165 +static double one = 1.0, Zero[] = {0.0, -0.0,};
1166 +#endif
1168 +#ifdef __STDC__
1169 + double __ieee754_fmod(double x, double y)
1170 +#else
1171 + double __ieee754_fmod(x,y)
1172 + double x,y ;
1173 +#endif
1175 + int32_t n,hx,hy,hz,ix,iy,sx,i;
1176 + u_int32_t lx,ly,lz;
1178 + EXTRACT_WORDS(hx,lx,x);
1179 + EXTRACT_WORDS(hy,ly,y);
1180 + sx = hx&0x80000000; /* sign of x */
1181 + hx ^=sx; /* |x| */
1182 + hy &= 0x7fffffff; /* |y| */
1184 + /* purge off exception values */
1185 + if((hy|ly)==0||(hx>=0x7ff00000)|| /* y=0,or x not finite */
1186 + ((hy|((ly|-ly)>>31))>0x7ff00000)) /* or y is NaN */
1187 + return (x*y)/(x*y);
1188 + if(hx<=hy) {
1189 + if((hx<hy)||(lx<ly)) return x; /* |x|<|y| return x */
1190 + if(lx==ly)
1191 + return Zero[(u_int32_t)sx>>31]; /* |x|=|y| return x*0*/
1194 + /* determine ix = ilogb(x) */
1195 + if(hx<0x00100000) { /* subnormal x */
1196 + if(hx==0) {
1197 + for (ix = -1043, i=lx; i>0; i<<=1) ix -=1;
1198 + } else {
1199 + for (ix = -1022,i=(hx<<11); i>0; i<<=1) ix -=1;
1201 + } else ix = (hx>>20)-1023;
1203 + /* determine iy = ilogb(y) */
1204 + if(hy<0x00100000) { /* subnormal y */
1205 + if(hy==0) {
1206 + for (iy = -1043, i=ly; i>0; i<<=1) iy -=1;
1207 + } else {
1208 + for (iy = -1022,i=(hy<<11); i>0; i<<=1) iy -=1;
1210 + } else iy = (hy>>20)-1023;
1212 + /* set up {hx,lx}, {hy,ly} and align y to x */
1213 + if(ix >= -1022)
1214 + hx = 0x00100000|(0x000fffff&hx);
1215 + else { /* subnormal x, shift x to normal */
1216 + n = -1022-ix;
1217 + if(n<=31) {
1218 + hx = (hx<<n)|(lx>>(32-n));
1219 + lx <<= n;
1220 + } else {
1221 + hx = lx<<(n-32);
1222 + lx = 0;
1225 + if(iy >= -1022)
1226 + hy = 0x00100000|(0x000fffff&hy);
1227 + else { /* subnormal y, shift y to normal */
1228 + n = -1022-iy;
1229 + if(n<=31) {
1230 + hy = (hy<<n)|(ly>>(32-n));
1231 + ly <<= n;
1232 + } else {
1233 + hy = ly<<(n-32);
1234 + ly = 0;
1238 + /* fix point fmod */
1239 + n = ix - iy;
1240 + while(n--) {
1241 + hz=hx-hy;lz=lx-ly; if(lx<ly) hz -= 1;
1242 + if(hz<0){hx = hx+hx+(lx>>31); lx = lx+lx;}
1243 + else {
1244 + if((hz|lz)==0) /* return sign(x)*0 */
1245 + return Zero[(u_int32_t)sx>>31];
1246 + hx = hz+hz+(lz>>31); lx = lz+lz;
1249 + hz=hx-hy;lz=lx-ly; if(lx<ly) hz -= 1;
1250 + if(hz>=0) {hx=hz;lx=lz;}
1252 + /* convert back to floating value and restore the sign */
1253 + if((hx|lx)==0) /* return sign(x)*0 */
1254 + return Zero[(u_int32_t)sx>>31];
1255 + while(hx<0x00100000) { /* normalize x */
1256 + hx = hx+hx+(lx>>31); lx = lx+lx;
1257 + iy -= 1;
1259 + if(iy>= -1022) { /* normalize output */
1260 + hx = ((hx-0x00100000)|((iy+1023)<<20));
1261 + INSERT_WORDS(x,hx|sx,lx);
1262 + } else { /* subnormal output */
1263 + n = -1022 - iy;
1264 + if(n<=20) {
1265 + lx = (lx>>n)|((u_int32_t)hx<<(32-n));
1266 + hx >>= n;
1267 + } else if (n<=31) {
1268 + lx = (hx<<(32-n))|(lx>>n); hx = sx;
1269 + } else {
1270 + lx = hx>>(n-32); hx = sx;
1272 + INSERT_WORDS(x,hx|sx,lx);
1273 + x *= one; /* create necessary signal */
1275 + return x; /* exact output */
1277 diff -urN dietlibc-0.30/libm/e_gamma.c dietlibc-0.30-libm/libm/e_gamma.c
1278 --- dietlibc-0.30/libm/e_gamma.c 1970-01-01 00:00:00.000000000 +0000
1279 +++ dietlibc-0.30-libm/libm/e_gamma.c 2006-06-25 11:20:16.000000000 +0000
1280 @@ -0,0 +1,34 @@
1282 +/* @(#)e_gamma.c 5.1 93/09/24 */
1284 + * ====================================================
1285 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
1287 + * Developed at SunPro, a Sun Microsystems, Inc. business.
1288 + * Permission to use, copy, modify, and distribute this
1289 + * software is freely granted, provided that this notice
1290 + * is preserved.
1291 + * ====================================================
1293 + */
1295 +/* __ieee754_gamma(x)
1296 + * Return the logarithm of the Gamma function of x.
1298 + * Method: call __ieee754_gamma_r
1299 + */
1301 +#include "math_private.h"
1303 +extern int signgam;
1305 +#ifdef __STDC__
1306 + //__private_extern__
1307 + double __ieee754_gamma(double x)
1308 +#else
1309 + double __ieee754_gamma(x)
1310 + double x;
1311 +#endif
1313 + return __ieee754_gamma_r(x,&signgam);
1315 diff -urN dietlibc-0.30/libm/e_gamma_r.c dietlibc-0.30-libm/libm/e_gamma_r.c
1316 --- dietlibc-0.30/libm/e_gamma_r.c 1970-01-01 00:00:00.000000000 +0000
1317 +++ dietlibc-0.30-libm/libm/e_gamma_r.c 2006-06-25 11:20:20.000000000 +0000
1318 @@ -0,0 +1,33 @@
1320 +/* @(#)e_gamma_r.c 5.1 93/09/24 */
1322 + * ====================================================
1323 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
1325 + * Developed at SunPro, a Sun Microsystems, Inc. business.
1326 + * Permission to use, copy, modify, and distribute this
1327 + * software is freely granted, provided that this notice
1328 + * is preserved.
1329 + * ====================================================
1331 + */
1333 +/* __ieee754_gamma_r(x, signgamp)
1334 + * Reentrant version of the logarithm of the Gamma function
1335 + * with user provide pointer for the sign of Gamma(x).
1337 + * Method: See __ieee754_lgamma_r
1338 + */
1340 +#include "math_private.h"
1342 +#ifdef __STDC__
1343 + //__private_extern__
1344 + double __ieee754_gamma_r(double x, int *signgamp)
1345 +#else
1346 + double __ieee754_gamma_r(x,signgamp)
1347 + double x; int *signgamp;
1348 +#endif
1350 + return __ieee754_lgamma_r(x,signgamp);
1352 diff -urN dietlibc-0.30/libm/e_hypot.c dietlibc-0.30-libm/libm/e_hypot.c
1353 --- dietlibc-0.30/libm/e_hypot.c 1970-01-01 00:00:00.000000000 +0000
1354 +++ dietlibc-0.30-libm/libm/e_hypot.c 2006-06-25 11:20:00.000000000 +0000
1355 @@ -0,0 +1,128 @@
1356 +/* @(#)e_hypot.c 5.1 93/09/24 */
1358 + * ====================================================
1359 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
1361 + * Developed at SunPro, a Sun Microsystems, Inc. business.
1362 + * Permission to use, copy, modify, and distribute this
1363 + * software is freely granted, provided that this notice
1364 + * is preserved.
1365 + * ====================================================
1366 + */
1368 +#if defined(LIBM_SCCS) && !defined(lint)
1369 +static char rcsid[] = "$NetBSD: e_hypot.c,v 1.9 1995/05/12 04:57:27 jtc Exp $";
1370 +#endif
1372 +/* __ieee754_hypot(x,y)
1374 + * Method :
1375 + * If (assume round-to-nearest) z=x*x+y*y
1376 + * has error less than sqrt(2)/2 ulp, than
1377 + * sqrt(z) has error less than 1 ulp (exercise).
1379 + * So, compute sqrt(x*x+y*y) with some care as
1380 + * follows to get the error below 1 ulp:
1382 + * Assume x>y>0;
1383 + * (if possible, set rounding to round-to-nearest)
1384 + * 1. if x > 2y use
1385 + * x1*x1+(y*y+(x2*(x+x1))) for x*x+y*y
1386 + * where x1 = x with lower 32 bits cleared, x2 = x-x1; else
1387 + * 2. if x <= 2y use
1388 + * t1*y1+((x-y)*(x-y)+(t1*y2+t2*y))
1389 + * where t1 = 2x with lower 32 bits cleared, t2 = 2x-t1,
1390 + * y1= y with lower 32 bits chopped, y2 = y-y1.
1392 + * NOTE: scaling may be necessary if some argument is too
1393 + * large or too tiny
1395 + * Special cases:
1396 + * hypot(x,y) is INF if x or y is +INF or -INF; else
1397 + * hypot(x,y) is NAN if x or y is NAN.
1399 + * Accuracy:
1400 + * hypot(x,y) returns sqrt(x^2+y^2) with error less
1401 + * than 1 ulps (units in the last place)
1402 + */
1404 +#include "math.h"
1405 +#include "math_private.h"
1407 +#ifdef __STDC__
1408 + double __ieee754_hypot(double x, double y)
1409 +#else
1410 + double __ieee754_hypot(x,y)
1411 + double x, y;
1412 +#endif
1414 + double a=x,b=y,t1,t2,y1,y2,w;
1415 + int32_t j,k,ha,hb;
1417 + GET_HIGH_WORD(ha,x);
1418 + ha &= 0x7fffffff;
1419 + GET_HIGH_WORD(hb,y);
1420 + hb &= 0x7fffffff;
1421 + if(hb > ha) {a=y;b=x;j=ha; ha=hb;hb=j;} else {a=x;b=y;}
1422 + SET_HIGH_WORD(a,ha); /* a <- |a| */
1423 + SET_HIGH_WORD(b,hb); /* b <- |b| */
1424 + if((ha-hb)>0x3c00000) {return a+b;} /* x/y > 2**60 */
1425 + k=0;
1426 + if(ha > 0x5f300000) { /* a>2**500 */
1427 + if(ha >= 0x7ff00000) { /* Inf or NaN */
1428 + u_int32_t low;
1429 + w = a+b; /* for sNaN */
1430 + GET_LOW_WORD(low,a);
1431 + if(((ha&0xfffff)|low)==0) w = a;
1432 + GET_LOW_WORD(low,b);
1433 + if(((hb^0x7ff00000)|low)==0) w = b;
1434 + return w;
1436 + /* scale a and b by 2**-600 */
1437 + ha -= 0x25800000; hb -= 0x25800000; k += 600;
1438 + SET_HIGH_WORD(a,ha);
1439 + SET_HIGH_WORD(b,hb);
1441 + if(hb < 0x20b00000) { /* b < 2**-500 */
1442 + if(hb <= 0x000fffff) { /* subnormal b or 0 */
1443 + u_int32_t low;
1444 + GET_LOW_WORD(low,b);
1445 + if((hb|low)==0) return a;
1446 + t1=0;
1447 + SET_HIGH_WORD(t1,0x7fd00000); /* t1=2^1022 */
1448 + b *= t1;
1449 + a *= t1;
1450 + k -= 1022;
1451 + } else { /* scale a and b by 2^600 */
1452 + ha += 0x25800000; /* a *= 2^600 */
1453 + hb += 0x25800000; /* b *= 2^600 */
1454 + k -= 600;
1455 + SET_HIGH_WORD(a,ha);
1456 + SET_HIGH_WORD(b,hb);
1459 + /* medium size a and b */
1460 + w = a-b;
1461 + if (w>b) {
1462 + t1 = 0;
1463 + SET_HIGH_WORD(t1,ha);
1464 + t2 = a-t1;
1465 + w = __ieee754_sqrt(t1*t1-(b*(-b)-t2*(a+t1)));
1466 + } else {
1467 + a = a+a;
1468 + y1 = 0;
1469 + SET_HIGH_WORD(y1,hb);
1470 + y2 = b - y1;
1471 + t1 = 0;
1472 + SET_HIGH_WORD(t1,ha+0x00100000);
1473 + t2 = a - t1;
1474 + w = __ieee754_sqrt(t1*y1-(w*(-w)-(t1*y2+t2*b)));
1476 + if(k!=0) {
1477 + u_int32_t high;
1478 + t1 = 1.0;
1479 + GET_HIGH_WORD(high,t1);
1480 + SET_HIGH_WORD(t1,high+(k<<20));
1481 + return t1*w;
1482 + } else return w;
1484 diff -urN dietlibc-0.30/libm/e_j0.c dietlibc-0.30-libm/libm/e_j0.c
1485 --- dietlibc-0.30/libm/e_j0.c 1970-01-01 00:00:00.000000000 +0000
1486 +++ dietlibc-0.30-libm/libm/e_j0.c 2006-06-25 11:20:13.000000000 +0000
1487 @@ -0,0 +1,487 @@
1488 +/* @(#)e_j0.c 5.1 93/09/24 */
1490 + * ====================================================
1491 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
1493 + * Developed at SunPro, a Sun Microsystems, Inc. business.
1494 + * Permission to use, copy, modify, and distribute this
1495 + * software is freely granted, provided that this notice
1496 + * is preserved.
1497 + * ====================================================
1498 + */
1500 +#if defined(LIBM_SCCS) && !defined(lint)
1501 +static char rcsid[] = "$NetBSD: e_j0.c,v 1.8 1995/05/10 20:45:23 jtc Exp $";
1502 +#endif
1504 +/* __ieee754_j0(x), __ieee754_y0(x)
1505 + * Bessel function of the first and second kinds of order zero.
1506 + * Method -- j0(x):
1507 + * 1. For tiny x, we use j0(x) = 1 - x^2/4 + x^4/64 - ...
1508 + * 2. Reduce x to |x| since j0(x)=j0(-x), and
1509 + * for x in (0,2)
1510 + * j0(x) = 1-z/4+ z^2*R0/S0, where z = x*x;
1511 + * (precision: |j0-1+z/4-z^2R0/S0 |<2**-63.67 )
1512 + * for x in (2,inf)
1513 + * j0(x) = sqrt(2/(pi*x))*(p0(x)*cos(x0)-q0(x)*sin(x0))
1514 + * where x0 = x-pi/4. It is better to compute sin(x0),cos(x0)
1515 + * as follow:
1516 + * cos(x0) = cos(x)cos(pi/4)+sin(x)sin(pi/4)
1517 + * = 1/sqrt(2) * (cos(x) + sin(x))
1518 + * sin(x0) = sin(x)cos(pi/4)-cos(x)sin(pi/4)
1519 + * = 1/sqrt(2) * (sin(x) - cos(x))
1520 + * (To avoid cancellation, use
1521 + * sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
1522 + * to compute the worse one.)
1524 + * 3 Special cases
1525 + * j0(nan)= nan
1526 + * j0(0) = 1
1527 + * j0(inf) = 0
1529 + * Method -- y0(x):
1530 + * 1. For x<2.
1531 + * Since
1532 + * y0(x) = 2/pi*(j0(x)*(ln(x/2)+Euler) + x^2/4 - ...)
1533 + * therefore y0(x)-2/pi*j0(x)*ln(x) is an even function.
1534 + * We use the following function to approximate y0,
1535 + * y0(x) = U(z)/V(z) + (2/pi)*(j0(x)*ln(x)), z= x^2
1536 + * where
1537 + * U(z) = u00 + u01*z + ... + u06*z^6
1538 + * V(z) = 1 + v01*z + ... + v04*z^4
1539 + * with absolute approximation error bounded by 2**-72.
1540 + * Note: For tiny x, U/V = u0 and j0(x)~1, hence
1541 + * y0(tiny) = u0 + (2/pi)*ln(tiny), (choose tiny<2**-27)
1542 + * 2. For x>=2.
1543 + * y0(x) = sqrt(2/(pi*x))*(p0(x)*cos(x0)+q0(x)*sin(x0))
1544 + * where x0 = x-pi/4. It is better to compute sin(x0),cos(x0)
1545 + * by the method mentioned above.
1546 + * 3. Special cases: y0(0)=-inf, y0(x<0)=NaN, y0(inf)=0.
1547 + */
1549 +#include "math.h"
1550 +#include "math_private.h"
1552 +#ifdef __STDC__
1553 +static double pzero(double), qzero(double);
1554 +#else
1555 +static double pzero(), qzero();
1556 +#endif
1558 +#ifdef __STDC__
1559 +static const double
1560 +#else
1561 +static double
1562 +#endif
1563 +huge = 1e300,
1564 +one = 1.0,
1565 +invsqrtpi= 5.64189583547756279280e-01, /* 0x3FE20DD7, 0x50429B6D */
1566 +tpi = 6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */
1567 + /* R0/S0 on [0, 2.00] */
1568 +R02 = 1.56249999999999947958e-02, /* 0x3F8FFFFF, 0xFFFFFFFD */
1569 +R03 = -1.89979294238854721751e-04, /* 0xBF28E6A5, 0xB61AC6E9 */
1570 +R04 = 1.82954049532700665670e-06, /* 0x3EBEB1D1, 0x0C503919 */
1571 +R05 = -4.61832688532103189199e-09, /* 0xBE33D5E7, 0x73D63FCE */
1572 +S01 = 1.56191029464890010492e-02, /* 0x3F8FFCE8, 0x82C8C2A4 */
1573 +S02 = 1.16926784663337450260e-04, /* 0x3F1EA6D2, 0xDD57DBF4 */
1574 +S03 = 5.13546550207318111446e-07, /* 0x3EA13B54, 0xCE84D5A9 */
1575 +S04 = 1.16614003333790000205e-09; /* 0x3E1408BC, 0xF4745D8F */
1577 +#ifdef __STDC__
1578 +static const double zero = 0.0;
1579 +#else
1580 +static double zero = 0.0;
1581 +#endif
1583 +#ifdef __STDC__
1584 + double __ieee754_j0(double x)
1585 +#else
1586 + double __ieee754_j0(x)
1587 + double x;
1588 +#endif
1590 + double z, s,c,ss,cc,r,u,v;
1591 + int32_t hx,ix;
1593 + GET_HIGH_WORD(hx,x);
1594 + ix = hx&0x7fffffff;
1595 + if(ix>=0x7ff00000) return one/(x*x);
1596 + x = fabs(x);
1597 + if(ix >= 0x40000000) { /* |x| >= 2.0 */
1598 + s = sin(x);
1599 + c = cos(x);
1600 + ss = s-c;
1601 + cc = s+c;
1602 + if(ix<0x7fe00000) { /* make sure x+x not overflow */
1603 + z = -cos(x+x);
1604 + if ((s*c)<zero) cc = z/ss;
1605 + else ss = z/cc;
1607 + /*
1608 + * j0(x) = 1/sqrt(pi) * (P(0,x)*cc - Q(0,x)*ss) / sqrt(x)
1609 + * y0(x) = 1/sqrt(pi) * (P(0,x)*ss + Q(0,x)*cc) / sqrt(x)
1610 + */
1611 + if(ix>0x48000000) z = (invsqrtpi*cc)/sqrt(x);
1612 + else {
1613 + u = pzero(x); v = qzero(x);
1614 + z = invsqrtpi*(u*cc-v*ss)/sqrt(x);
1616 + return z;
1618 + if(ix<0x3f200000) { /* |x| < 2**-13 */
1619 + if(huge+x>one) { /* raise inexact if x != 0 */
1620 + if(ix<0x3e400000) return one; /* |x|<2**-27 */
1621 + else return one - 0.25*x*x;
1624 + z = x*x;
1625 + r = z*(R02+z*(R03+z*(R04+z*R05)));
1626 + s = one+z*(S01+z*(S02+z*(S03+z*S04)));
1627 + if(ix < 0x3FF00000) { /* |x| < 1.00 */
1628 + return one + z*(-0.25+(r/s));
1629 + } else {
1630 + u = 0.5*x;
1631 + return((one+u)*(one-u)+z*(r/s));
1635 +#ifdef __STDC__
1636 +static const double
1637 +#else
1638 +static double
1639 +#endif
1640 +u00 = -7.38042951086872317523e-02, /* 0xBFB2E4D6, 0x99CBD01F */
1641 +u01 = 1.76666452509181115538e-01, /* 0x3FC69D01, 0x9DE9E3FC */
1642 +u02 = -1.38185671945596898896e-02, /* 0xBF8C4CE8, 0xB16CFA97 */
1643 +u03 = 3.47453432093683650238e-04, /* 0x3F36C54D, 0x20B29B6B */
1644 +u04 = -3.81407053724364161125e-06, /* 0xBECFFEA7, 0x73D25CAD */
1645 +u05 = 1.95590137035022920206e-08, /* 0x3E550057, 0x3B4EABD4 */
1646 +u06 = -3.98205194132103398453e-11, /* 0xBDC5E43D, 0x693FB3C8 */
1647 +v01 = 1.27304834834123699328e-02, /* 0x3F8A1270, 0x91C9C71A */
1648 +v02 = 7.60068627350353253702e-05, /* 0x3F13ECBB, 0xF578C6C1 */
1649 +v03 = 2.59150851840457805467e-07, /* 0x3E91642D, 0x7FF202FD */
1650 +v04 = 4.41110311332675467403e-10; /* 0x3DFE5018, 0x3BD6D9EF */
1652 +#ifdef __STDC__
1653 + double __ieee754_y0(double x)
1654 +#else
1655 + double __ieee754_y0(x)
1656 + double x;
1657 +#endif
1659 + double z, s,c,ss,cc,u,v;
1660 + int32_t hx,ix,lx;
1662 + EXTRACT_WORDS(hx,lx,x);
1663 + ix = 0x7fffffff&hx;
1664 + /* Y0(NaN) is NaN, y0(-inf) is Nan, y0(inf) is 0 */
1665 + if(ix>=0x7ff00000) return one/(x+x*x);
1666 + if((ix|lx)==0) return -one/zero;
1667 + if(hx<0) return zero/zero;
1668 + if(ix >= 0x40000000) { /* |x| >= 2.0 */
1669 + /* y0(x) = sqrt(2/(pi*x))*(p0(x)*sin(x0)+q0(x)*cos(x0))
1670 + * where x0 = x-pi/4
1671 + * Better formula:
1672 + * cos(x0) = cos(x)cos(pi/4)+sin(x)sin(pi/4)
1673 + * = 1/sqrt(2) * (sin(x) + cos(x))
1674 + * sin(x0) = sin(x)cos(3pi/4)-cos(x)sin(3pi/4)
1675 + * = 1/sqrt(2) * (sin(x) - cos(x))
1676 + * To avoid cancellation, use
1677 + * sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
1678 + * to compute the worse one.
1679 + */
1680 + s = sin(x);
1681 + c = cos(x);
1682 + ss = s-c;
1683 + cc = s+c;
1684 + /*
1685 + * j0(x) = 1/sqrt(pi) * (P(0,x)*cc - Q(0,x)*ss) / sqrt(x)
1686 + * y0(x) = 1/sqrt(pi) * (P(0,x)*ss + Q(0,x)*cc) / sqrt(x)
1687 + */
1688 + if(ix<0x7fe00000) { /* make sure x+x not overflow */
1689 + z = -cos(x+x);
1690 + if ((s*c)<zero) cc = z/ss;
1691 + else ss = z/cc;
1693 + if(ix>0x48000000) z = (invsqrtpi*ss)/sqrt(x);
1694 + else {
1695 + u = pzero(x); v = qzero(x);
1696 + z = invsqrtpi*(u*ss+v*cc)/sqrt(x);
1698 + return z;
1700 + if(ix<=0x3e400000) { /* x < 2**-27 */
1701 + return(u00 + tpi*__ieee754_log(x));
1703 + z = x*x;
1704 + u = u00+z*(u01+z*(u02+z*(u03+z*(u04+z*(u05+z*u06)))));
1705 + v = one+z*(v01+z*(v02+z*(v03+z*v04)));
1706 + return(u/v + tpi*(__ieee754_j0(x)*__ieee754_log(x)));
1709 +/* The asymptotic expansions of pzero is
1710 + * 1 - 9/128 s^2 + 11025/98304 s^4 - ..., where s = 1/x.
1711 + * For x >= 2, We approximate pzero by
1712 + * pzero(x) = 1 + (R/S)
1713 + * where R = pR0 + pR1*s^2 + pR2*s^4 + ... + pR5*s^10
1714 + * S = 1 + pS0*s^2 + ... + pS4*s^10
1715 + * and
1716 + * | pzero(x)-1-R/S | <= 2 ** ( -60.26)
1717 + */
1718 +#ifdef __STDC__
1719 +static const double pR8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
1720 +#else
1721 +static double pR8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
1722 +#endif
1723 + 0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */
1724 + -7.03124999999900357484e-02, /* 0xBFB1FFFF, 0xFFFFFD32 */
1725 + -8.08167041275349795626e+00, /* 0xC02029D0, 0xB44FA779 */
1726 + -2.57063105679704847262e+02, /* 0xC0701102, 0x7B19E863 */
1727 + -2.48521641009428822144e+03, /* 0xC0A36A6E, 0xCD4DCAFC */
1728 + -5.25304380490729545272e+03, /* 0xC0B4850B, 0x36CC643D */
1730 +#ifdef __STDC__
1731 +static const double pS8[5] = {
1732 +#else
1733 +static double pS8[5] = {
1734 +#endif
1735 + 1.16534364619668181717e+02, /* 0x405D2233, 0x07A96751 */
1736 + 3.83374475364121826715e+03, /* 0x40ADF37D, 0x50596938 */
1737 + 4.05978572648472545552e+04, /* 0x40E3D2BB, 0x6EB6B05F */
1738 + 1.16752972564375915681e+05, /* 0x40FC810F, 0x8F9FA9BD */
1739 + 4.76277284146730962675e+04, /* 0x40E74177, 0x4F2C49DC */
1742 +#ifdef __STDC__
1743 +static const double pR5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
1744 +#else
1745 +static double pR5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
1746 +#endif
1747 + -1.14125464691894502584e-11, /* 0xBDA918B1, 0x47E495CC */
1748 + -7.03124940873599280078e-02, /* 0xBFB1FFFF, 0xE69AFBC6 */
1749 + -4.15961064470587782438e+00, /* 0xC010A370, 0xF90C6BBF */
1750 + -6.76747652265167261021e+01, /* 0xC050EB2F, 0x5A7D1783 */
1751 + -3.31231299649172967747e+02, /* 0xC074B3B3, 0x6742CC63 */
1752 + -3.46433388365604912451e+02, /* 0xC075A6EF, 0x28A38BD7 */
1754 +#ifdef __STDC__
1755 +static const double pS5[5] = {
1756 +#else
1757 +static double pS5[5] = {
1758 +#endif
1759 + 6.07539382692300335975e+01, /* 0x404E6081, 0x0C98C5DE */
1760 + 1.05125230595704579173e+03, /* 0x40906D02, 0x5C7E2864 */
1761 + 5.97897094333855784498e+03, /* 0x40B75AF8, 0x8FBE1D60 */
1762 + 9.62544514357774460223e+03, /* 0x40C2CCB8, 0xFA76FA38 */
1763 + 2.40605815922939109441e+03, /* 0x40A2CC1D, 0xC70BE864 */
1766 +#ifdef __STDC__
1767 +static const double pR3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
1768 +#else
1769 +static double pR3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
1770 +#endif
1771 + -2.54704601771951915620e-09, /* 0xBE25E103, 0x6FE1AA86 */
1772 + -7.03119616381481654654e-02, /* 0xBFB1FFF6, 0xF7C0E24B */
1773 + -2.40903221549529611423e+00, /* 0xC00345B2, 0xAEA48074 */
1774 + -2.19659774734883086467e+01, /* 0xC035F74A, 0x4CB94E14 */
1775 + -5.80791704701737572236e+01, /* 0xC04D0A22, 0x420A1A45 */
1776 + -3.14479470594888503854e+01, /* 0xC03F72AC, 0xA892D80F */
1778 +#ifdef __STDC__
1779 +static const double pS3[5] = {
1780 +#else
1781 +static double pS3[5] = {
1782 +#endif
1783 + 3.58560338055209726349e+01, /* 0x4041ED92, 0x84077DD3 */
1784 + 3.61513983050303863820e+02, /* 0x40769839, 0x464A7C0E */
1785 + 1.19360783792111533330e+03, /* 0x4092A66E, 0x6D1061D6 */
1786 + 1.12799679856907414432e+03, /* 0x40919FFC, 0xB8C39B7E */
1787 + 1.73580930813335754692e+02, /* 0x4065B296, 0xFC379081 */
1790 +#ifdef __STDC__
1791 +static const double pR2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
1792 +#else
1793 +static double pR2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
1794 +#endif
1795 + -8.87534333032526411254e-08, /* 0xBE77D316, 0xE927026D */
1796 + -7.03030995483624743247e-02, /* 0xBFB1FF62, 0x495E1E42 */
1797 + -1.45073846780952986357e+00, /* 0xBFF73639, 0x8A24A843 */
1798 + -7.63569613823527770791e+00, /* 0xC01E8AF3, 0xEDAFA7F3 */
1799 + -1.11931668860356747786e+01, /* 0xC02662E6, 0xC5246303 */
1800 + -3.23364579351335335033e+00, /* 0xC009DE81, 0xAF8FE70F */
1802 +#ifdef __STDC__
1803 +static const double pS2[5] = {
1804 +#else
1805 +static double pS2[5] = {
1806 +#endif
1807 + 2.22202997532088808441e+01, /* 0x40363865, 0x908B5959 */
1808 + 1.36206794218215208048e+02, /* 0x4061069E, 0x0EE8878F */
1809 + 2.70470278658083486789e+02, /* 0x4070E786, 0x42EA079B */
1810 + 1.53875394208320329881e+02, /* 0x40633C03, 0x3AB6FAFF */
1811 + 1.46576176948256193810e+01, /* 0x402D50B3, 0x44391809 */
1814 +#ifdef __STDC__
1815 + static double pzero(double x)
1816 +#else
1817 + static double pzero(x)
1818 + double x;
1819 +#endif
1821 +#ifdef __STDC__
1822 + const double *p = 0,*q = 0;
1823 +#else
1824 + double *p,*q;
1825 +#endif
1826 + double z,r,s;
1827 + int32_t ix;
1828 + GET_HIGH_WORD(ix,x);
1829 + ix &= 0x7fffffff;
1830 + if(ix>=0x40200000) {p = pR8; q= pS8;}
1831 + else if(ix>=0x40122E8B){p = pR5; q= pS5;}
1832 + else if(ix>=0x4006DB6D){p = pR3; q= pS3;}
1833 + else if(ix>=0x40000000){p = pR2; q= pS2;}
1834 + z = one/(x*x);
1835 + r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
1836 + s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4]))));
1837 + return one+ r/s;
1841 +/* For x >= 8, the asymptotic expansions of qzero is
1842 + * -1/8 s + 75/1024 s^3 - ..., where s = 1/x.
1843 + * We approximate pzero by
1844 + * qzero(x) = s*(-1.25 + (R/S))
1845 + * where R = qR0 + qR1*s^2 + qR2*s^4 + ... + qR5*s^10
1846 + * S = 1 + qS0*s^2 + ... + qS5*s^12
1847 + * and
1848 + * | qzero(x)/s +1.25-R/S | <= 2 ** ( -61.22)
1849 + */
1850 +#ifdef __STDC__
1851 +static const double qR8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
1852 +#else
1853 +static double qR8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
1854 +#endif
1855 + 0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */
1856 + 7.32421874999935051953e-02, /* 0x3FB2BFFF, 0xFFFFFE2C */
1857 + 1.17682064682252693899e+01, /* 0x40278952, 0x5BB334D6 */
1858 + 5.57673380256401856059e+02, /* 0x40816D63, 0x15301825 */
1859 + 8.85919720756468632317e+03, /* 0x40C14D99, 0x3E18F46D */
1860 + 3.70146267776887834771e+04, /* 0x40E212D4, 0x0E901566 */
1862 +#ifdef __STDC__
1863 +static const double qS8[6] = {
1864 +#else
1865 +static double qS8[6] = {
1866 +#endif
1867 + 1.63776026895689824414e+02, /* 0x406478D5, 0x365B39BC */
1868 + 8.09834494656449805916e+03, /* 0x40BFA258, 0x4E6B0563 */
1869 + 1.42538291419120476348e+05, /* 0x41016652, 0x54D38C3F */
1870 + 8.03309257119514397345e+05, /* 0x412883DA, 0x83A52B43 */
1871 + 8.40501579819060512818e+05, /* 0x4129A66B, 0x28DE0B3D */
1872 + -3.43899293537866615225e+05, /* 0xC114FD6D, 0x2C9530C5 */
1875 +#ifdef __STDC__
1876 +static const double qR5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
1877 +#else
1878 +static double qR5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
1879 +#endif
1880 + 1.84085963594515531381e-11, /* 0x3DB43D8F, 0x29CC8CD9 */
1881 + 7.32421766612684765896e-02, /* 0x3FB2BFFF, 0xD172B04C */
1882 + 5.83563508962056953777e+00, /* 0x401757B0, 0xB9953DD3 */
1883 + 1.35111577286449829671e+02, /* 0x4060E392, 0x0A8788E9 */
1884 + 1.02724376596164097464e+03, /* 0x40900CF9, 0x9DC8C481 */
1885 + 1.98997785864605384631e+03, /* 0x409F17E9, 0x53C6E3A6 */
1887 +#ifdef __STDC__
1888 +static const double qS5[6] = {
1889 +#else
1890 +static double qS5[6] = {
1891 +#endif
1892 + 8.27766102236537761883e+01, /* 0x4054B1B3, 0xFB5E1543 */
1893 + 2.07781416421392987104e+03, /* 0x40A03BA0, 0xDA21C0CE */
1894 + 1.88472887785718085070e+04, /* 0x40D267D2, 0x7B591E6D */
1895 + 5.67511122894947329769e+04, /* 0x40EBB5E3, 0x97E02372 */
1896 + 3.59767538425114471465e+04, /* 0x40E19118, 0x1F7A54A0 */
1897 + -5.35434275601944773371e+03, /* 0xC0B4EA57, 0xBEDBC609 */
1900 +#ifdef __STDC__
1901 +static const double qR3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
1902 +#else
1903 +static double qR3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
1904 +#endif
1905 + 4.37741014089738620906e-09, /* 0x3E32CD03, 0x6ADECB82 */
1906 + 7.32411180042911447163e-02, /* 0x3FB2BFEE, 0x0E8D0842 */
1907 + 3.34423137516170720929e+00, /* 0x400AC0FC, 0x61149CF5 */
1908 + 4.26218440745412650017e+01, /* 0x40454F98, 0x962DAEDD */
1909 + 1.70808091340565596283e+02, /* 0x406559DB, 0xE25EFD1F */
1910 + 1.66733948696651168575e+02, /* 0x4064D77C, 0x81FA21E0 */
1912 +#ifdef __STDC__
1913 +static const double qS3[6] = {
1914 +#else
1915 +static double qS3[6] = {
1916 +#endif
1917 + 4.87588729724587182091e+01, /* 0x40486122, 0xBFE343A6 */
1918 + 7.09689221056606015736e+02, /* 0x40862D83, 0x86544EB3 */
1919 + 3.70414822620111362994e+03, /* 0x40ACF04B, 0xE44DFC63 */
1920 + 6.46042516752568917582e+03, /* 0x40B93C6C, 0xD7C76A28 */
1921 + 2.51633368920368957333e+03, /* 0x40A3A8AA, 0xD94FB1C0 */
1922 + -1.49247451836156386662e+02, /* 0xC062A7EB, 0x201CF40F */
1925 +#ifdef __STDC__
1926 +static const double qR2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
1927 +#else
1928 +static double qR2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
1929 +#endif
1930 + 1.50444444886983272379e-07, /* 0x3E84313B, 0x54F76BDB */
1931 + 7.32234265963079278272e-02, /* 0x3FB2BEC5, 0x3E883E34 */
1932 + 1.99819174093815998816e+00, /* 0x3FFFF897, 0xE727779C */
1933 + 1.44956029347885735348e+01, /* 0x402CFDBF, 0xAAF96FE5 */
1934 + 3.16662317504781540833e+01, /* 0x403FAA8E, 0x29FBDC4A */
1935 + 1.62527075710929267416e+01, /* 0x403040B1, 0x71814BB4 */
1937 +#ifdef __STDC__
1938 +static const double qS2[6] = {
1939 +#else
1940 +static double qS2[6] = {
1941 +#endif
1942 + 3.03655848355219184498e+01, /* 0x403E5D96, 0xF7C07AED */
1943 + 2.69348118608049844624e+02, /* 0x4070D591, 0xE4D14B40 */
1944 + 8.44783757595320139444e+02, /* 0x408A6645, 0x22B3BF22 */
1945 + 8.82935845112488550512e+02, /* 0x408B977C, 0x9C5CC214 */
1946 + 2.12666388511798828631e+02, /* 0x406A9553, 0x0E001365 */
1947 + -5.31095493882666946917e+00, /* 0xC0153E6A, 0xF8B32931 */
1950 +#ifdef __STDC__
1951 + static double qzero(double x)
1952 +#else
1953 + static double qzero(x)
1954 + double x;
1955 +#endif
1957 +#ifdef __STDC__
1958 + const double *p=0,*q=0;
1959 +#else
1960 + double *p,*q;
1961 +#endif
1962 + double s,r,z;
1963 + int32_t ix;
1964 + GET_HIGH_WORD(ix,x);
1965 + ix &= 0x7fffffff;
1966 + if(ix>=0x40200000) {p = qR8; q= qS8;}
1967 + else if(ix>=0x40122E8B){p = qR5; q= qS5;}
1968 + else if(ix>=0x4006DB6D){p = qR3; q= qS3;}
1969 + else if(ix>=0x40000000){p = qR2; q= qS2;}
1970 + z = one/(x*x);
1971 + r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
1972 + s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5])))));
1973 + return (-.125 + r/s)/x;
1975 diff -urN dietlibc-0.30/libm/e_j1.c dietlibc-0.30-libm/libm/e_j1.c
1976 --- dietlibc-0.30/libm/e_j1.c 1970-01-01 00:00:00.000000000 +0000
1977 +++ dietlibc-0.30-libm/libm/e_j1.c 2006-06-25 11:20:13.000000000 +0000
1978 @@ -0,0 +1,486 @@
1979 +/* @(#)e_j1.c 5.1 93/09/24 */
1981 + * ====================================================
1982 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
1984 + * Developed at SunPro, a Sun Microsystems, Inc. business.
1985 + * Permission to use, copy, modify, and distribute this
1986 + * software is freely granted, provided that this notice
1987 + * is preserved.
1988 + * ====================================================
1989 + */
1991 +#if defined(LIBM_SCCS) && !defined(lint)
1992 +static char rcsid[] = "$NetBSD: e_j1.c,v 1.8 1995/05/10 20:45:27 jtc Exp $";
1993 +#endif
1995 +/* __ieee754_j1(x), __ieee754_y1(x)
1996 + * Bessel function of the first and second kinds of order zero.
1997 + * Method -- j1(x):
1998 + * 1. For tiny x, we use j1(x) = x/2 - x^3/16 + x^5/384 - ...
1999 + * 2. Reduce x to |x| since j1(x)=-j1(-x), and
2000 + * for x in (0,2)
2001 + * j1(x) = x/2 + x*z*R0/S0, where z = x*x;
2002 + * (precision: |j1/x - 1/2 - R0/S0 |<2**-61.51 )
2003 + * for x in (2,inf)
2004 + * j1(x) = sqrt(2/(pi*x))*(p1(x)*cos(x1)-q1(x)*sin(x1))
2005 + * y1(x) = sqrt(2/(pi*x))*(p1(x)*sin(x1)+q1(x)*cos(x1))
2006 + * where x1 = x-3*pi/4. It is better to compute sin(x1),cos(x1)
2007 + * as follow:
2008 + * cos(x1) = cos(x)cos(3pi/4)+sin(x)sin(3pi/4)
2009 + * = 1/sqrt(2) * (sin(x) - cos(x))
2010 + * sin(x1) = sin(x)cos(3pi/4)-cos(x)sin(3pi/4)
2011 + * = -1/sqrt(2) * (sin(x) + cos(x))
2012 + * (To avoid cancellation, use
2013 + * sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
2014 + * to compute the worse one.)
2016 + * 3 Special cases
2017 + * j1(nan)= nan
2018 + * j1(0) = 0
2019 + * j1(inf) = 0
2021 + * Method -- y1(x):
2022 + * 1. screen out x<=0 cases: y1(0)=-inf, y1(x<0)=NaN
2023 + * 2. For x<2.
2024 + * Since
2025 + * y1(x) = 2/pi*(j1(x)*(ln(x/2)+Euler)-1/x-x/2+5/64*x^3-...)
2026 + * therefore y1(x)-2/pi*j1(x)*ln(x)-1/x is an odd function.
2027 + * We use the following function to approximate y1,
2028 + * y1(x) = x*U(z)/V(z) + (2/pi)*(j1(x)*ln(x)-1/x), z= x^2
2029 + * where for x in [0,2] (abs err less than 2**-65.89)
2030 + * U(z) = U0[0] + U0[1]*z + ... + U0[4]*z^4
2031 + * V(z) = 1 + v0[0]*z + ... + v0[4]*z^5
2032 + * Note: For tiny x, 1/x dominate y1 and hence
2033 + * y1(tiny) = -2/pi/tiny, (choose tiny<2**-54)
2034 + * 3. For x>=2.
2035 + * y1(x) = sqrt(2/(pi*x))*(p1(x)*sin(x1)+q1(x)*cos(x1))
2036 + * where x1 = x-3*pi/4. It is better to compute sin(x1),cos(x1)
2037 + * by method mentioned above.
2038 + */
2040 +#include "math.h"
2041 +#include "math_private.h"
2043 +#ifdef __STDC__
2044 +static double pone(double), qone(double);
2045 +#else
2046 +static double pone(), qone();
2047 +#endif
2049 +#ifdef __STDC__
2050 +static const double
2051 +#else
2052 +static double
2053 +#endif
2054 +huge = 1e300,
2055 +one = 1.0,
2056 +invsqrtpi= 5.64189583547756279280e-01, /* 0x3FE20DD7, 0x50429B6D */
2057 +tpi = 6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */
2058 + /* R0/S0 on [0,2] */
2059 +r00 = -6.25000000000000000000e-02, /* 0xBFB00000, 0x00000000 */
2060 +r01 = 1.40705666955189706048e-03, /* 0x3F570D9F, 0x98472C61 */
2061 +r02 = -1.59955631084035597520e-05, /* 0xBEF0C5C6, 0xBA169668 */
2062 +r03 = 4.96727999609584448412e-08, /* 0x3E6AAAFA, 0x46CA0BD9 */
2063 +s01 = 1.91537599538363460805e-02, /* 0x3F939D0B, 0x12637E53 */
2064 +s02 = 1.85946785588630915560e-04, /* 0x3F285F56, 0xB9CDF664 */
2065 +s03 = 1.17718464042623683263e-06, /* 0x3EB3BFF8, 0x333F8498 */
2066 +s04 = 5.04636257076217042715e-09, /* 0x3E35AC88, 0xC97DFF2C */
2067 +s05 = 1.23542274426137913908e-11; /* 0x3DAB2ACF, 0xCFB97ED8 */
2069 +#ifdef __STDC__
2070 +static const double zero = 0.0;
2071 +#else
2072 +static double zero = 0.0;
2073 +#endif
2075 +#ifdef __STDC__
2076 + double __ieee754_j1(double x)
2077 +#else
2078 + double __ieee754_j1(x)
2079 + double x;
2080 +#endif
2082 + double z, s,c,ss,cc,r,u,v,y;
2083 + int32_t hx,ix;
2085 + GET_HIGH_WORD(hx,x);
2086 + ix = hx&0x7fffffff;
2087 + if(ix>=0x7ff00000) return one/x;
2088 + y = fabs(x);
2089 + if(ix >= 0x40000000) { /* |x| >= 2.0 */
2090 + s = sin(y);
2091 + c = cos(y);
2092 + ss = -s-c;
2093 + cc = s-c;
2094 + if(ix<0x7fe00000) { /* make sure y+y not overflow */
2095 + z = cos(y+y);
2096 + if ((s*c)>zero) cc = z/ss;
2097 + else ss = z/cc;
2099 + /*
2100 + * j1(x) = 1/sqrt(pi) * (P(1,x)*cc - Q(1,x)*ss) / sqrt(x)
2101 + * y1(x) = 1/sqrt(pi) * (P(1,x)*ss + Q(1,x)*cc) / sqrt(x)
2102 + */
2103 + if(ix>0x48000000) z = (invsqrtpi*cc)/sqrt(y);
2104 + else {
2105 + u = pone(y); v = qone(y);
2106 + z = invsqrtpi*(u*cc-v*ss)/sqrt(y);
2108 + if(hx<0) return -z;
2109 + else return z;
2111 + if(ix<0x3e400000) { /* |x|<2**-27 */
2112 + if(huge+x>one) return 0.5*x;/* inexact if x!=0 necessary */
2114 + z = x*x;
2115 + r = z*(r00+z*(r01+z*(r02+z*r03)));
2116 + s = one+z*(s01+z*(s02+z*(s03+z*(s04+z*s05))));
2117 + r *= x;
2118 + return(x*0.5+r/s);
2121 +#ifdef __STDC__
2122 +static const double U0[5] = {
2123 +#else
2124 +static double U0[5] = {
2125 +#endif
2126 + -1.96057090646238940668e-01, /* 0xBFC91866, 0x143CBC8A */
2127 + 5.04438716639811282616e-02, /* 0x3FA9D3C7, 0x76292CD1 */
2128 + -1.91256895875763547298e-03, /* 0xBF5F55E5, 0x4844F50F */
2129 + 2.35252600561610495928e-05, /* 0x3EF8AB03, 0x8FA6B88E */
2130 + -9.19099158039878874504e-08, /* 0xBE78AC00, 0x569105B8 */
2132 +#ifdef __STDC__
2133 +static const double V0[5] = {
2134 +#else
2135 +static double V0[5] = {
2136 +#endif
2137 + 1.99167318236649903973e-02, /* 0x3F94650D, 0x3F4DA9F0 */
2138 + 2.02552581025135171496e-04, /* 0x3F2A8C89, 0x6C257764 */
2139 + 1.35608801097516229404e-06, /* 0x3EB6C05A, 0x894E8CA6 */
2140 + 6.22741452364621501295e-09, /* 0x3E3ABF1D, 0x5BA69A86 */
2141 + 1.66559246207992079114e-11, /* 0x3DB25039, 0xDACA772A */
2144 +#ifdef __STDC__
2145 + double __ieee754_y1(double x)
2146 +#else
2147 + double __ieee754_y1(x)
2148 + double x;
2149 +#endif
2151 + double z, s,c,ss,cc,u,v;
2152 + int32_t hx,ix,lx;
2154 + EXTRACT_WORDS(hx,lx,x);
2155 + ix = 0x7fffffff&hx;
2156 + /* if Y1(NaN) is NaN, Y1(-inf) is NaN, Y1(inf) is 0 */
2157 + if(ix>=0x7ff00000) return one/(x+x*x);
2158 + if((ix|lx)==0) return -one/zero;
2159 + if(hx<0) return zero/zero;
2160 + if(ix >= 0x40000000) { /* |x| >= 2.0 */
2161 + s = sin(x);
2162 + c = cos(x);
2163 + ss = -s-c;
2164 + cc = s-c;
2165 + if(ix<0x7fe00000) { /* make sure x+x not overflow */
2166 + z = cos(x+x);
2167 + if ((s*c)>zero) cc = z/ss;
2168 + else ss = z/cc;
2170 + /* y1(x) = sqrt(2/(pi*x))*(p1(x)*sin(x0)+q1(x)*cos(x0))
2171 + * where x0 = x-3pi/4
2172 + * Better formula:
2173 + * cos(x0) = cos(x)cos(3pi/4)+sin(x)sin(3pi/4)
2174 + * = 1/sqrt(2) * (sin(x) - cos(x))
2175 + * sin(x0) = sin(x)cos(3pi/4)-cos(x)sin(3pi/4)
2176 + * = -1/sqrt(2) * (cos(x) + sin(x))
2177 + * To avoid cancellation, use
2178 + * sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x))
2179 + * to compute the worse one.
2180 + */
2181 + if(ix>0x48000000) z = (invsqrtpi*ss)/sqrt(x);
2182 + else {
2183 + u = pone(x); v = qone(x);
2184 + z = invsqrtpi*(u*ss+v*cc)/sqrt(x);
2186 + return z;
2188 + if(ix<=0x3c900000) { /* x < 2**-54 */
2189 + return(-tpi/x);
2191 + z = x*x;
2192 + u = U0[0]+z*(U0[1]+z*(U0[2]+z*(U0[3]+z*U0[4])));
2193 + v = one+z*(V0[0]+z*(V0[1]+z*(V0[2]+z*(V0[3]+z*V0[4]))));
2194 + return(x*(u/v) + tpi*(__ieee754_j1(x)*__ieee754_log(x)-one/x));
2197 +/* For x >= 8, the asymptotic expansions of pone is
2198 + * 1 + 15/128 s^2 - 4725/2^15 s^4 - ..., where s = 1/x.
2199 + * We approximate pone by
2200 + * pone(x) = 1 + (R/S)
2201 + * where R = pr0 + pr1*s^2 + pr2*s^4 + ... + pr5*s^10
2202 + * S = 1 + ps0*s^2 + ... + ps4*s^10
2203 + * and
2204 + * | pone(x)-1-R/S | <= 2 ** ( -60.06)
2205 + */
2207 +#ifdef __STDC__
2208 +static const double pr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
2209 +#else
2210 +static double pr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
2211 +#endif
2212 + 0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */
2213 + 1.17187499999988647970e-01, /* 0x3FBDFFFF, 0xFFFFFCCE */
2214 + 1.32394806593073575129e+01, /* 0x402A7A9D, 0x357F7FCE */
2215 + 4.12051854307378562225e+02, /* 0x4079C0D4, 0x652EA590 */
2216 + 3.87474538913960532227e+03, /* 0x40AE457D, 0xA3A532CC */
2217 + 7.91447954031891731574e+03, /* 0x40BEEA7A, 0xC32782DD */
2219 +#ifdef __STDC__
2220 +static const double ps8[5] = {
2221 +#else
2222 +static double ps8[5] = {
2223 +#endif
2224 + 1.14207370375678408436e+02, /* 0x405C8D45, 0x8E656CAC */
2225 + 3.65093083420853463394e+03, /* 0x40AC85DC, 0x964D274F */
2226 + 3.69562060269033463555e+04, /* 0x40E20B86, 0x97C5BB7F */
2227 + 9.76027935934950801311e+04, /* 0x40F7D42C, 0xB28F17BB */
2228 + 3.08042720627888811578e+04, /* 0x40DE1511, 0x697A0B2D */
2231 +#ifdef __STDC__
2232 +static const double pr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
2233 +#else
2234 +static double pr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
2235 +#endif
2236 + 1.31990519556243522749e-11, /* 0x3DAD0667, 0xDAE1CA7D */
2237 + 1.17187493190614097638e-01, /* 0x3FBDFFFF, 0xE2C10043 */
2238 + 6.80275127868432871736e+00, /* 0x401B3604, 0x6E6315E3 */
2239 + 1.08308182990189109773e+02, /* 0x405B13B9, 0x452602ED */
2240 + 5.17636139533199752805e+02, /* 0x40802D16, 0xD052D649 */
2241 + 5.28715201363337541807e+02, /* 0x408085B8, 0xBB7E0CB7 */
2243 +#ifdef __STDC__
2244 +static const double ps5[5] = {
2245 +#else
2246 +static double ps5[5] = {
2247 +#endif
2248 + 5.92805987221131331921e+01, /* 0x404DA3EA, 0xA8AF633D */
2249 + 9.91401418733614377743e+02, /* 0x408EFB36, 0x1B066701 */
2250 + 5.35326695291487976647e+03, /* 0x40B4E944, 0x5706B6FB */
2251 + 7.84469031749551231769e+03, /* 0x40BEA4B0, 0xB8A5BB15 */
2252 + 1.50404688810361062679e+03, /* 0x40978030, 0x036F5E51 */
2255 +#ifdef __STDC__
2256 +static const double pr3[6] = {
2257 +#else
2258 +static double pr3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
2259 +#endif
2260 + 3.02503916137373618024e-09, /* 0x3E29FC21, 0xA7AD9EDD */
2261 + 1.17186865567253592491e-01, /* 0x3FBDFFF5, 0x5B21D17B */
2262 + 3.93297750033315640650e+00, /* 0x400F76BC, 0xE85EAD8A */
2263 + 3.51194035591636932736e+01, /* 0x40418F48, 0x9DA6D129 */
2264 + 9.10550110750781271918e+01, /* 0x4056C385, 0x4D2C1837 */
2265 + 4.85590685197364919645e+01, /* 0x4048478F, 0x8EA83EE5 */
2267 +#ifdef __STDC__
2268 +static const double ps3[5] = {
2269 +#else
2270 +static double ps3[5] = {
2271 +#endif
2272 + 3.47913095001251519989e+01, /* 0x40416549, 0xA134069C */
2273 + 3.36762458747825746741e+02, /* 0x40750C33, 0x07F1A75F */
2274 + 1.04687139975775130551e+03, /* 0x40905B7C, 0x5037D523 */
2275 + 8.90811346398256432622e+02, /* 0x408BD67D, 0xA32E31E9 */
2276 + 1.03787932439639277504e+02, /* 0x4059F26D, 0x7C2EED53 */
2279 +#ifdef __STDC__
2280 +static const double pr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
2281 +#else
2282 +static double pr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
2283 +#endif
2284 + 1.07710830106873743082e-07, /* 0x3E7CE9D4, 0xF65544F4 */
2285 + 1.17176219462683348094e-01, /* 0x3FBDFF42, 0xBE760D83 */
2286 + 2.36851496667608785174e+00, /* 0x4002F2B7, 0xF98FAEC0 */
2287 + 1.22426109148261232917e+01, /* 0x40287C37, 0x7F71A964 */
2288 + 1.76939711271687727390e+01, /* 0x4031B1A8, 0x177F8EE2 */
2289 + 5.07352312588818499250e+00, /* 0x40144B49, 0xA574C1FE */
2291 +#ifdef __STDC__
2292 +static const double ps2[5] = {
2293 +#else
2294 +static double ps2[5] = {
2295 +#endif
2296 + 2.14364859363821409488e+01, /* 0x40356FBD, 0x8AD5ECDC */
2297 + 1.25290227168402751090e+02, /* 0x405F5293, 0x14F92CD5 */
2298 + 2.32276469057162813669e+02, /* 0x406D08D8, 0xD5A2DBD9 */
2299 + 1.17679373287147100768e+02, /* 0x405D6B7A, 0xDA1884A9 */
2300 + 8.36463893371618283368e+00, /* 0x4020BAB1, 0xF44E5192 */
2303 +#ifdef __STDC__
2304 + static double pone(double x)
2305 +#else
2306 + static double pone(x)
2307 + double x;
2308 +#endif
2310 +#ifdef __STDC__
2311 + const double *p=0,*q=0;
2312 +#else
2313 + double *p,*q;
2314 +#endif
2315 + double z,r,s;
2316 + int32_t ix;
2317 + GET_HIGH_WORD(ix,x);
2318 + ix &= 0x7fffffff;
2319 + if(ix>=0x40200000) {p = pr8; q= ps8;}
2320 + else if(ix>=0x40122E8B){p = pr5; q= ps5;}
2321 + else if(ix>=0x4006DB6D){p = pr3; q= ps3;}
2322 + else if(ix>=0x40000000){p = pr2; q= ps2;}
2323 + z = one/(x*x);
2324 + r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
2325 + s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4]))));
2326 + return one+ r/s;
2330 +/* For x >= 8, the asymptotic expansions of qone is
2331 + * 3/8 s - 105/1024 s^3 - ..., where s = 1/x.
2332 + * We approximate pone by
2333 + * qone(x) = s*(0.375 + (R/S))
2334 + * where R = qr1*s^2 + qr2*s^4 + ... + qr5*s^10
2335 + * S = 1 + qs1*s^2 + ... + qs6*s^12
2336 + * and
2337 + * | qone(x)/s -0.375-R/S | <= 2 ** ( -61.13)
2338 + */
2340 +#ifdef __STDC__
2341 +static const double qr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
2342 +#else
2343 +static double qr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */
2344 +#endif
2345 + 0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */
2346 + -1.02539062499992714161e-01, /* 0xBFBA3FFF, 0xFFFFFDF3 */
2347 + -1.62717534544589987888e+01, /* 0xC0304591, 0xA26779F7 */
2348 + -7.59601722513950107896e+02, /* 0xC087BCD0, 0x53E4B576 */
2349 + -1.18498066702429587167e+04, /* 0xC0C724E7, 0x40F87415 */
2350 + -4.84385124285750353010e+04, /* 0xC0E7A6D0, 0x65D09C6A */
2352 +#ifdef __STDC__
2353 +static const double qs8[6] = {
2354 +#else
2355 +static double qs8[6] = {
2356 +#endif
2357 + 1.61395369700722909556e+02, /* 0x40642CA6, 0xDE5BCDE5 */
2358 + 7.82538599923348465381e+03, /* 0x40BE9162, 0xD0D88419 */
2359 + 1.33875336287249578163e+05, /* 0x4100579A, 0xB0B75E98 */
2360 + 7.19657723683240939863e+05, /* 0x4125F653, 0x72869C19 */
2361 + 6.66601232617776375264e+05, /* 0x412457D2, 0x7719AD5C */
2362 + -2.94490264303834643215e+05, /* 0xC111F969, 0x0EA5AA18 */
2365 +#ifdef __STDC__
2366 +static const double qr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
2367 +#else
2368 +static double qr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */
2369 +#endif
2370 + -2.08979931141764104297e-11, /* 0xBDB6FA43, 0x1AA1A098 */
2371 + -1.02539050241375426231e-01, /* 0xBFBA3FFF, 0xCB597FEF */
2372 + -8.05644828123936029840e+00, /* 0xC0201CE6, 0xCA03AD4B */
2373 + -1.83669607474888380239e+02, /* 0xC066F56D, 0x6CA7B9B0 */
2374 + -1.37319376065508163265e+03, /* 0xC09574C6, 0x6931734F */
2375 + -2.61244440453215656817e+03, /* 0xC0A468E3, 0x88FDA79D */
2377 +#ifdef __STDC__
2378 +static const double qs5[6] = {
2379 +#else
2380 +static double qs5[6] = {
2381 +#endif
2382 + 8.12765501384335777857e+01, /* 0x405451B2, 0xFF5A11B2 */
2383 + 1.99179873460485964642e+03, /* 0x409F1F31, 0xE77BF839 */
2384 + 1.74684851924908907677e+04, /* 0x40D10F1F, 0x0D64CE29 */
2385 + 4.98514270910352279316e+04, /* 0x40E8576D, 0xAABAD197 */
2386 + 2.79480751638918118260e+04, /* 0x40DB4B04, 0xCF7C364B */
2387 + -4.71918354795128470869e+03, /* 0xC0B26F2E, 0xFCFFA004 */
2390 +#ifdef __STDC__
2391 +static const double qr3[6] = {
2392 +#else
2393 +static double qr3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */
2394 +#endif
2395 + -5.07831226461766561369e-09, /* 0xBE35CFA9, 0xD38FC84F */
2396 + -1.02537829820837089745e-01, /* 0xBFBA3FEB, 0x51AEED54 */
2397 + -4.61011581139473403113e+00, /* 0xC01270C2, 0x3302D9FF */
2398 + -5.78472216562783643212e+01, /* 0xC04CEC71, 0xC25D16DA */
2399 + -2.28244540737631695038e+02, /* 0xC06C87D3, 0x4718D55F */
2400 + -2.19210128478909325622e+02, /* 0xC06B66B9, 0x5F5C1BF6 */
2402 +#ifdef __STDC__
2403 +static const double qs3[6] = {
2404 +#else
2405 +static double qs3[6] = {
2406 +#endif
2407 + 4.76651550323729509273e+01, /* 0x4047D523, 0xCCD367E4 */
2408 + 6.73865112676699709482e+02, /* 0x40850EEB, 0xC031EE3E */
2409 + 3.38015286679526343505e+03, /* 0x40AA684E, 0x448E7C9A */
2410 + 5.54772909720722782367e+03, /* 0x40B5ABBA, 0xA61D54A6 */
2411 + 1.90311919338810798763e+03, /* 0x409DBC7A, 0x0DD4DF4B */
2412 + -1.35201191444307340817e+02, /* 0xC060E670, 0x290A311F */
2415 +#ifdef __STDC__
2416 +static const double qr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
2417 +#else
2418 +static double qr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */
2419 +#endif
2420 + -1.78381727510958865572e-07, /* 0xBE87F126, 0x44C626D2 */
2421 + -1.02517042607985553460e-01, /* 0xBFBA3E8E, 0x9148B010 */
2422 + -2.75220568278187460720e+00, /* 0xC0060484, 0x69BB4EDA */
2423 + -1.96636162643703720221e+01, /* 0xC033A9E2, 0xC168907F */
2424 + -4.23253133372830490089e+01, /* 0xC04529A3, 0xDE104AAA */
2425 + -2.13719211703704061733e+01, /* 0xC0355F36, 0x39CF6E52 */
2427 +#ifdef __STDC__
2428 +static const double qs2[6] = {
2429 +#else
2430 +static double qs2[6] = {
2431 +#endif
2432 + 2.95333629060523854548e+01, /* 0x403D888A, 0x78AE64FF */
2433 + 2.52981549982190529136e+02, /* 0x406F9F68, 0xDB821CBA */
2434 + 7.57502834868645436472e+02, /* 0x4087AC05, 0xCE49A0F7 */
2435 + 7.39393205320467245656e+02, /* 0x40871B25, 0x48D4C029 */
2436 + 1.55949003336666123687e+02, /* 0x40637E5E, 0x3C3ED8D4 */
2437 + -4.95949898822628210127e+00, /* 0xC013D686, 0xE71BE86B */
2440 +#ifdef __STDC__
2441 + static double qone(double x)
2442 +#else
2443 + static double qone(x)
2444 + double x;
2445 +#endif
2447 +#ifdef __STDC__
2448 + const double *p=0,*q=0;
2449 +#else
2450 + double *p,*q;
2451 +#endif
2452 + double s,r,z;
2453 + int32_t ix;
2454 + GET_HIGH_WORD(ix,x);
2455 + ix &= 0x7fffffff;
2456 + if(ix>=0x40200000) {p = qr8; q= qs8;}
2457 + else if(ix>=0x40122E8B){p = qr5; q= qs5;}
2458 + else if(ix>=0x4006DB6D){p = qr3; q= qs3;}
2459 + else if(ix>=0x40000000){p = qr2; q= qs2;}
2460 + z = one/(x*x);
2461 + r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
2462 + s = one+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5])))));
2463 + return (.375 + r/s)/x;
2465 diff -urN dietlibc-0.30/libm/e_jn.c dietlibc-0.30-libm/libm/e_jn.c
2466 --- dietlibc-0.30/libm/e_jn.c 1970-01-01 00:00:00.000000000 +0000
2467 +++ dietlibc-0.30-libm/libm/e_jn.c 2006-06-25 11:20:14.000000000 +0000
2468 @@ -0,0 +1,281 @@
2469 +/* @(#)e_jn.c 5.1 93/09/24 */
2471 + * ====================================================
2472 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
2474 + * Developed at SunPro, a Sun Microsystems, Inc. business.
2475 + * Permission to use, copy, modify, and distribute this
2476 + * software is freely granted, provided that this notice
2477 + * is preserved.
2478 + * ====================================================
2479 + */
2481 +#if defined(LIBM_SCCS) && !defined(lint)
2482 +static char rcsid[] = "$NetBSD: e_jn.c,v 1.9 1995/05/10 20:45:34 jtc Exp $";
2483 +#endif
2486 + * __ieee754_jn(n, x), __ieee754_yn(n, x)
2487 + * floating point Bessel's function of the 1st and 2nd kind
2488 + * of order n
2490 + * Special cases:
2491 + * y0(0)=y1(0)=yn(n,0) = -inf with division by zero signal;
2492 + * y0(-ve)=y1(-ve)=yn(n,-ve) are NaN with invalid signal.
2493 + * Note 2. About jn(n,x), yn(n,x)
2494 + * For n=0, j0(x) is called,
2495 + * for n=1, j1(x) is called,
2496 + * for n<x, forward recursion us used starting
2497 + * from values of j0(x) and j1(x).
2498 + * for n>x, a continued fraction approximation to
2499 + * j(n,x)/j(n-1,x) is evaluated and then backward
2500 + * recursion is used starting from a supposed value
2501 + * for j(n,x). The resulting value of j(0,x) is
2502 + * compared with the actual value to correct the
2503 + * supposed value of j(n,x).
2505 + * yn(n,x) is similar in all respects, except
2506 + * that forward recursion is used for all
2507 + * values of n>1.
2509 + */
2511 +#include "math.h"
2512 +#include "math_private.h"
2514 +#ifdef __STDC__
2515 +static const double
2516 +#else
2517 +static double
2518 +#endif
2519 +invsqrtpi= 5.64189583547756279280e-01, /* 0x3FE20DD7, 0x50429B6D */
2520 +two = 2.00000000000000000000e+00, /* 0x40000000, 0x00000000 */
2521 +one = 1.00000000000000000000e+00; /* 0x3FF00000, 0x00000000 */
2523 +#ifdef __STDC__
2524 +static const double zero = 0.00000000000000000000e+00;
2525 +#else
2526 +static double zero = 0.00000000000000000000e+00;
2527 +#endif
2529 +#ifdef __STDC__
2530 + double __ieee754_jn(int n, double x)
2531 +#else
2532 + double __ieee754_jn(n,x)
2533 + int n; double x;
2534 +#endif
2536 + int32_t i,hx,ix,lx, sgn;
2537 + double a, b, temp=0, di;
2538 + double z, w;
2540 + /* J(-n,x) = (-1)^n * J(n, x), J(n, -x) = (-1)^n * J(n, x)
2541 + * Thus, J(-n,x) = J(n,-x)
2542 + */
2543 + EXTRACT_WORDS(hx,lx,x);
2544 + ix = 0x7fffffff&hx;
2545 + /* if J(n,NaN) is NaN */
2546 + if((ix|((u_int32_t)(lx|-lx))>>31)>0x7ff00000) return x+x;
2547 + if(n<0){
2548 + n = -n;
2549 + x = -x;
2550 + hx ^= 0x80000000;
2552 + if(n==0) return(__ieee754_j0(x));
2553 + if(n==1) return(__ieee754_j1(x));
2554 + sgn = (n&1)&(hx>>31); /* even n -- 0, odd n -- sign(x) */
2555 + x = fabs(x);
2556 + if((ix|lx)==0||ix>=0x7ff00000) /* if x is 0 or inf */
2557 + b = zero;
2558 + else if((double)n<=x) {
2559 + /* Safe to use J(n+1,x)=2n/x *J(n,x)-J(n-1,x) */
2560 + if(ix>=0x52D00000) { /* x > 2**302 */
2561 + /* (x >> n**2)
2562 + * Jn(x) = cos(x-(2n+1)*pi/4)*sqrt(2/x*pi)
2563 + * Yn(x) = sin(x-(2n+1)*pi/4)*sqrt(2/x*pi)
2564 + * Let s=sin(x), c=cos(x),
2565 + * xn=x-(2n+1)*pi/4, sqt2 = sqrt(2),then
2567 + * n sin(xn)*sqt2 cos(xn)*sqt2
2568 + * ----------------------------------
2569 + * 0 s-c c+s
2570 + * 1 -s-c -c+s
2571 + * 2 -s+c -c-s
2572 + * 3 s+c c-s
2573 + */
2574 + switch(n&3) {
2575 + case 0: temp = cos(x)+sin(x); break;
2576 + case 1: temp = -cos(x)+sin(x); break;
2577 + case 2: temp = -cos(x)-sin(x); break;
2578 + case 3: temp = cos(x)-sin(x); break;
2580 + b = invsqrtpi*temp/sqrt(x);
2581 + } else {
2582 + a = __ieee754_j0(x);
2583 + b = __ieee754_j1(x);
2584 + for(i=1;i<n;i++){
2585 + temp = b;
2586 + b = b*((double)(i+i)/x) - a; /* avoid underflow */
2587 + a = temp;
2590 + } else {
2591 + if(ix<0x3e100000) { /* x < 2**-29 */
2592 + /* x is tiny, return the first Taylor expansion of J(n,x)
2593 + * J(n,x) = 1/n!*(x/2)^n - ...
2594 + */
2595 + if(n>33) /* underflow */
2596 + b = zero;
2597 + else {
2598 + temp = x*0.5; b = temp;
2599 + for (a=one,i=2;i<=n;i++) {
2600 + a *= (double)i; /* a = n! */
2601 + b *= temp; /* b = (x/2)^n */
2603 + b = b/a;
2605 + } else {
2606 + /* use backward recurrence */
2607 + /* x x^2 x^2
2608 + * J(n,x)/J(n-1,x) = ---- ------ ------ .....
2609 + * 2n - 2(n+1) - 2(n+2)
2611 + * 1 1 1
2612 + * (for large x) = ---- ------ ------ .....
2613 + * 2n 2(n+1) 2(n+2)
2614 + * -- - ------ - ------ -
2615 + * x x x
2617 + * Let w = 2n/x and h=2/x, then the above quotient
2618 + * is equal to the continued fraction:
2619 + * 1
2620 + * = -----------------------
2621 + * 1
2622 + * w - -----------------
2623 + * 1
2624 + * w+h - ---------
2625 + * w+2h - ...
2627 + * To determine how many terms needed, let
2628 + * Q(0) = w, Q(1) = w(w+h) - 1,
2629 + * Q(k) = (w+k*h)*Q(k-1) - Q(k-2),
2630 + * When Q(k) > 1e4 good for single
2631 + * When Q(k) > 1e9 good for double
2632 + * When Q(k) > 1e17 good for quadruple
2633 + */
2634 + /* determine k */
2635 + double t,v;
2636 + double q0,q1,h,tmp; int32_t k,m;
2637 + w = (n+n)/(double)x; h = 2.0/(double)x;
2638 + q0 = w; z = w+h; q1 = w*z - 1.0; k=1;
2639 + while(q1<1.0e9) {
2640 + k += 1; z += h;
2641 + tmp = z*q1 - q0;
2642 + q0 = q1;
2643 + q1 = tmp;
2645 + m = n+n;
2646 + for(t=zero, i = 2*(n+k); i>=m; i -= 2) t = one/(i/x-t);
2647 + a = t;
2648 + b = one;
2649 + /* estimate log((2/x)^n*n!) = n*log(2/x)+n*ln(n)
2650 + * Hence, if n*(log(2n/x)) > ...
2651 + * single 8.8722839355e+01
2652 + * double 7.09782712893383973096e+02
2653 + * long double 1.1356523406294143949491931077970765006170e+04
2654 + * then recurrent value may overflow and the result is
2655 + * likely underflow to zero
2656 + */
2657 + tmp = n;
2658 + v = two/x;
2659 + tmp = tmp*__ieee754_log(fabs(v*tmp));
2660 + if(tmp<7.09782712893383973096e+02) {
2661 + for(i=n-1,di=(double)(i+i);i>0;i--){
2662 + temp = b;
2663 + b *= di;
2664 + b = b/x - a;
2665 + a = temp;
2666 + di -= two;
2668 + } else {
2669 + for(i=n-1,di=(double)(i+i);i>0;i--){
2670 + temp = b;
2671 + b *= di;
2672 + b = b/x - a;
2673 + a = temp;
2674 + di -= two;
2675 + /* scale b to avoid spurious overflow */
2676 + if(b>1e100) {
2677 + a /= b;
2678 + t /= b;
2679 + b = one;
2683 + b = (t*__ieee754_j0(x)/b);
2686 + if(sgn==1) return -b; else return b;
2689 +#ifdef __STDC__
2690 + double __ieee754_yn(int n, double x)
2691 +#else
2692 + double __ieee754_yn(n,x)
2693 + int n; double x;
2694 +#endif
2696 + int32_t i,hx,ix,lx;
2697 + int32_t sign;
2698 + double a, b, temp=0;
2700 + EXTRACT_WORDS(hx,lx,x);
2701 + ix = 0x7fffffff&hx;
2702 + /* if Y(n,NaN) is NaN */
2703 + if((ix|((u_int32_t)(lx|-lx))>>31)>0x7ff00000) return x+x;
2704 + if((ix|lx)==0) return -one/zero;
2705 + if(hx<0) return zero/zero;
2706 + sign = 1;
2707 + if(n<0){
2708 + n = -n;
2709 + sign = 1 - ((n&1)<<1);
2711 + if(n==0) return(__ieee754_y0(x));
2712 + if(n==1) return(sign*__ieee754_y1(x));
2713 + if(ix==0x7ff00000) return zero;
2714 + if(ix>=0x52D00000) { /* x > 2**302 */
2715 + /* (x >> n**2)
2716 + * Jn(x) = cos(x-(2n+1)*pi/4)*sqrt(2/x*pi)
2717 + * Yn(x) = sin(x-(2n+1)*pi/4)*sqrt(2/x*pi)
2718 + * Let s=sin(x), c=cos(x),
2719 + * xn=x-(2n+1)*pi/4, sqt2 = sqrt(2),then
2721 + * n sin(xn)*sqt2 cos(xn)*sqt2
2722 + * ----------------------------------
2723 + * 0 s-c c+s
2724 + * 1 -s-c -c+s
2725 + * 2 -s+c -c-s
2726 + * 3 s+c c-s
2727 + */
2728 + switch(n&3) {
2729 + case 0: temp = sin(x)-cos(x); break;
2730 + case 1: temp = -sin(x)-cos(x); break;
2731 + case 2: temp = -sin(x)+cos(x); break;
2732 + case 3: temp = sin(x)+cos(x); break;
2734 + b = invsqrtpi*temp/sqrt(x);
2735 + } else {
2736 + u_int32_t high;
2737 + a = __ieee754_y0(x);
2738 + b = __ieee754_y1(x);
2739 + /* quit if b is -inf */
2740 + GET_HIGH_WORD(high,b);
2741 + for(i=1;i<n&&high!=0xfff00000;i++){
2742 + temp = b;
2743 + b = ((double)(i+i)/x)*b - a;
2744 + GET_HIGH_WORD(high,b);
2745 + a = temp;
2748 + if(sign>0) return b; else return -b;
2750 diff -urN dietlibc-0.30/libm/e_lgamma.c dietlibc-0.30-libm/libm/e_lgamma.c
2751 --- dietlibc-0.30/libm/e_lgamma.c 1970-01-01 00:00:00.000000000 +0000
2752 +++ dietlibc-0.30-libm/libm/e_lgamma.c 2006-06-25 11:20:15.000000000 +0000
2753 @@ -0,0 +1,34 @@
2755 +/* @(#)e_lgamma.c 5.1 93/09/24 */
2757 + * ====================================================
2758 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
2760 + * Developed at SunPro, a Sun Microsystems, Inc. business.
2761 + * Permission to use, copy, modify, and distribute this
2762 + * software is freely granted, provided that this notice
2763 + * is preserved.
2764 + * ====================================================
2766 + */
2768 +/* __ieee754_lgamma(x)
2769 + * Return the logarithm of the Gamma function of x.
2771 + * Method: call __ieee754_lgamma_r
2772 + */
2774 +#include "math_private.h"
2776 +extern int signgam;
2778 +#ifdef __STDC__
2779 + //__private_extern__
2780 + double __ieee754_lgamma(double x)
2781 +#else
2782 + double __ieee754_lgamma(x)
2783 + double x;
2784 +#endif
2786 + return __ieee754_lgamma_r(x,&signgam);
2788 diff -urN dietlibc-0.30/libm/e_lgamma_r.c dietlibc-0.30-libm/libm/e_lgamma_r.c
2789 --- dietlibc-0.30/libm/e_lgamma_r.c 1970-01-01 00:00:00.000000000 +0000
2790 +++ dietlibc-0.30-libm/libm/e_lgamma_r.c 2006-06-25 11:20:23.000000000 +0000
2791 @@ -0,0 +1,316 @@
2792 +/* @(#)er_lgamma.c 5.1 93/09/24 */
2794 + * ====================================================
2795 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
2797 + * Developed at SunPro, a Sun Microsystems, Inc. business.
2798 + * Permission to use, copy, modify, and distribute this
2799 + * software is freely granted, provided that this notice
2800 + * is preserved.
2801 + * ====================================================
2802 + */
2804 +#if defined(LIBM_SCCS) && !defined(lint)
2805 +static char rcsid[] = "$NetBSD: e_lgamma_r.c,v 1.7 1995/05/10 20:45:42 jtc Exp $";
2806 +#endif
2808 +/* __ieee754_lgamma_r(x, signgamp)
2809 + * Reentrant version of the logarithm of the Gamma function
2810 + * with user provide pointer for the sign of Gamma(x).
2812 + * Method:
2813 + * 1. Argument Reduction for 0 < x <= 8
2814 + * Since gamma(1+s)=s*gamma(s), for x in [0,8], we may
2815 + * reduce x to a number in [1.5,2.5] by
2816 + * lgamma(1+s) = log(s) + lgamma(s)
2817 + * for example,
2818 + * lgamma(7.3) = log(6.3) + lgamma(6.3)
2819 + * = log(6.3*5.3) + lgamma(5.3)
2820 + * = log(6.3*5.3*4.3*3.3*2.3) + lgamma(2.3)
2821 + * 2. Polynomial approximation of lgamma around its
2822 + * minimun ymin=1.461632144968362245 to maintain monotonicity.
2823 + * On [ymin-0.23, ymin+0.27] (i.e., [1.23164,1.73163]), use
2824 + * Let z = x-ymin;
2825 + * lgamma(x) = -1.214862905358496078218 + z^2*poly(z)
2826 + * where
2827 + * poly(z) is a 14 degree polynomial.
2828 + * 2. Rational approximation in the primary interval [2,3]
2829 + * We use the following approximation:
2830 + * s = x-2.0;
2831 + * lgamma(x) = 0.5*s + s*P(s)/Q(s)
2832 + * with accuracy
2833 + * |P/Q - (lgamma(x)-0.5s)| < 2**-61.71
2834 + * Our algorithms are based on the following observation
2836 + * zeta(2)-1 2 zeta(3)-1 3
2837 + * lgamma(2+s) = s*(1-Euler) + --------- * s - --------- * s + ...
2838 + * 2 3
2840 + * where Euler = 0.5771... is the Euler constant, which is very
2841 + * close to 0.5.
2843 + * 3. For x>=8, we have
2844 + * lgamma(x)~(x-0.5)log(x)-x+0.5*log(2pi)+1/(12x)-1/(360x**3)+....
2845 + * (better formula:
2846 + * lgamma(x)~(x-0.5)*(log(x)-1)-.5*(log(2pi)-1) + ...)
2847 + * Let z = 1/x, then we approximation
2848 + * f(z) = lgamma(x) - (x-0.5)(log(x)-1)
2849 + * by
2850 + * 3 5 11
2851 + * w = w0 + w1*z + w2*z + w3*z + ... + w6*z
2852 + * where
2853 + * |w - f(z)| < 2**-58.74
2855 + * 4. For negative x, since (G is gamma function)
2856 + * -x*G(-x)*G(x) = pi/sin(pi*x),
2857 + * we have
2858 + * G(x) = pi/(sin(pi*x)*(-x)*G(-x))
2859 + * since G(-x) is positive, sign(G(x)) = sign(sin(pi*x)) for x<0
2860 + * Hence, for x<0, signgam = sign(sin(pi*x)) and
2861 + * lgamma(x) = log(|Gamma(x)|)
2862 + * = log(pi/(|x*sin(pi*x)|)) - lgamma(-x);
2863 + * Note: one should avoid compute pi*(-x) directly in the
2864 + * computation of sin(pi*(-x)).
2866 + * 5. Special Cases
2867 + * lgamma(2+s) ~ s*(1-Euler) for tiny s
2868 + * lgamma(1)=lgamma(2)=0
2869 + * lgamma(x) ~ -log(x) for tiny x
2870 + * lgamma(0) = lgamma(inf) = inf
2871 + * lgamma(-integer) = +-inf
2873 + */
2875 +#include "math.h"
2876 +#include "math_private.h"
2878 +#ifdef __STDC__
2879 +static const double
2880 +#else
2881 +static double
2882 +#endif
2883 +two52= 4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
2884 +half= 5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */
2885 +one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
2886 +pi = 3.14159265358979311600e+00, /* 0x400921FB, 0x54442D18 */
2887 +a0 = 7.72156649015328655494e-02, /* 0x3FB3C467, 0xE37DB0C8 */
2888 +a1 = 3.22467033424113591611e-01, /* 0x3FD4A34C, 0xC4A60FAD */
2889 +a2 = 6.73523010531292681824e-02, /* 0x3FB13E00, 0x1A5562A7 */
2890 +a3 = 2.05808084325167332806e-02, /* 0x3F951322, 0xAC92547B */
2891 +a4 = 7.38555086081402883957e-03, /* 0x3F7E404F, 0xB68FEFE8 */
2892 +a5 = 2.89051383673415629091e-03, /* 0x3F67ADD8, 0xCCB7926B */
2893 +a6 = 1.19270763183362067845e-03, /* 0x3F538A94, 0x116F3F5D */
2894 +a7 = 5.10069792153511336608e-04, /* 0x3F40B6C6, 0x89B99C00 */
2895 +a8 = 2.20862790713908385557e-04, /* 0x3F2CF2EC, 0xED10E54D */
2896 +a9 = 1.08011567247583939954e-04, /* 0x3F1C5088, 0x987DFB07 */
2897 +a10 = 2.52144565451257326939e-05, /* 0x3EFA7074, 0x428CFA52 */
2898 +a11 = 4.48640949618915160150e-05, /* 0x3F07858E, 0x90A45837 */
2899 +tc = 1.46163214496836224576e+00, /* 0x3FF762D8, 0x6356BE3F */
2900 +tf = -1.21486290535849611461e-01, /* 0xBFBF19B9, 0xBCC38A42 */
2901 +/* tt = -(tail of tf) */
2902 +tt = -3.63867699703950536541e-18, /* 0xBC50C7CA, 0xA48A971F */
2903 +t0 = 4.83836122723810047042e-01, /* 0x3FDEF72B, 0xC8EE38A2 */
2904 +t1 = -1.47587722994593911752e-01, /* 0xBFC2E427, 0x8DC6C509 */
2905 +t2 = 6.46249402391333854778e-02, /* 0x3FB08B42, 0x94D5419B */
2906 +t3 = -3.27885410759859649565e-02, /* 0xBFA0C9A8, 0xDF35B713 */
2907 +t4 = 1.79706750811820387126e-02, /* 0x3F9266E7, 0x970AF9EC */
2908 +t5 = -1.03142241298341437450e-02, /* 0xBF851F9F, 0xBA91EC6A */
2909 +t6 = 6.10053870246291332635e-03, /* 0x3F78FCE0, 0xE370E344 */
2910 +t7 = -3.68452016781138256760e-03, /* 0xBF6E2EFF, 0xB3E914D7 */
2911 +t8 = 2.25964780900612472250e-03, /* 0x3F6282D3, 0x2E15C915 */
2912 +t9 = -1.40346469989232843813e-03, /* 0xBF56FE8E, 0xBF2D1AF1 */
2913 +t10 = 8.81081882437654011382e-04, /* 0x3F4CDF0C, 0xEF61A8E9 */
2914 +t11 = -5.38595305356740546715e-04, /* 0xBF41A610, 0x9C73E0EC */
2915 +t12 = 3.15632070903625950361e-04, /* 0x3F34AF6D, 0x6C0EBBF7 */
2916 +t13 = -3.12754168375120860518e-04, /* 0xBF347F24, 0xECC38C38 */
2917 +t14 = 3.35529192635519073543e-04, /* 0x3F35FD3E, 0xE8C2D3F4 */
2918 +u0 = -7.72156649015328655494e-02, /* 0xBFB3C467, 0xE37DB0C8 */
2919 +u1 = 6.32827064025093366517e-01, /* 0x3FE4401E, 0x8B005DFF */
2920 +u2 = 1.45492250137234768737e+00, /* 0x3FF7475C, 0xD119BD6F */
2921 +u3 = 9.77717527963372745603e-01, /* 0x3FEF4976, 0x44EA8450 */
2922 +u4 = 2.28963728064692451092e-01, /* 0x3FCD4EAE, 0xF6010924 */
2923 +u5 = 1.33810918536787660377e-02, /* 0x3F8B678B, 0xBF2BAB09 */
2924 +v1 = 2.45597793713041134822e+00, /* 0x4003A5D7, 0xC2BD619C */
2925 +v2 = 2.12848976379893395361e+00, /* 0x40010725, 0xA42B18F5 */
2926 +v3 = 7.69285150456672783825e-01, /* 0x3FE89DFB, 0xE45050AF */
2927 +v4 = 1.04222645593369134254e-01, /* 0x3FBAAE55, 0xD6537C88 */
2928 +v5 = 3.21709242282423911810e-03, /* 0x3F6A5ABB, 0x57D0CF61 */
2929 +s0 = -7.72156649015328655494e-02, /* 0xBFB3C467, 0xE37DB0C8 */
2930 +s1 = 2.14982415960608852501e-01, /* 0x3FCB848B, 0x36E20878 */
2931 +s2 = 3.25778796408930981787e-01, /* 0x3FD4D98F, 0x4F139F59 */
2932 +s3 = 1.46350472652464452805e-01, /* 0x3FC2BB9C, 0xBEE5F2F7 */
2933 +s4 = 2.66422703033638609560e-02, /* 0x3F9B481C, 0x7E939961 */
2934 +s5 = 1.84028451407337715652e-03, /* 0x3F5E26B6, 0x7368F239 */
2935 +s6 = 3.19475326584100867617e-05, /* 0x3F00BFEC, 0xDD17E945 */
2936 +r1 = 1.39200533467621045958e+00, /* 0x3FF645A7, 0x62C4AB74 */
2937 +r2 = 7.21935547567138069525e-01, /* 0x3FE71A18, 0x93D3DCDC */
2938 +r3 = 1.71933865632803078993e-01, /* 0x3FC601ED, 0xCCFBDF27 */
2939 +r4 = 1.86459191715652901344e-02, /* 0x3F9317EA, 0x742ED475 */
2940 +r5 = 7.77942496381893596434e-04, /* 0x3F497DDA, 0xCA41A95B */
2941 +r6 = 7.32668430744625636189e-06, /* 0x3EDEBAF7, 0xA5B38140 */
2942 +w0 = 4.18938533204672725052e-01, /* 0x3FDACFE3, 0x90C97D69 */
2943 +w1 = 8.33333333333329678849e-02, /* 0x3FB55555, 0x5555553B */
2944 +w2 = -2.77777777728775536470e-03, /* 0xBF66C16C, 0x16B02E5C */
2945 +w3 = 7.93650558643019558500e-04, /* 0x3F4A019F, 0x98CF38B6 */
2946 +w4 = -5.95187557450339963135e-04, /* 0xBF4380CB, 0x8C0FE741 */
2947 +w5 = 8.36339918996282139126e-04, /* 0x3F4B67BA, 0x4CDAD5D1 */
2948 +w6 = -1.63092934096575273989e-03; /* 0xBF5AB89D, 0x0B9E43E4 */
2950 +#ifdef __STDC__
2951 +static const double zero= 0.00000000000000000000e+00;
2952 +#else
2953 +static double zero= 0.00000000000000000000e+00;
2954 +#endif
2956 +static
2957 +#ifdef __GNUC__
2958 +__inline__
2959 +#endif
2960 +#ifdef __STDC__
2961 + double sin_pi(double x)
2962 +#else
2963 + double sin_pi(x)
2964 + double x;
2965 +#endif
2967 + double y,z;
2968 + int n,ix;
2970 + GET_HIGH_WORD(ix,x);
2971 + ix &= 0x7fffffff;
2973 + if(ix<0x3fd00000) return __kernel_sin(pi*x,zero,0);
2974 + y = -x; /* x is assume negative */
2976 + /*
2977 + * argument reduction, make sure inexact flag not raised if input
2978 + * is an integer
2979 + */
2980 + z = floor(y);
2981 + if(z!=y) { /* inexact anyway */
2982 + y *= 0.5;
2983 + y = 2.0*(y - floor(y)); /* y = |x| mod 2.0 */
2984 + n = (int) (y*4.0);
2985 + } else {
2986 + if(ix>=0x43400000) {
2987 + y = zero; n = 0; /* y must be even */
2988 + } else {
2989 + if(ix<0x43300000) z = y+two52; /* exact */
2990 + GET_LOW_WORD(n,z);
2991 + n &= 1;
2992 + y = n;
2993 + n<<= 2;
2996 + switch (n) {
2997 + case 0: y = __kernel_sin(pi*y,zero,0); break;
2998 + case 1:
2999 + case 2: y = __kernel_cos(pi*(0.5-y),zero); break;
3000 + case 3:
3001 + case 4: y = __kernel_sin(pi*(one-y),zero,0); break;
3002 + case 5:
3003 + case 6: y = -__kernel_cos(pi*(y-1.5),zero); break;
3004 + default: y = __kernel_sin(pi*(y-2.0),zero,0); break;
3006 + return -y;
3010 +#ifdef __STDC__
3011 + double __ieee754_lgamma_r(double x, int *signgamp)
3012 +#else
3013 + double __ieee754_lgamma_r(x,signgamp)
3014 + double x; int *signgamp;
3015 +#endif
3017 + double t,y,z,nadj=0,p,p1,p2,p3,q,r,w;
3018 + int i,hx,lx,ix;
3020 + EXTRACT_WORDS(hx,lx,x);
3022 + /* purge off +-inf, NaN, +-0, and negative arguments */
3023 + *signgamp = 1;
3024 + ix = hx&0x7fffffff;
3025 + if(ix>=0x7ff00000) return x*x;
3026 + if((ix|lx)==0) return one/zero;
3027 + if(ix<0x3b900000) { /* |x|<2**-70, return -log(|x|) */
3028 + if(hx<0) {
3029 + *signgamp = -1;
3030 + return -__ieee754_log(-x);
3031 + } else return -__ieee754_log(x);
3033 + if(hx<0) {
3034 + if(ix>=0x43300000) /* |x|>=2**52, must be -integer */
3035 + return one/zero;
3036 + t = sin_pi(x);
3037 + if(t==zero) return one/zero; /* -integer */
3038 + nadj = __ieee754_log(pi/fabs(t*x));
3039 + if(t<zero) *signgamp = -1;
3040 + x = -x;
3043 + /* purge off 1 and 2 */
3044 + if((((ix-0x3ff00000)|lx)==0)||(((ix-0x40000000)|lx)==0)) r = 0;
3045 + /* for x < 2.0 */
3046 + else if(ix<0x40000000) {
3047 + if(ix<=0x3feccccc) { /* lgamma(x) = lgamma(x+1)-log(x) */
3048 + r = -__ieee754_log(x);
3049 + if(ix>=0x3FE76944) {y = one-x; i= 0;}
3050 + else if(ix>=0x3FCDA661) {y= x-(tc-one); i=1;}
3051 + else {y = x; i=2;}
3052 + } else {
3053 + r = zero;
3054 + if(ix>=0x3FFBB4C3) {y=2.0-x;i=0;} /* [1.7316,2] */
3055 + else if(ix>=0x3FF3B4C4) {y=x-tc;i=1;} /* [1.23,1.73] */
3056 + else {y=x-one;i=2;}
3058 + switch(i) {
3059 + case 0:
3060 + z = y*y;
3061 + p1 = a0+z*(a2+z*(a4+z*(a6+z*(a8+z*a10))));
3062 + p2 = z*(a1+z*(a3+z*(a5+z*(a7+z*(a9+z*a11)))));
3063 + p = y*p1+p2;
3064 + r += (p-0.5*y); break;
3065 + case 1:
3066 + z = y*y;
3067 + w = z*y;
3068 + p1 = t0+w*(t3+w*(t6+w*(t9 +w*t12))); /* parallel comp */
3069 + p2 = t1+w*(t4+w*(t7+w*(t10+w*t13)));
3070 + p3 = t2+w*(t5+w*(t8+w*(t11+w*t14)));
3071 + p = z*p1-(tt-w*(p2+y*p3));
3072 + r += (tf + p); break;
3073 + case 2:
3074 + p1 = y*(u0+y*(u1+y*(u2+y*(u3+y*(u4+y*u5)))));
3075 + p2 = one+y*(v1+y*(v2+y*(v3+y*(v4+y*v5))));
3076 + r += (-0.5*y + p1/p2);
3079 + else if(ix<0x40200000) { /* x < 8.0 */
3080 + i = (int)x;
3081 + t = zero;
3082 + y = x-(double)i;
3083 + p = y*(s0+y*(s1+y*(s2+y*(s3+y*(s4+y*(s5+y*s6))))));
3084 + q = one+y*(r1+y*(r2+y*(r3+y*(r4+y*(r5+y*r6)))));
3085 + r = half*y+p/q;
3086 + z = one; /* lgamma(1+s) = log(s) + lgamma(s) */
3087 + switch(i) {
3088 + case 7: z *= (y+6.0); /* FALLTHRU */
3089 + case 6: z *= (y+5.0); /* FALLTHRU */
3090 + case 5: z *= (y+4.0); /* FALLTHRU */
3091 + case 4: z *= (y+3.0); /* FALLTHRU */
3092 + case 3: z *= (y+2.0); /* FALLTHRU */
3093 + r += __ieee754_log(z); break;
3095 + /* 8.0 <= x < 2**58 */
3096 + } else if (ix < 0x43900000) {
3097 + t = __ieee754_log(x);
3098 + z = one/x;
3099 + y = z*z;
3100 + w = w0+z*(w1+y*(w2+y*(w3+y*(w4+y*(w5+y*w6)))));
3101 + r = (x-half)*(t-one)+w;
3102 + } else
3103 + /* 2**58 <= x <= inf */
3104 + r = x*(__ieee754_log(x)-one);
3105 + if(hx<0) r = nadj - r;
3106 + return r;
3108 diff -urN dietlibc-0.30/libm/e_log.c dietlibc-0.30-libm/libm/e_log.c
3109 --- dietlibc-0.30/libm/e_log.c 1970-01-01 00:00:00.000000000 +0000
3110 +++ dietlibc-0.30-libm/libm/e_log.c 2006-06-25 11:20:02.000000000 +0000
3111 @@ -0,0 +1,147 @@
3112 +/* @(#)e_log.c 5.1 93/09/24 */
3114 + * ====================================================
3115 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
3117 + * Developed at SunPro, a Sun Microsystems, Inc. business.
3118 + * Permission to use, copy, modify, and distribute this
3119 + * software is freely granted, provided that this notice
3120 + * is preserved.
3121 + * ====================================================
3122 + */
3124 +#if defined(LIBM_SCCS) && !defined(lint)
3125 +static char rcsid[] = "$NetBSD: e_log.c,v 1.8 1995/05/10 20:45:49 jtc Exp $";
3126 +#endif
3128 +/* __ieee754_log(x)
3129 + * Return the logrithm of x
3131 + * Method :
3132 + * 1. Argument Reduction: find k and f such that
3133 + * x = 2^k * (1+f),
3134 + * where sqrt(2)/2 < 1+f < sqrt(2) .
3136 + * 2. Approximation of log(1+f).
3137 + * Let s = f/(2+f) ; based on log(1+f) = log(1+s) - log(1-s)
3138 + * = 2s + 2/3 s**3 + 2/5 s**5 + .....,
3139 + * = 2s + s*R
3140 + * We use a special Reme algorithm on [0,0.1716] to generate
3141 + * a polynomial of degree 14 to approximate R The maximum error
3142 + * of this polynomial approximation is bounded by 2**-58.45. In
3143 + * other words,
3144 + * 2 4 6 8 10 12 14
3145 + * R(z) ~ Lg1*s +Lg2*s +Lg3*s +Lg4*s +Lg5*s +Lg6*s +Lg7*s
3146 + * (the values of Lg1 to Lg7 are listed in the program)
3147 + * and
3148 + * | 2 14 | -58.45
3149 + * | Lg1*s +...+Lg7*s - R(z) | <= 2
3150 + * | |
3151 + * Note that 2s = f - s*f = f - hfsq + s*hfsq, where hfsq = f*f/2.
3152 + * In order to guarantee error in log below 1ulp, we compute log
3153 + * by
3154 + * log(1+f) = f - s*(f - R) (if f is not too large)
3155 + * log(1+f) = f - (hfsq - s*(hfsq+R)). (better accuracy)
3157 + * 3. Finally, log(x) = k*ln2 + log(1+f).
3158 + * = k*ln2_hi+(f-(hfsq-(s*(hfsq+R)+k*ln2_lo)))
3159 + * Here ln2 is split into two floating point number:
3160 + * ln2_hi + ln2_lo,
3161 + * where n*ln2_hi is always exact for |n| < 2000.
3163 + * Special cases:
3164 + * log(x) is NaN with signal if x < 0 (including -INF) ;
3165 + * log(+INF) is +INF; log(0) is -INF with signal;
3166 + * log(NaN) is that NaN with no signal.
3168 + * Accuracy:
3169 + * according to an error analysis, the error is always less than
3170 + * 1 ulp (unit in the last place).
3172 + * Constants:
3173 + * The hexadecimal values are the intended ones for the following
3174 + * constants. The decimal values may be used, provided that the
3175 + * compiler will convert from decimal to binary accurately enough
3176 + * to produce the hexadecimal values shown.
3177 + */
3179 +#include "math.h"
3180 +#include "math_private.h"
3182 +#ifdef __STDC__
3183 +static const double
3184 +#else
3185 +static double
3186 +#endif
3187 +ln2_hi = 6.93147180369123816490e-01, /* 3fe62e42 fee00000 */
3188 +ln2_lo = 1.90821492927058770002e-10, /* 3dea39ef 35793c76 */
3189 +two54 = 1.80143985094819840000e+16, /* 43500000 00000000 */
3190 +Lg1 = 6.666666666666735130e-01, /* 3FE55555 55555593 */
3191 +Lg2 = 3.999999999940941908e-01, /* 3FD99999 9997FA04 */
3192 +Lg3 = 2.857142874366239149e-01, /* 3FD24924 94229359 */
3193 +Lg4 = 2.222219843214978396e-01, /* 3FCC71C5 1D8E78AF */
3194 +Lg5 = 1.818357216161805012e-01, /* 3FC74664 96CB03DE */
3195 +Lg6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */
3196 +Lg7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */
3198 +#ifdef __STDC__
3199 +static const double zero = 0.0;
3200 +#else
3201 +static double zero = 0.0;
3202 +#endif
3204 +#ifdef __STDC__
3205 + double __ieee754_log(double x)
3206 +#else
3207 + double __ieee754_log(x)
3208 + double x;
3209 +#endif
3211 + double hfsq,f,s,z,R,w,t1,t2,dk;
3212 + int32_t k,hx,i,j;
3213 + u_int32_t lx;
3215 + EXTRACT_WORDS(hx,lx,x);
3217 + k=0;
3218 + if (hx < 0x00100000) { /* x < 2**-1022 */
3219 + if (((hx&0x7fffffff)|lx)==0)
3220 + return -two54/zero; /* log(+-0)=-inf */
3221 + if (hx<0) return (x-x)/zero; /* log(-#) = NaN */
3222 + k -= 54; x *= two54; /* subnormal number, scale up x */
3223 + GET_HIGH_WORD(hx,x);
3225 + if (hx >= 0x7ff00000) return x+x;
3226 + k += (hx>>20)-1023;
3227 + hx &= 0x000fffff;
3228 + i = (hx+0x95f64)&0x100000;
3229 + SET_HIGH_WORD(x,hx|(i^0x3ff00000)); /* normalize x or x/2 */
3230 + k += (i>>20);
3231 + f = x-1.0;
3232 + if((0x000fffff&(2+hx))<3) { /* |f| < 2**-20 */
3233 + if(f==zero) {if(k==0) return zero; else {dk=(double)k;
3234 + return dk*ln2_hi+dk*ln2_lo;}
3236 + R = f*f*(0.5-0.33333333333333333*f);
3237 + if(k==0) return f-R; else {dk=(double)k;
3238 + return dk*ln2_hi-((R-dk*ln2_lo)-f);}
3240 + s = f/(2.0+f);
3241 + dk = (double)k;
3242 + z = s*s;
3243 + i = hx-0x6147a;
3244 + w = z*z;
3245 + j = 0x6b851-hx;
3246 + t1= w*(Lg2+w*(Lg4+w*Lg6));
3247 + t2= z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7)));
3248 + i |= j;
3249 + R = t2+t1;
3250 + if(i>0) {
3251 + hfsq=0.5*f*f;
3252 + if(k==0) return f-(hfsq-s*(hfsq+R)); else
3253 + return dk*ln2_hi-((hfsq-(s*(hfsq+R)+dk*ln2_lo))-f);
3254 + } else {
3255 + if(k==0) return f-s*(f-R); else
3256 + return dk*ln2_hi-((s*(f-R)-dk*ln2_lo)-f);
3259 diff -urN dietlibc-0.30/libm/e_log10.c dietlibc-0.30-libm/libm/e_log10.c
3260 --- dietlibc-0.30/libm/e_log10.c 1970-01-01 00:00:00.000000000 +0000
3261 +++ dietlibc-0.30-libm/libm/e_log10.c 2006-06-25 11:20:14.000000000 +0000
3262 @@ -0,0 +1,98 @@
3263 +/* @(#)e_log10.c 5.1 93/09/24 */
3265 + * ====================================================
3266 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
3268 + * Developed at SunPro, a Sun Microsystems, Inc. business.
3269 + * Permission to use, copy, modify, and distribute this
3270 + * software is freely granted, provided that this notice
3271 + * is preserved.
3272 + * ====================================================
3273 + */
3275 +#if defined(LIBM_SCCS) && !defined(lint)
3276 +static char rcsid[] = "$NetBSD: e_log10.c,v 1.9 1995/05/10 20:45:51 jtc Exp $";
3277 +#endif
3279 +/* __ieee754_log10(x)
3280 + * Return the base 10 logarithm of x
3282 + * Method :
3283 + * Let log10_2hi = leading 40 bits of log10(2) and
3284 + * log10_2lo = log10(2) - log10_2hi,
3285 + * ivln10 = 1/log(10) rounded.
3286 + * Then
3287 + * n = ilogb(x),
3288 + * if(n<0) n = n+1;
3289 + * x = scalbn(x,-n);
3290 + * log10(x) := n*log10_2hi + (n*log10_2lo + ivln10*log(x))
3292 + * Note 1:
3293 + * To guarantee log10(10**n)=n, where 10**n is normal, the rounding
3294 + * mode must set to Round-to-Nearest.
3295 + * Note 2:
3296 + * [1/log(10)] rounded to 53 bits has error .198 ulps;
3297 + * log10 is monotonic at all binary break points.
3299 + * Special cases:
3300 + * log10(x) is NaN with signal if x < 0;
3301 + * log10(+INF) is +INF with no signal; log10(0) is -INF with signal;
3302 + * log10(NaN) is that NaN with no signal;
3303 + * log10(10**N) = N for N=0,1,...,22.
3305 + * Constants:
3306 + * The hexadecimal values are the intended ones for the following constants.
3307 + * The decimal values may be used, provided that the compiler will convert
3308 + * from decimal to binary accurately enough to produce the hexadecimal values
3309 + * shown.
3310 + */
3312 +#include "math.h"
3313 +#include "math_private.h"
3315 +#ifdef __STDC__
3316 +static const double
3317 +#else
3318 +static double
3319 +#endif
3320 +two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */
3321 +ivln10 = 4.34294481903251816668e-01, /* 0x3FDBCB7B, 0x1526E50E */
3322 +log10_2hi = 3.01029995663611771306e-01, /* 0x3FD34413, 0x509F6000 */
3323 +log10_2lo = 3.69423907715893078616e-13; /* 0x3D59FEF3, 0x11F12B36 */
3325 +#ifdef __STDC__
3326 +static const double zero = 0.0;
3327 +#else
3328 +static double zero = 0.0;
3329 +#endif
3331 +#ifdef __STDC__
3332 + double __ieee754_log10(double x)
3333 +#else
3334 + double __ieee754_log10(x)
3335 + double x;
3336 +#endif
3338 + double y,z;
3339 + int32_t i,k,hx;
3340 + u_int32_t lx;
3342 + EXTRACT_WORDS(hx,lx,x);
3344 + k=0;
3345 + if (hx < 0x00100000) { /* x < 2**-1022 */
3346 + if (((hx&0x7fffffff)|lx)==0)
3347 + return -two54/zero; /* log(+-0)=-inf */
3348 + if (hx<0) return (x-x)/zero; /* log(-#) = NaN */
3349 + k -= 54; x *= two54; /* subnormal number, scale up x */
3350 + GET_HIGH_WORD(hx,x);
3352 + if (hx >= 0x7ff00000) return x+x;
3353 + k += (hx>>20)-1023;
3354 + i = ((u_int32_t)k&0x80000000)>>31;
3355 + hx = (hx&0x000fffff)|((0x3ff-i)<<20);
3356 + y = (double)(k+i);
3357 + SET_HIGH_WORD(x,hx);
3358 + z = y*log10_2lo + ivln10*__ieee754_log(x);
3359 + return z+y*log10_2hi;
3361 diff -urN dietlibc-0.30/libm/e_pow.c dietlibc-0.30-libm/libm/e_pow.c
3362 --- dietlibc-0.30/libm/e_pow.c 1970-01-01 00:00:00.000000000 +0000
3363 +++ dietlibc-0.30-libm/libm/e_pow.c 2006-06-25 11:20:02.000000000 +0000
3364 @@ -0,0 +1,308 @@
3365 +/* @(#)e_pow.c 5.1 93/09/24 */
3367 + * ====================================================
3368 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
3370 + * Developed at SunPro, a Sun Microsystems, Inc. business.
3371 + * Permission to use, copy, modify, and distribute this
3372 + * software is freely granted, provided that this notice
3373 + * is preserved.
3374 + * ====================================================
3375 + */
3377 +#if defined(LIBM_SCCS) && !defined(lint)
3378 +static char rcsid[] = "$NetBSD: e_pow.c,v 1.9 1995/05/12 04:57:32 jtc Exp $";
3379 +#endif
3381 +/* __ieee754_pow(x,y) return x**y
3383 + * n
3384 + * Method: Let x = 2 * (1+f)
3385 + * 1. Compute and return log2(x) in two pieces:
3386 + * log2(x) = w1 + w2,
3387 + * where w1 has 53-24 = 29 bit trailing zeros.
3388 + * 2. Perform y*log2(x) = n+y' by simulating muti-precision
3389 + * arithmetic, where |y'|<=0.5.
3390 + * 3. Return x**y = 2**n*exp(y'*log2)
3392 + * Special cases:
3393 + * 1. (anything) ** 0 is 1
3394 + * 2. (anything) ** 1 is itself
3395 + * 3. (anything) ** NAN is NAN
3396 + * 4. NAN ** (anything except 0) is NAN
3397 + * 5. +-(|x| > 1) ** +INF is +INF
3398 + * 6. +-(|x| > 1) ** -INF is +0
3399 + * 7. +-(|x| < 1) ** +INF is +0
3400 + * 8. +-(|x| < 1) ** -INF is +INF
3401 + * 9. +-1 ** +-INF is NAN
3402 + * 10. +0 ** (+anything except 0, NAN) is +0
3403 + * 11. -0 ** (+anything except 0, NAN, odd integer) is +0
3404 + * 12. +0 ** (-anything except 0, NAN) is +INF
3405 + * 13. -0 ** (-anything except 0, NAN, odd integer) is +INF
3406 + * 14. -0 ** (odd integer) = -( +0 ** (odd integer) )
3407 + * 15. +INF ** (+anything except 0,NAN) is +INF
3408 + * 16. +INF ** (-anything except 0,NAN) is +0
3409 + * 17. -INF ** (anything) = -0 ** (-anything)
3410 + * 18. (-anything) ** (integer) is (-1)**(integer)*(+anything**integer)
3411 + * 19. (-anything except 0 and inf) ** (non-integer) is NAN
3413 + * Accuracy:
3414 + * pow(x,y) returns x**y nearly rounded. In particular
3415 + * pow(integer,integer)
3416 + * always returns the correct integer provided it is
3417 + * representable.
3419 + * Constants :
3420 + * The hexadecimal values are the intended ones for the following
3421 + * constants. The decimal values may be used, provided that the
3422 + * compiler will convert from decimal to binary accurately enough
3423 + * to produce the hexadecimal values shown.
3424 + */
3426 +#include "math.h"
3427 +#include "math_private.h"
3429 +#ifdef __STDC__
3430 +static const double
3431 +#else
3432 +static double
3433 +#endif
3434 +bp[] = {1.0, 1.5,},
3435 +dp_h[] = { 0.0, 5.84962487220764160156e-01,}, /* 0x3FE2B803, 0x40000000 */
3436 +dp_l[] = { 0.0, 1.35003920212974897128e-08,}, /* 0x3E4CFDEB, 0x43CFD006 */
3437 +zero = 0.0,
3438 +one = 1.0,
3439 +two = 2.0,
3440 +two53 = 9007199254740992.0, /* 0x43400000, 0x00000000 */
3441 +huge = 1.0e300,
3442 +tiny = 1.0e-300,
3443 + /* poly coefs for (3/2)*(log(x)-2s-2/3*s**3 */
3444 +L1 = 5.99999999999994648725e-01, /* 0x3FE33333, 0x33333303 */
3445 +L2 = 4.28571428578550184252e-01, /* 0x3FDB6DB6, 0xDB6FABFF */
3446 +L3 = 3.33333329818377432918e-01, /* 0x3FD55555, 0x518F264D */
3447 +L4 = 2.72728123808534006489e-01, /* 0x3FD17460, 0xA91D4101 */
3448 +L5 = 2.30660745775561754067e-01, /* 0x3FCD864A, 0x93C9DB65 */
3449 +L6 = 2.06975017800338417784e-01, /* 0x3FCA7E28, 0x4A454EEF */
3450 +P1 = 1.66666666666666019037e-01, /* 0x3FC55555, 0x5555553E */
3451 +P2 = -2.77777777770155933842e-03, /* 0xBF66C16C, 0x16BEBD93 */
3452 +P3 = 6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */
3453 +P4 = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */
3454 +P5 = 4.13813679705723846039e-08, /* 0x3E663769, 0x72BEA4D0 */
3455 +lg2 = 6.93147180559945286227e-01, /* 0x3FE62E42, 0xFEFA39EF */
3456 +lg2_h = 6.93147182464599609375e-01, /* 0x3FE62E43, 0x00000000 */
3457 +lg2_l = -1.90465429995776804525e-09, /* 0xBE205C61, 0x0CA86C39 */
3458 +ovt = 8.0085662595372944372e-0017, /* -(1024-log2(ovfl+.5ulp)) */
3459 +cp = 9.61796693925975554329e-01, /* 0x3FEEC709, 0xDC3A03FD =2/(3ln2) */
3460 +cp_h = 9.61796700954437255859e-01, /* 0x3FEEC709, 0xE0000000 =(float)cp */
3461 +cp_l = -7.02846165095275826516e-09, /* 0xBE3E2FE0, 0x145B01F5 =tail of cp_h*/
3462 +ivln2 = 1.44269504088896338700e+00, /* 0x3FF71547, 0x652B82FE =1/ln2 */
3463 +ivln2_h = 1.44269502162933349609e+00, /* 0x3FF71547, 0x60000000 =24b 1/ln2*/
3464 +ivln2_l = 1.92596299112661746887e-08; /* 0x3E54AE0B, 0xF85DDF44 =1/ln2 tail*/
3466 +#ifdef __STDC__
3467 + double __ieee754_pow(double x, double y)
3468 +#else
3469 + double __ieee754_pow(x,y)
3470 + double x, y;
3471 +#endif
3473 + double z,ax,z_h,z_l,p_h,p_l;
3474 + double y1,t1,t2,r,s,t,u,v,w;
3475 + int32_t i,j,k,yisint,n;
3476 + int32_t hx,hy,ix,iy;
3477 + u_int32_t lx,ly;
3479 + EXTRACT_WORDS(hx,lx,x);
3480 + EXTRACT_WORDS(hy,ly,y);
3481 + ix = hx&0x7fffffff; iy = hy&0x7fffffff;
3483 + /* y==zero: x**0 = 1 */
3484 + if((iy|ly)==0) return one;
3486 + /* +-NaN return x+y */
3487 + if(ix > 0x7ff00000 || ((ix==0x7ff00000)&&(lx!=0)) ||
3488 + iy > 0x7ff00000 || ((iy==0x7ff00000)&&(ly!=0)))
3489 + return x+y;
3491 + /* determine if y is an odd int when x < 0
3492 + * yisint = 0 ... y is not an integer
3493 + * yisint = 1 ... y is an odd int
3494 + * yisint = 2 ... y is an even int
3495 + */
3496 + yisint = 0;
3497 + if(hx<0) {
3498 + if(iy>=0x43400000) yisint = 2; /* even integer y */
3499 + else if(iy>=0x3ff00000) {
3500 + k = (iy>>20)-0x3ff; /* exponent */
3501 + if(k>20) {
3502 + j = ly>>(52-k);
3503 + if((j<<(52-k))==ly) yisint = 2-(j&1);
3504 + } else if(ly==0) {
3505 + j = iy>>(20-k);
3506 + if((j<<(20-k))==iy) yisint = 2-(j&1);
3511 + /* special value of y */
3512 + if(ly==0) {
3513 + if (iy==0x7ff00000) { /* y is +-inf */
3514 + if(((ix-0x3ff00000)|lx)==0)
3515 + return y - y; /* inf**+-1 is NaN */
3516 + else if (ix >= 0x3ff00000)/* (|x|>1)**+-inf = inf,0 */
3517 + return (hy>=0)? y: zero;
3518 + else /* (|x|<1)**-,+inf = inf,0 */
3519 + return (hy<0)?-y: zero;
3521 + if(iy==0x3ff00000) { /* y is +-1 */
3522 + if(hy<0) return one/x; else return x;
3524 + if(hy==0x40000000) return x*x; /* y is 2 */
3525 + if(hy==0x3fe00000) { /* y is 0.5 */
3526 + if(hx>=0) /* x >= +0 */
3527 + return __ieee754_sqrt(x);
3531 + ax = fabs(x);
3532 + /* special value of x */
3533 + if(lx==0) {
3534 + if(ix==0x7ff00000||ix==0||ix==0x3ff00000){
3535 + z = ax; /*x is +-0,+-inf,+-1*/
3536 + if(hy<0) z = one/z; /* z = (1/|x|) */
3537 + if(hx<0) {
3538 + if(((ix-0x3ff00000)|yisint)==0) {
3539 + z = (z-z)/(z-z); /* (-1)**non-int is NaN */
3540 + } else if(yisint==1)
3541 + z = -z; /* (x<0)**odd = -(|x|**odd) */
3543 + return z;
3547 + /* (x<0)**(non-int) is NaN */
3548 + if(((((u_int32_t)hx>>31)-1)|yisint)==0) return (x-x)/(x-x);
3550 + /* |y| is huge */
3551 + if(iy>0x41e00000) { /* if |y| > 2**31 */
3552 + if(iy>0x43f00000){ /* if |y| > 2**64, must o/uflow */
3553 + if(ix<=0x3fefffff) return (hy<0)? huge*huge:tiny*tiny;
3554 + if(ix>=0x3ff00000) return (hy>0)? huge*huge:tiny*tiny;
3556 + /* over/underflow if x is not close to one */
3557 + if(ix<0x3fefffff) return (hy<0)? huge*huge:tiny*tiny;
3558 + if(ix>0x3ff00000) return (hy>0)? huge*huge:tiny*tiny;
3559 + /* now |1-x| is tiny <= 2**-20, suffice to compute
3560 + log(x) by x-x^2/2+x^3/3-x^4/4 */
3561 + t = x-1; /* t has 20 trailing zeros */
3562 + w = (t*t)*(0.5-t*(0.3333333333333333333333-t*0.25));
3563 + u = ivln2_h*t; /* ivln2_h has 21 sig. bits */
3564 + v = t*ivln2_l-w*ivln2;
3565 + t1 = u+v;
3566 + SET_LOW_WORD(t1,0);
3567 + t2 = v-(t1-u);
3568 + } else {
3569 + double s2,s_h,s_l,t_h,t_l;
3570 + n = 0;
3571 + /* take care subnormal number */
3572 + if(ix<0x00100000)
3573 + {ax *= two53; n -= 53; GET_HIGH_WORD(ix,ax); }
3574 + n += ((ix)>>20)-0x3ff;
3575 + j = ix&0x000fffff;
3576 + /* determine interval */
3577 + ix = j|0x3ff00000; /* normalize ix */
3578 + if(j<=0x3988E) k=0; /* |x|<sqrt(3/2) */
3579 + else if(j<0xBB67A) k=1; /* |x|<sqrt(3) */
3580 + else {k=0;n+=1;ix -= 0x00100000;}
3581 + SET_HIGH_WORD(ax,ix);
3583 + /* compute s = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5) */
3584 + u = ax-bp[k]; /* bp[0]=1.0, bp[1]=1.5 */
3585 + v = one/(ax+bp[k]);
3586 + s = u*v;
3587 + s_h = s;
3588 + SET_LOW_WORD(s_h,0);
3589 + /* t_h=ax+bp[k] High */
3590 + t_h = zero;
3591 + SET_HIGH_WORD(t_h,((ix>>1)|0x20000000)+0x00080000+(k<<18));
3592 + t_l = ax - (t_h-bp[k]);
3593 + s_l = v*((u-s_h*t_h)-s_h*t_l);
3594 + /* compute log(ax) */
3595 + s2 = s*s;
3596 + r = s2*s2*(L1+s2*(L2+s2*(L3+s2*(L4+s2*(L5+s2*L6)))));
3597 + r += s_l*(s_h+s);
3598 + s2 = s_h*s_h;
3599 + t_h = 3.0+s2+r;
3600 + SET_LOW_WORD(t_h,0);
3601 + t_l = r-((t_h-3.0)-s2);
3602 + /* u+v = s*(1+...) */
3603 + u = s_h*t_h;
3604 + v = s_l*t_h+t_l*s;
3605 + /* 2/(3log2)*(s+...) */
3606 + p_h = u+v;
3607 + SET_LOW_WORD(p_h,0);
3608 + p_l = v-(p_h-u);
3609 + z_h = cp_h*p_h; /* cp_h+cp_l = 2/(3*log2) */
3610 + z_l = cp_l*p_h+p_l*cp+dp_l[k];
3611 + /* log2(ax) = (s+..)*2/(3*log2) = n + dp_h + z_h + z_l */
3612 + t = (double)n;
3613 + t1 = (((z_h+z_l)+dp_h[k])+t);
3614 + SET_LOW_WORD(t1,0);
3615 + t2 = z_l-(((t1-t)-dp_h[k])-z_h);
3618 + s = one; /* s (sign of result -ve**odd) = -1 else = 1 */
3619 + if(((((u_int32_t)hx>>31)-1)|(yisint-1))==0)
3620 + s = -one;/* (-ve)**(odd int) */
3622 + /* split up y into y1+y2 and compute (y1+y2)*(t1+t2) */
3623 + y1 = y;
3624 + SET_LOW_WORD(y1,0);
3625 + p_l = (y-y1)*t1+y*t2;
3626 + p_h = y1*t1;
3627 + z = p_l+p_h;
3628 + EXTRACT_WORDS(j,i,z);
3629 + if (j>=0x40900000) { /* z >= 1024 */
3630 + if(((j-0x40900000)|i)!=0) /* if z > 1024 */
3631 + return s*huge*huge; /* overflow */
3632 + else {
3633 + if(p_l+ovt>z-p_h) return s*huge*huge; /* overflow */
3635 + } else if((j&0x7fffffff)>=0x4090cc00 ) { /* z <= -1075 */
3636 + if(((j-0xc090cc00)|i)!=0) /* z < -1075 */
3637 + return s*tiny*tiny; /* underflow */
3638 + else {
3639 + if(p_l<=z-p_h) return s*tiny*tiny; /* underflow */
3642 + /*
3643 + * compute 2**(p_h+p_l)
3644 + */
3645 + i = j&0x7fffffff;
3646 + k = (i>>20)-0x3ff;
3647 + n = 0;
3648 + if(i>0x3fe00000) { /* if |z| > 0.5, set n = [z+0.5] */
3649 + n = j+(0x00100000>>(k+1));
3650 + k = ((n&0x7fffffff)>>20)-0x3ff; /* new k for n */
3651 + t = zero;
3652 + SET_HIGH_WORD(t,n&~(0x000fffff>>k));
3653 + n = ((n&0x000fffff)|0x00100000)>>(20-k);
3654 + if(j<0) n = -n;
3655 + p_h -= t;
3657 + t = p_l+p_h;
3658 + SET_LOW_WORD(t,0);
3659 + u = t*lg2_h;
3660 + v = (p_l-(t-p_h))*lg2+t*lg2_l;
3661 + z = u+v;
3662 + w = v-(z-u);
3663 + t = z*z;
3664 + t1 = z - t*(P1+t*(P2+t*(P3+t*(P4+t*P5))));
3665 + r = (z*t1)/(t1-two)-(w+z*w);
3666 + z = one-(r-z);
3667 + GET_HIGH_WORD(j,z);
3668 + j += (n<<20);
3669 + if((j>>20)<=0) z = scalbn(z,n); /* subnormal output */
3670 + else SET_HIGH_WORD(z,j);
3671 + return s*z;
3673 diff -urN dietlibc-0.30/libm/e_rem_pio2.c dietlibc-0.30-libm/libm/e_rem_pio2.c
3674 --- dietlibc-0.30/libm/e_rem_pio2.c 1970-01-01 00:00:00.000000000 +0000
3675 +++ dietlibc-0.30-libm/libm/e_rem_pio2.c 2006-06-25 11:20:15.000000000 +0000
3676 @@ -0,0 +1,183 @@
3677 +/* @(#)e_rem_pio2.c 5.1 93/09/24 */
3679 + * ====================================================
3680 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
3682 + * Developed at SunPro, a Sun Microsystems, Inc. business.
3683 + * Permission to use, copy, modify, and distribute this
3684 + * software is freely granted, provided that this notice
3685 + * is preserved.
3686 + * ====================================================
3687 + */
3689 +#if defined(LIBM_SCCS) && !defined(lint)
3690 +static char rcsid[] = "$NetBSD: e_rem_pio2.c,v 1.8 1995/05/10 20:46:02 jtc Exp $";
3691 +#endif
3693 +/* __ieee754_rem_pio2(x,y)
3695 + * return the remainder of x rem pi/2 in y[0]+y[1]
3696 + * use __kernel_rem_pio2()
3697 + */
3699 +#include "math.h"
3700 +#include "math_private.h"
3703 + * Table of constants for 2/pi, 396 Hex digits (476 decimal) of 2/pi
3704 + */
3705 +#ifdef __STDC__
3706 +static const int32_t two_over_pi[] = {
3707 +#else
3708 +static int32_t two_over_pi[] = {
3709 +#endif
3710 +0xA2F983, 0x6E4E44, 0x1529FC, 0x2757D1, 0xF534DD, 0xC0DB62,
3711 +0x95993C, 0x439041, 0xFE5163, 0xABDEBB, 0xC561B7, 0x246E3A,
3712 +0x424DD2, 0xE00649, 0x2EEA09, 0xD1921C, 0xFE1DEB, 0x1CB129,
3713 +0xA73EE8, 0x8235F5, 0x2EBB44, 0x84E99C, 0x7026B4, 0x5F7E41,
3714 +0x3991D6, 0x398353, 0x39F49C, 0x845F8B, 0xBDF928, 0x3B1FF8,
3715 +0x97FFDE, 0x05980F, 0xEF2F11, 0x8B5A0A, 0x6D1F6D, 0x367ECF,
3716 +0x27CB09, 0xB74F46, 0x3F669E, 0x5FEA2D, 0x7527BA, 0xC7EBE5,
3717 +0xF17B3D, 0x0739F7, 0x8A5292, 0xEA6BFB, 0x5FB11F, 0x8D5D08,
3718 +0x560330, 0x46FC7B, 0x6BABF0, 0xCFBC20, 0x9AF436, 0x1DA9E3,
3719 +0x91615E, 0xE61B08, 0x659985, 0x5F14A0, 0x68408D, 0xFFD880,
3720 +0x4D7327, 0x310606, 0x1556CA, 0x73A8C9, 0x60E27B, 0xC08C6B,
3723 +#ifdef __STDC__
3724 +static const int32_t npio2_hw[] = {
3725 +#else
3726 +static int32_t npio2_hw[] = {
3727 +#endif
3728 +0x3FF921FB, 0x400921FB, 0x4012D97C, 0x401921FB, 0x401F6A7A, 0x4022D97C,
3729 +0x4025FDBB, 0x402921FB, 0x402C463A, 0x402F6A7A, 0x4031475C, 0x4032D97C,
3730 +0x40346B9C, 0x4035FDBB, 0x40378FDB, 0x403921FB, 0x403AB41B, 0x403C463A,
3731 +0x403DD85A, 0x403F6A7A, 0x40407E4C, 0x4041475C, 0x4042106C, 0x4042D97C,
3732 +0x4043A28C, 0x40446B9C, 0x404534AC, 0x4045FDBB, 0x4046C6CB, 0x40478FDB,
3733 +0x404858EB, 0x404921FB,
3737 + * invpio2: 53 bits of 2/pi
3738 + * pio2_1: first 33 bit of pi/2
3739 + * pio2_1t: pi/2 - pio2_1
3740 + * pio2_2: second 33 bit of pi/2
3741 + * pio2_2t: pi/2 - (pio2_1+pio2_2)
3742 + * pio2_3: third 33 bit of pi/2
3743 + * pio2_3t: pi/2 - (pio2_1+pio2_2+pio2_3)
3744 + */
3746 +#ifdef __STDC__
3747 +static const double
3748 +#else
3749 +static double
3750 +#endif
3751 +zero = 0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */
3752 +half = 5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */
3753 +two24 = 1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */
3754 +invpio2 = 6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */
3755 +pio2_1 = 1.57079632673412561417e+00, /* 0x3FF921FB, 0x54400000 */
3756 +pio2_1t = 6.07710050650619224932e-11, /* 0x3DD0B461, 0x1A626331 */
3757 +pio2_2 = 6.07710050630396597660e-11, /* 0x3DD0B461, 0x1A600000 */
3758 +pio2_2t = 2.02226624879595063154e-21, /* 0x3BA3198A, 0x2E037073 */
3759 +pio2_3 = 2.02226624871116645580e-21, /* 0x3BA3198A, 0x2E000000 */
3760 +pio2_3t = 8.47842766036889956997e-32; /* 0x397B839A, 0x252049C1 */
3762 +#ifdef __STDC__
3763 + int32_t __ieee754_rem_pio2(double x, double *y)
3764 +#else
3765 + int32_t __ieee754_rem_pio2(x,y)
3766 + double x,y[];
3767 +#endif
3769 + double z=0.0,w,t,r,fn;
3770 + double tx[3];
3771 + int32_t e0,i,j,nx,n,ix,hx;
3772 + u_int32_t low;
3774 + GET_HIGH_WORD(hx,x); /* high word of x */
3775 + ix = hx&0x7fffffff;
3776 + if(ix<=0x3fe921fb) /* |x| ~<= pi/4 , no need for reduction */
3777 + {y[0] = x; y[1] = 0; return 0;}
3778 + if(ix<0x4002d97c) { /* |x| < 3pi/4, special case with n=+-1 */
3779 + if(hx>0) {
3780 + z = x - pio2_1;
3781 + if(ix!=0x3ff921fb) { /* 33+53 bit pi is good enough */
3782 + y[0] = z - pio2_1t;
3783 + y[1] = (z-y[0])-pio2_1t;
3784 + } else { /* near pi/2, use 33+33+53 bit pi */
3785 + z -= pio2_2;
3786 + y[0] = z - pio2_2t;
3787 + y[1] = (z-y[0])-pio2_2t;
3789 + return 1;
3790 + } else { /* negative x */
3791 + z = x + pio2_1;
3792 + if(ix!=0x3ff921fb) { /* 33+53 bit pi is good enough */
3793 + y[0] = z + pio2_1t;
3794 + y[1] = (z-y[0])+pio2_1t;
3795 + } else { /* near pi/2, use 33+33+53 bit pi */
3796 + z += pio2_2;
3797 + y[0] = z + pio2_2t;
3798 + y[1] = (z-y[0])+pio2_2t;
3800 + return -1;
3803 + if(ix<=0x413921fb) { /* |x| ~<= 2^19*(pi/2), medium size */
3804 + t = fabs(x);
3805 + n = (int32_t) (t*invpio2+half);
3806 + fn = (double)n;
3807 + r = t-fn*pio2_1;
3808 + w = fn*pio2_1t; /* 1st round good to 85 bit */
3809 + if(n<32&&ix!=npio2_hw[n-1]) {
3810 + y[0] = r-w; /* quick check no cancellation */
3811 + } else {
3812 + u_int32_t high;
3813 + j = ix>>20;
3814 + y[0] = r-w;
3815 + GET_HIGH_WORD(high,y[0]);
3816 + i = j-((high>>20)&0x7ff);
3817 + if(i>16) { /* 2nd iteration needed, good to 118 */
3818 + t = r;
3819 + w = fn*pio2_2;
3820 + r = t-w;
3821 + w = fn*pio2_2t-((t-r)-w);
3822 + y[0] = r-w;
3823 + GET_HIGH_WORD(high,y[0]);
3824 + i = j-((high>>20)&0x7ff);
3825 + if(i>49) { /* 3rd iteration need, 151 bits acc */
3826 + t = r; /* will cover all possible cases */
3827 + w = fn*pio2_3;
3828 + r = t-w;
3829 + w = fn*pio2_3t-((t-r)-w);
3830 + y[0] = r-w;
3834 + y[1] = (r-y[0])-w;
3835 + if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;}
3836 + else return n;
3838 + /*
3839 + * all other (large) arguments
3840 + */
3841 + if(ix>=0x7ff00000) { /* x is inf or NaN */
3842 + y[0]=y[1]=x-x; return 0;
3844 + /* set z = scalbn(|x|,ilogb(x)-23) */
3845 + GET_LOW_WORD(low,x);
3846 + SET_LOW_WORD(z,low);
3847 + e0 = (ix>>20)-1046; /* e0 = ilogb(z)-23; */
3848 + SET_HIGH_WORD(z, ix - ((int32_t)(e0<<20)));
3849 + for(i=0;i<2;i++) {
3850 + tx[i] = (double)((int32_t)(z));
3851 + z = (z-tx[i])*two24;
3853 + tx[2] = z;
3854 + nx = 3;
3855 + while(tx[nx-1]==zero) nx--; /* skip zero term */
3856 + n = __kernel_rem_pio2(tx,y,e0,nx,2,two_over_pi);
3857 + if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;}
3858 + return n;
3860 diff -urN dietlibc-0.30/libm/e_remainder.c dietlibc-0.30-libm/libm/e_remainder.c
3861 --- dietlibc-0.30/libm/e_remainder.c 1970-01-01 00:00:00.000000000 +0000
3862 +++ dietlibc-0.30-libm/libm/e_remainder.c 2006-06-25 11:20:04.000000000 +0000
3863 @@ -0,0 +1,80 @@
3864 +/* @(#)e_remainder.c 5.1 93/09/24 */
3866 + * ====================================================
3867 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
3869 + * Developed at SunPro, a Sun Microsystems, Inc. business.
3870 + * Permission to use, copy, modify, and distribute this
3871 + * software is freely granted, provided that this notice
3872 + * is preserved.
3873 + * ====================================================
3874 + */
3876 +#if defined(LIBM_SCCS) && !defined(lint)
3877 +static char rcsid[] = "$NetBSD: e_remainder.c,v 1.8 1995/05/10 20:46:05 jtc Exp $";
3878 +#endif
3880 +/* __ieee754_remainder(x,p)
3881 + * Return :
3882 + * returns x REM p = x - [x/p]*p as if in infinite
3883 + * precise arithmetic, where [x/p] is the (infinite bit)
3884 + * integer nearest x/p (in half way case choose the even one).
3885 + * Method :
3886 + * Based on fmod() return x-[x/p]chopped*p exactlp.
3887 + */
3889 +#include "math.h"
3890 +#include "math_private.h"
3892 +#ifdef __STDC__
3893 +static const double zero = 0.0;
3894 +#else
3895 +static double zero = 0.0;
3896 +#endif
3899 +#ifdef __STDC__
3900 + double __ieee754_remainder(double x, double p)
3901 +#else
3902 + double __ieee754_remainder(x,p)
3903 + double x,p;
3904 +#endif
3906 + int32_t hx,hp;
3907 + u_int32_t sx,lx,lp;
3908 + double p_half;
3910 + EXTRACT_WORDS(hx,lx,x);
3911 + EXTRACT_WORDS(hp,lp,p);
3912 + sx = hx&0x80000000;
3913 + hp &= 0x7fffffff;
3914 + hx &= 0x7fffffff;
3916 + /* purge off exception values */
3917 + if((hp|lp)==0) return (x*p)/(x*p); /* p = 0 */
3918 + if((hx>=0x7ff00000)|| /* x not finite */
3919 + ((hp>=0x7ff00000)&& /* p is NaN */
3920 + (((hp-0x7ff00000)|lp)!=0)))
3921 + return (x*p)/(x*p);
3924 + if (hp<=0x7fdfffff) x = __ieee754_fmod(x,p+p); /* now x < 2p */
3925 + if (((hx-hp)|(lx-lp))==0) return zero*x;
3926 + x = fabs(x);
3927 + p = fabs(p);
3928 + if (hp<0x00200000) {
3929 + if(x+x>p) {
3930 + x-=p;
3931 + if(x+x>=p) x -= p;
3933 + } else {
3934 + p_half = 0.5*p;
3935 + if(x>p_half) {
3936 + x-=p;
3937 + if(x>=p_half) x -= p;
3940 + GET_HIGH_WORD(hx,x);
3941 + SET_HIGH_WORD(x,hx^sx);
3942 + return x;
3944 diff -urN dietlibc-0.30/libm/e_scalb.c dietlibc-0.30-libm/libm/e_scalb.c
3945 --- dietlibc-0.30/libm/e_scalb.c 1970-01-01 00:00:00.000000000 +0000
3946 +++ dietlibc-0.30-libm/libm/e_scalb.c 2006-06-25 11:20:10.000000000 +0000
3947 @@ -0,0 +1,55 @@
3948 +/* @(#)e_scalb.c 5.1 93/09/24 */
3950 + * ====================================================
3951 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
3953 + * Developed at SunPro, a Sun Microsystems, Inc. business.
3954 + * Permission to use, copy, modify, and distribute this
3955 + * software is freely granted, provided that this notice
3956 + * is preserved.
3957 + * ====================================================
3958 + */
3960 +#if defined(LIBM_SCCS) && !defined(lint)
3961 +static char rcsid[] = "$NetBSD: e_scalb.c,v 1.6 1995/05/10 20:46:09 jtc Exp $";
3962 +#endif
3965 + * __ieee754_scalb(x, fn) is provide for
3966 + * passing various standard test suite. One
3967 + * should use scalbn() instead.
3968 + */
3970 +#include "math.h"
3971 +#include "math_private.h"
3973 +#ifdef _SCALB_INT
3974 +#ifdef __STDC__
3975 + double __ieee754_scalb(double x, int fn)
3976 +#else
3977 + double __ieee754_scalb(x,fn)
3978 + double x; int fn;
3979 +#endif
3980 +#else
3981 +#ifdef __STDC__
3982 + double __ieee754_scalb(double x, double fn)
3983 +#else
3984 + double __ieee754_scalb(x,fn)
3985 + double x, fn;
3986 +#endif
3987 +#endif
3989 +#ifdef _SCALB_INT
3990 + return scalbn(x,fn);
3991 +#else
3992 + if (isnan(x)||isnan(fn)) return x*fn;
3993 + if (!finite(fn)) {
3994 + if(fn>0.0) return x*fn;
3995 + else return x/(-fn);
3997 + if (rint(fn)!=fn) return (fn-fn)/(fn-fn);
3998 + if ( fn > 65000.0) return scalbn(x, 65000);
3999 + if (-fn > 65000.0) return scalbn(x,-65000);
4000 + return scalbn(x,(int)fn);
4001 +#endif
4003 diff -urN dietlibc-0.30/libm/e_sinh.c dietlibc-0.30-libm/libm/e_sinh.c
4004 --- dietlibc-0.30/libm/e_sinh.c 1970-01-01 00:00:00.000000000 +0000
4005 +++ dietlibc-0.30-libm/libm/e_sinh.c 2006-06-25 11:20:10.000000000 +0000
4006 @@ -0,0 +1,86 @@
4007 +/* @(#)e_sinh.c 5.1 93/09/24 */
4009 + * ====================================================
4010 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
4012 + * Developed at SunPro, a Sun Microsystems, Inc. business.
4013 + * Permission to use, copy, modify, and distribute this
4014 + * software is freely granted, provided that this notice
4015 + * is preserved.
4016 + * ====================================================
4017 + */
4019 +#if defined(LIBM_SCCS) && !defined(lint)
4020 +static char rcsid[] = "$NetBSD: e_sinh.c,v 1.7 1995/05/10 20:46:13 jtc Exp $";
4021 +#endif
4023 +/* __ieee754_sinh(x)
4024 + * Method :
4025 + * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
4026 + * 1. Replace x by |x| (sinh(-x) = -sinh(x)).
4027 + * 2.
4028 + * E + E/(E+1)
4029 + * 0 <= x <= 22 : sinh(x) := --------------, E=expm1(x)
4030 + * 2
4032 + * 22 <= x <= lnovft : sinh(x) := exp(x)/2
4033 + * lnovft <= x <= ln2ovft: sinh(x) := exp(x/2)/2 * exp(x/2)
4034 + * ln2ovft < x : sinh(x) := x*shuge (overflow)
4036 + * Special cases:
4037 + * sinh(x) is |x| if x is +INF, -INF, or NaN.
4038 + * only sinh(0)=0 is exact for finite x.
4039 + */
4041 +#include "math.h"
4042 +#include "math_private.h"
4044 +#ifdef __STDC__
4045 +static const double one = 1.0, shuge = 1.0e307;
4046 +#else
4047 +static double one = 1.0, shuge = 1.0e307;
4048 +#endif
4050 +#ifdef __STDC__
4051 + double __ieee754_sinh(double x)
4052 +#else
4053 + double __ieee754_sinh(x)
4054 + double x;
4055 +#endif
4057 + double t,w,h;
4058 + int32_t ix,jx;
4059 + u_int32_t lx;
4061 + /* High word of |x|. */
4062 + GET_HIGH_WORD(jx,x);
4063 + ix = jx&0x7fffffff;
4065 + /* x is INF or NaN */
4066 + if(ix>=0x7ff00000) return x+x;
4068 + h = 0.5;
4069 + if (jx<0) h = -h;
4070 + /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */
4071 + if (ix < 0x40360000) { /* |x|<22 */
4072 + if (ix<0x3e300000) /* |x|<2**-28 */
4073 + if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */
4074 + t = expm1(fabs(x));
4075 + if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one));
4076 + return h*(t+t/(t+one));
4079 + /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */
4080 + if (ix < 0x40862E42) return h*__ieee754_exp(fabs(x));
4082 + /* |x| in [log(maxdouble), overflowthresold] */
4083 + GET_LOW_WORD(lx,x);
4084 + if (ix<0x408633CE || ((ix==0x408633ce)&&(lx<=(u_int32_t)0x8fb9f87d))) {
4085 + w = __ieee754_exp(0.5*fabs(x));
4086 + t = h*w;
4087 + return t*w;
4090 + /* |x| > overflowthresold, sinh(x) overflow */
4091 + return x*shuge;
4093 diff -urN dietlibc-0.30/libm/e_sqrt.c dietlibc-0.30-libm/libm/e_sqrt.c
4094 --- dietlibc-0.30/libm/e_sqrt.c 1970-01-01 00:00:00.000000000 +0000
4095 +++ dietlibc-0.30-libm/libm/e_sqrt.c 2006-06-25 11:20:12.000000000 +0000
4096 @@ -0,0 +1,453 @@
4097 +/* @(#)e_sqrt.c 5.1 93/09/24 */
4099 + * ====================================================
4100 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
4102 + * Developed at SunPro, a Sun Microsystems, Inc. business.
4103 + * Permission to use, copy, modify, and distribute this
4104 + * software is freely granted, provided that this notice
4105 + * is preserved.
4106 + * ====================================================
4107 + */
4109 +#if defined(LIBM_SCCS) && !defined(lint)
4110 +static char rcsid[] = "$NetBSD: e_sqrt.c,v 1.8 1995/05/10 20:46:17 jtc Exp $";
4111 +#endif
4113 +/* __ieee754_sqrt(x)
4114 + * Return correctly rounded sqrt.
4115 + * ------------------------------------------
4116 + * | Use the hardware sqrt if you have one |
4117 + * ------------------------------------------
4118 + * Method:
4119 + * Bit by bit method using integer arithmetic. (Slow, but portable)
4120 + * 1. Normalization
4121 + * Scale x to y in [1,4) with even powers of 2:
4122 + * find an integer k such that 1 <= (y=x*2^(2k)) < 4, then
4123 + * sqrt(x) = 2^k * sqrt(y)
4124 + * 2. Bit by bit computation
4125 + * Let q = sqrt(y) truncated to i bit after binary point (q = 1),
4126 + * i 0
4127 + * i+1 2
4128 + * s = 2*q , and y = 2 * ( y - q ). (1)
4129 + * i i i i
4131 + * To compute q from q , one checks whether
4132 + * i+1 i
4134 + * -(i+1) 2
4135 + * (q + 2 ) <= y. (2)
4136 + * i
4137 + * -(i+1)
4138 + * If (2) is false, then q = q ; otherwise q = q + 2 .
4139 + * i+1 i i+1 i
4141 + * With some algebric manipulation, it is not difficult to see
4142 + * that (2) is equivalent to
4143 + * -(i+1)
4144 + * s + 2 <= y (3)
4145 + * i i
4147 + * The advantage of (3) is that s and y can be computed by
4148 + * i i
4149 + * the following recurrence formula:
4150 + * if (3) is false
4152 + * s = s , y = y ; (4)
4153 + * i+1 i i+1 i
4155 + * otherwise,
4156 + * -i -(i+1)
4157 + * s = s + 2 , y = y - s - 2 (5)
4158 + * i+1 i i+1 i i
4160 + * One may easily use induction to prove (4) and (5).
4161 + * Note. Since the left hand side of (3) contain only i+2 bits,
4162 + * it does not necessary to do a full (53-bit) comparison
4163 + * in (3).
4164 + * 3. Final rounding
4165 + * After generating the 53 bits result, we compute one more bit.
4166 + * Together with the remainder, we can decide whether the
4167 + * result is exact, bigger than 1/2ulp, or less than 1/2ulp
4168 + * (it will never equal to 1/2ulp).
4169 + * The rounding mode can be detected by checking whether
4170 + * huge + tiny is equal to huge, and whether huge - tiny is
4171 + * equal to huge for some floating point number "huge" and "tiny".
4173 + * Special cases:
4174 + * sqrt(+-0) = +-0 ... exact
4175 + * sqrt(inf) = inf
4176 + * sqrt(-ve) = NaN ... with invalid signal
4177 + * sqrt(NaN) = NaN ... with invalid signal for signaling NaN
4179 + * Other methods : see the appended file at the end of the program below.
4180 + *---------------
4181 + */
4183 +#include "math.h"
4184 +#include "math_private.h"
4186 +#ifdef __STDC__
4187 +static const double one = 1.0, tiny=1.0e-300;
4188 +#else
4189 +static double one = 1.0, tiny=1.0e-300;
4190 +#endif
4192 +#ifdef __STDC__
4193 + double __ieee754_sqrt(double x)
4194 +#else
4195 + double __ieee754_sqrt(x)
4196 + double x;
4197 +#endif
4199 + double z;
4200 + int32_t sign = (int)0x80000000;
4201 + int32_t ix0,s0,q,m,t,i;
4202 + u_int32_t r,t1,s1,ix1,q1;
4204 + EXTRACT_WORDS(ix0,ix1,x);
4206 + /* take care of Inf and NaN */
4207 + if((ix0&0x7ff00000)==0x7ff00000) {
4208 + return x*x+x; /* sqrt(NaN)=NaN, sqrt(+inf)=+inf
4209 + sqrt(-inf)=sNaN */
4211 + /* take care of zero */
4212 + if(ix0<=0) {
4213 + if(((ix0&(~sign))|ix1)==0) return x;/* sqrt(+-0) = +-0 */
4214 + else if(ix0<0)
4215 + return (x-x)/(x-x); /* sqrt(-ve) = sNaN */
4217 + /* normalize x */
4218 + m = (ix0>>20);
4219 + if(m==0) { /* subnormal x */
4220 + while(ix0==0) {
4221 + m -= 21;
4222 + ix0 |= (ix1>>11); ix1 <<= 21;
4224 + for(i=0;(ix0&0x00100000)==0;i++) ix0<<=1;
4225 + m -= i-1;
4226 + ix0 |= (ix1>>(32-i));
4227 + ix1 <<= i;
4229 + m -= 1023; /* unbias exponent */
4230 + ix0 = (ix0&0x000fffff)|0x00100000;
4231 + if(m&1){ /* odd m, double x to make it even */
4232 + ix0 += ix0 + ((ix1&sign)>>31);
4233 + ix1 += ix1;
4235 + m >>= 1; /* m = [m/2] */
4237 + /* generate sqrt(x) bit by bit */
4238 + ix0 += ix0 + ((ix1&sign)>>31);
4239 + ix1 += ix1;
4240 + q = q1 = s0 = s1 = 0; /* [q,q1] = sqrt(x) */
4241 + r = 0x00200000; /* r = moving bit from right to left */
4243 + while(r!=0) {
4244 + t = s0+r;
4245 + if(t<=ix0) {
4246 + s0 = t+r;
4247 + ix0 -= t;
4248 + q += r;
4250 + ix0 += ix0 + ((ix1&sign)>>31);
4251 + ix1 += ix1;
4252 + r>>=1;
4255 + r = sign;
4256 + while(r!=0) {
4257 + t1 = s1+r;
4258 + t = s0;
4259 + if((t<ix0)||((t==ix0)&&(t1<=ix1))) {
4260 + s1 = t1+r;
4261 + if(((t1&sign)==sign)&&(s1&sign)==0) s0 += 1;
4262 + ix0 -= t;
4263 + if (ix1 < t1) ix0 -= 1;
4264 + ix1 -= t1;
4265 + q1 += r;
4267 + ix0 += ix0 + ((ix1&sign)>>31);
4268 + ix1 += ix1;
4269 + r>>=1;
4272 + /* use floating add to find out rounding direction */
4273 + if((ix0|ix1)!=0) {
4274 + z = one-tiny; /* trigger inexact flag */
4275 + if (z>=one) {
4276 + z = one+tiny;
4277 + if (q1==(u_int32_t)0xffffffff) { q1=0; q += 1;}
4278 + else if (z>one) {
4279 + if (q1==(u_int32_t)0xfffffffe) q+=1;
4280 + q1+=2;
4281 + } else
4282 + q1 += (q1&1);
4285 + ix0 = (q>>1)+0x3fe00000;
4286 + ix1 = q1>>1;
4287 + if ((q&1)==1) ix1 |= sign;
4288 + ix0 += (m <<20);
4289 + INSERT_WORDS(z,ix0,ix1);
4290 + return z;
4294 +Other methods (use floating-point arithmetic)
4295 +-------------
4296 +(This is a copy of a drafted paper by Prof W. Kahan
4297 +and K.C. Ng, written in May, 1986)
4299 + Two algorithms are given here to implement sqrt(x)
4300 + (IEEE double precision arithmetic) in software.
4301 + Both supply sqrt(x) correctly rounded. The first algorithm (in
4302 + Section A) uses newton iterations and involves four divisions.
4303 + The second one uses reciproot iterations to avoid division, but
4304 + requires more multiplications. Both algorithms need the ability
4305 + to chop results of arithmetic operations instead of round them,
4306 + and the INEXACT flag to indicate when an arithmetic operation
4307 + is executed exactly with no roundoff error, all part of the
4308 + standard (IEEE 754-1985). The ability to perform shift, add,
4309 + subtract and logical AND operations upon 32-bit words is needed
4310 + too, though not part of the standard.
4312 +A. sqrt(x) by Newton Iteration
4314 + (1) Initial approximation
4316 + Let x0 and x1 be the leading and the trailing 32-bit words of
4317 + a floating point number x (in IEEE double format) respectively
4319 + 1 11 52 ...widths
4320 + ------------------------------------------------------
4321 + x: |s| e | f |
4322 + ------------------------------------------------------
4323 + msb lsb msb lsb ...order
4326 + ------------------------ ------------------------
4327 + x0: |s| e | f1 | x1: | f2 |
4328 + ------------------------ ------------------------
4330 + By performing shifts and subtracts on x0 and x1 (both regarded
4331 + as integers), we obtain an 8-bit approximation of sqrt(x) as
4332 + follows.
4334 + k := (x0>>1) + 0x1ff80000;
4335 + y0 := k - T1[31&(k>>15)]. ... y ~ sqrt(x) to 8 bits
4336 + Here k is a 32-bit integer and T1[] is an integer array containing
4337 + correction terms. Now magically the floating value of y (y's
4338 + leading 32-bit word is y0, the value of its trailing word is 0)
4339 + approximates sqrt(x) to almost 8-bit.
4341 + Value of T1:
4342 + static int T1[32]= {
4343 + 0, 1024, 3062, 5746, 9193, 13348, 18162, 23592,
4344 + 29598, 36145, 43202, 50740, 58733, 67158, 75992, 85215,
4345 + 83599, 71378, 60428, 50647, 41945, 34246, 27478, 21581,
4346 + 16499, 12183, 8588, 5674, 3403, 1742, 661, 130,};
4348 + (2) Iterative refinement
4350 + Apply Heron's rule three times to y, we have y approximates
4351 + sqrt(x) to within 1 ulp (Unit in the Last Place):
4353 + y := (y+x/y)/2 ... almost 17 sig. bits
4354 + y := (y+x/y)/2 ... almost 35 sig. bits
4355 + y := y-(y-x/y)/2 ... within 1 ulp
4358 + Remark 1.
4359 + Another way to improve y to within 1 ulp is:
4361 + y := (y+x/y) ... almost 17 sig. bits to 2*sqrt(x)
4362 + y := y - 0x00100006 ... almost 18 sig. bits to sqrt(x)
4365 + (x-y )*y
4366 + y := y + 2* ---------- ...within 1 ulp
4368 + 3y + x
4371 + This formula has one division fewer than the one above; however,
4372 + it requires more multiplications and additions. Also x must be
4373 + scaled in advance to avoid spurious overflow in evaluating the
4374 + expression 3y*y+x. Hence it is not recommended uless division
4375 + is slow. If division is very slow, then one should use the
4376 + reciproot algorithm given in section B.
4378 + (3) Final adjustment
4380 + By twiddling y's last bit it is possible to force y to be
4381 + correctly rounded according to the prevailing rounding mode
4382 + as follows. Let r and i be copies of the rounding mode and
4383 + inexact flag before entering the square root program. Also we
4384 + use the expression y+-ulp for the next representable floating
4385 + numbers (up and down) of y. Note that y+-ulp = either fixed
4386 + point y+-1, or multiply y by nextafter(1,+-inf) in chopped
4387 + mode.
4389 + I := FALSE; ... reset INEXACT flag I
4390 + R := RZ; ... set rounding mode to round-toward-zero
4391 + z := x/y; ... chopped quotient, possibly inexact
4392 + If(not I) then { ... if the quotient is exact
4393 + if(z=y) {
4394 + I := i; ... restore inexact flag
4395 + R := r; ... restore rounded mode
4396 + return sqrt(x):=y.
4397 + } else {
4398 + z := z - ulp; ... special rounding
4401 + i := TRUE; ... sqrt(x) is inexact
4402 + If (r=RN) then z=z+ulp ... rounded-to-nearest
4403 + If (r=RP) then { ... round-toward-+inf
4404 + y = y+ulp; z=z+ulp;
4406 + y := y+z; ... chopped sum
4407 + y0:=y0-0x00100000; ... y := y/2 is correctly rounded.
4408 + I := i; ... restore inexact flag
4409 + R := r; ... restore rounded mode
4410 + return sqrt(x):=y.
4412 + (4) Special cases
4414 + Square root of +inf, +-0, or NaN is itself;
4415 + Square root of a negative number is NaN with invalid signal.
4418 +B. sqrt(x) by Reciproot Iteration
4420 + (1) Initial approximation
4422 + Let x0 and x1 be the leading and the trailing 32-bit words of
4423 + a floating point number x (in IEEE double format) respectively
4424 + (see section A). By performing shifs and subtracts on x0 and y0,
4425 + we obtain a 7.8-bit approximation of 1/sqrt(x) as follows.
4427 + k := 0x5fe80000 - (x0>>1);
4428 + y0:= k - T2[63&(k>>14)]. ... y ~ 1/sqrt(x) to 7.8 bits
4430 + Here k is a 32-bit integer and T2[] is an integer array
4431 + containing correction terms. Now magically the floating
4432 + value of y (y's leading 32-bit word is y0, the value of
4433 + its trailing word y1 is set to zero) approximates 1/sqrt(x)
4434 + to almost 7.8-bit.
4436 + Value of T2:
4437 + static int T2[64]= {
4438 + 0x1500, 0x2ef8, 0x4d67, 0x6b02, 0x87be, 0xa395, 0xbe7a, 0xd866,
4439 + 0xf14a, 0x1091b,0x11fcd,0x13552,0x14999,0x15c98,0x16e34,0x17e5f,
4440 + 0x18d03,0x19a01,0x1a545,0x1ae8a,0x1b5c4,0x1bb01,0x1bfde,0x1c28d,
4441 + 0x1c2de,0x1c0db,0x1ba73,0x1b11c,0x1a4b5,0x1953d,0x18266,0x16be0,
4442 + 0x1683e,0x179d8,0x18a4d,0x19992,0x1a789,0x1b445,0x1bf61,0x1c989,
4443 + 0x1d16d,0x1d77b,0x1dddf,0x1e2ad,0x1e5bf,0x1e6e8,0x1e654,0x1e3cd,
4444 + 0x1df2a,0x1d635,0x1cb16,0x1be2c,0x1ae4e,0x19bde,0x1868e,0x16e2e,
4445 + 0x1527f,0x1334a,0x11051,0xe951, 0xbe01, 0x8e0d, 0x5924, 0x1edd,};
4447 + (2) Iterative refinement
4449 + Apply Reciproot iteration three times to y and multiply the
4450 + result by x to get an approximation z that matches sqrt(x)
4451 + to about 1 ulp. To be exact, we will have
4452 + -1ulp < sqrt(x)-z<1.0625ulp.
4454 + ... set rounding mode to Round-to-nearest
4455 + y := y*(1.5-0.5*x*y*y) ... almost 15 sig. bits to 1/sqrt(x)
4456 + y := y*((1.5-2^-30)+0.5*x*y*y)... about 29 sig. bits to 1/sqrt(x)
4457 + ... special arrangement for better accuracy
4458 + z := x*y ... 29 bits to sqrt(x), with z*y<1
4459 + z := z + 0.5*z*(1-z*y) ... about 1 ulp to sqrt(x)
4461 + Remark 2. The constant 1.5-2^-30 is chosen to bias the error so that
4462 + (a) the term z*y in the final iteration is always less than 1;
4463 + (b) the error in the final result is biased upward so that
4464 + -1 ulp < sqrt(x) - z < 1.0625 ulp
4465 + instead of |sqrt(x)-z|<1.03125ulp.
4467 + (3) Final adjustment
4469 + By twiddling y's last bit it is possible to force y to be
4470 + correctly rounded according to the prevailing rounding mode
4471 + as follows. Let r and i be copies of the rounding mode and
4472 + inexact flag before entering the square root program. Also we
4473 + use the expression y+-ulp for the next representable floating
4474 + numbers (up and down) of y. Note that y+-ulp = either fixed
4475 + point y+-1, or multiply y by nextafter(1,+-inf) in chopped
4476 + mode.
4478 + R := RZ; ... set rounding mode to round-toward-zero
4479 + switch(r) {
4480 + case RN: ... round-to-nearest
4481 + if(x<= z*(z-ulp)...chopped) z = z - ulp; else
4482 + if(x<= z*(z+ulp)...chopped) z = z; else z = z+ulp;
4483 + break;
4484 + case RZ:case RM: ... round-to-zero or round-to--inf
4485 + R:=RP; ... reset rounding mod to round-to-+inf
4486 + if(x<z*z ... rounded up) z = z - ulp; else
4487 + if(x>=(z+ulp)*(z+ulp) ...rounded up) z = z+ulp;
4488 + break;
4489 + case RP: ... round-to-+inf
4490 + if(x>(z+ulp)*(z+ulp)...chopped) z = z+2*ulp; else
4491 + if(x>z*z ...chopped) z = z+ulp;
4492 + break;
4495 + Remark 3. The above comparisons can be done in fixed point. For
4496 + example, to compare x and w=z*z chopped, it suffices to compare
4497 + x1 and w1 (the trailing parts of x and w), regarding them as
4498 + two's complement integers.
4500 + ...Is z an exact square root?
4501 + To determine whether z is an exact square root of x, let z1 be the
4502 + trailing part of z, and also let x0 and x1 be the leading and
4503 + trailing parts of x.
4505 + If ((z1&0x03ffffff)!=0) ... not exact if trailing 26 bits of z!=0
4506 + I := 1; ... Raise Inexact flag: z is not exact
4507 + else {
4508 + j := 1 - [(x0>>20)&1] ... j = logb(x) mod 2
4509 + k := z1 >> 26; ... get z's 25-th and 26-th
4510 + fraction bits
4511 + I := i or (k&j) or ((k&(j+j+1))!=(x1&3));
4513 + R:= r ... restore rounded mode
4514 + return sqrt(x):=z.
4516 + If multiplication is cheaper then the foregoing red tape, the
4517 + Inexact flag can be evaluated by
4519 + I := i;
4520 + I := (z*z!=x) or I.
4522 + Note that z*z can overwrite I; this value must be sensed if it is
4523 + True.
4525 + Remark 4. If z*z = x exactly, then bit 25 to bit 0 of z1 must be
4526 + zero.
4528 + --------------------
4529 + z1: | f2 |
4530 + --------------------
4531 + bit 31 bit 0
4533 + Further more, bit 27 and 26 of z1, bit 0 and 1 of x1, and the odd
4534 + or even of logb(x) have the following relations:
4536 + -------------------------------------------------
4537 + bit 27,26 of z1 bit 1,0 of x1 logb(x)
4538 + -------------------------------------------------
4539 + 00 00 odd and even
4540 + 01 01 even
4541 + 10 10 odd
4542 + 10 00 even
4543 + 11 01 even
4544 + -------------------------------------------------
4546 + (4) Special cases (see (4) of Section A).
4548 + */
4550 diff -urN dietlibc-0.30/libm/erf.c dietlibc-0.30-libm/libm/erf.c
4551 --- dietlibc-0.30/libm/erf.c 2002-11-18 01:16:51.000000000 +0000
4552 +++ dietlibc-0.30-libm/libm/erf.c 1970-01-01 00:00:00.000000000 +0000
4553 @@ -1,95 +0,0 @@
4554 -#include "dietlibm.h"
4556 -/*--------------------------------------------------------------------------*
4558 - 1 | -x²/2
4559 -Name erf(z) = --------- | e dx
4560 - sqrt(2pi) |
4563 - oo
4564 - 1 | -x²/2
4565 - erfc(z) = -------- | e dx
4566 - sqrt(2pi) |
4569 -Usage double erf (double x);
4570 - double erfc(double x);
4572 -Prototype in math.h
4574 -Description erf(x) is the probability a normal distributed event occures
4575 - within the range [0,x]. erfc(x) is the probability a normal
4576 - distributed event occures within the range [x,oo].
4578 -Return value return their respective function value.
4580 -*---------------------------------------------------------------------------*/
4583 -/* even function in (0): Coefficients for gamma(0) */
4585 -static const double tab1 [9 + 1] = {
4586 - 0.398942280401432677926, -0.066490380066905446321, 9.97355701003581694794E-3, -1.18732821548045439878E-3, 1.15434687616155288764E-4, -9.44465625950361453450E-6, 6.65969351631665127484E-7, -4.12266741486268888409E-8, 2.27352982437280636972E-9, -1.13011716416192129505E-10
4589 -/* non even or odd function in (x), x>0: Coefficients for gamma(x), x>0 */
4591 -static const double tab2 [] [31 + 1] = {
4592 - { -0.158655253931457051468, +0.241970724519143349823, -0.120985362259571674911, 0, +0.0201642270432619458197, -4.03284540865238916394E-3, -2.01642270432619458197E-3, +7.68161030219502697887E-4, +1.20025160971797296538E-4, -8.80184513793180174807E-5, -1.86705805956129127862E-6, +7.37124220917704609315E-6, -4.72826391707080259142E-7, -4.83395817951682973566E-7, +6.57036391970156141055E-8, +2.5544260402922190768E-8, -5.4292285616752144141E-9, -1.08932444506260820153E-9, +3.44399256708718202774E-10, +3.6021429664641554881E-11, -1.81147204852239925966E-11, -7.66935128389784976374E-13, +8.19047721646461768154E-13, -3.78144699611990981391E-15, -3.24856460059989147863E-14, +1.44438130842455313227E-15, +1.14391687912824634892E-15, -9.38053726039148625184E-17, -3.59908648108845288945E-17, +4.36020846676166022246E-18, +1.01298640134330880603E-18, -1.68640470512244526894E-19 },
4593 - { -0.0227501319481792072104, +0.0539909665131880519553, -0.0539909665131880519553, +0.0269954832565940259776, -4.49924720943233766301E-3, -2.24962360471616883129E-3, +1.34977416282970129877E-3, -1.17837426913704081544E-4, -1.15159303574756261652E-4, +3.70473728554448438507E-5, +2.82690796888936559912E-6, -3.54513195524355369855E-6, +3.76695631261094890352E-7, +1.92024079214184701051E-7, -5.22690859049557191018E-8, -4.91799344974114749666E-9, +3.66377919234006038965E-9, -1.5981997209104676352E-10, -1.73812379171063320997E-10, +2.62403075313043113473E-11, +5.60918720760414713346E-12, -1.72126983666416144614E-12, -8.63428809787622525331E-14, +7.89441765474563834480E-14, -3.13747960081562321348E-15, -2.77519506625391157547E-15, +3.29321944203493138076E-16, +7.44375150395529134369E-17, -1.66428523299294690222E-17, -1.32735612757620496568E-18, +6.24122437514304644794E-19, +1.12471123532438919306E-21 },
4594 - { -1.3498980316300945272E-3, +4.43184841193800717687E-3, -6.64777261790701076574E-3, +5.90913121591734290293E-3, -3.32388630895350538287E-3, +1.10796210298450179421E-3, -1.10796210298450179595E-4, -8.44161602273906129349E-5, +4.35270826172482847927E-5, -6.30190085030867423515E-6, -1.9785037553294674925E-6, +1.05520200284238266374E-6, -1.13913852579575399458E-7, -4.81174572974454799623E-8, +1.78216871733806513653E-8, -5.85637697215219690327E-10, -9.29791350219350980904E-10, +1.96377023046901260016E-10, +1.58870373467897094393E-11, -1.22699105512396660364E-11, +1.08794270836433192571E-12, +3.99646995170699427940E-13, -1.01594404465456044793E-13, -3.33469605506835759271E-15, +4.46588935876766499879E-15, -4.08076707607833277747E-16, -1.17808602368979218862E-16, +2.76224909899945482352E-17, +1.09206599392049874162E-18, -1.03145418746203977253E-18, +6.79984672177279963209E-20, +2.55831283729070534712E-20 },
4595 - { -3.16712418331199212695E-5, +1.33830225764885351832E-4, -2.67660451529770703664E-4, +3.34575564412213379613E-4, -2.89965489157251595673E-4, +1.8178605666396926958E-4, -8.25286392216793003064E-5, +2.55180251904870680833E-5, -3.91665839292075186649E-6, -7.40182052221464123606E-7, +6.44220233592652481453E-7, -1.73701553397390201613E-7, +9.09595464817154590424E-9, +9.44943118114780783705E-9, -3.29957075383376125942E-9, +2.94920746951281580686E-10, +1.18744773902482360274E-10, -4.42039585809856402486E-11, +3.61422484008923382324E-12, +1.43638335494248833511E-12, -4.58476794992724591068E-13, +2.23496663226445199624E-14, +1.57839046076890756440E-14, -3.67258220998453293248E-15, -1.69716269032291432153E-17, +1.43497778353923791279E-16, -2.14499365995613073838E-17, -1.93255135682867953692E-18, +1.01377499752128183701E-18, -7.55713215369572830154E-20, -2.25510650946079103289E-20, +5.26633993110171917109E-21 },
4596 - { -2.86651571879193912033E-7, +1.48671951473429770924E-6, -3.7167987868357442731E-6, +5.9468780589371908374E-6, -6.81413110919886450076E-6, +5.92209940035828587496E-6, -4.02653201907205629582E-6, +2.17108246596119665457E-6, -9.25512396325170449452E-7, +3.03096091545533908077E-7, -6.92802772105295808398E-8, +6.69226396924248971087E-9, +2.46006252876483997508E-9, -1.41806830376639605249E-9, +3.44251040657349801884E-10, -2.6965166176434937652E-11, -1.16546962748761528049E-11, +4.91490145086991326748E-12, -7.55854519365765424197E-13, -4.53988828124843593484E-14, +4.71533558309731405623E-14, -9.17323049919073092370E-15, +4.35542982587998484108E-17, +3.71238868922011013332E-16, -7.90772907386322623053E-17, +1.58463483904927528072E-18, +2.61503941976309571331E-18, -5.40699423853895351239E-19, +6.61825040533797444037E-21, +1.68378440730394776550E-20, -3.01930850797704474581E-21, -3.80658085177617928332E-23 },
4597 - { -9.8658764503769814198E-10, +6.07588284982328549581E-9, -1.82276485494698564874E-8, +3.54426499573024987263E-8, -5.01260335110421053478E-8, +5.48348427196551516061E-8, -4.81513715848495375522E-8, +3.47446467489597046263E-8, -2.08994095347716137282E-8, +1.0554987922587771203E-8, -4.4752674615729637229E-9, +1.57746505810079893253E-9, -4.49697115294871911476E-10, +9.63210042443717269402E-11, -1.16300711402336909847E-11, -1.31070037808191623761E-12, +1.16993345829435057496E-12, -3.40636420312606285351E-13, +5.23724821541706939045E-14, +3.93541148139975862961E-16, -2.59886413069218394637E-15, +7.24729556829529838503E-16, -8.51485747763574768020E-17, -7.86503719948806184368E-18, +5.35986191777031053618E-18, -9.84873767617830925356E-19, +2.93759678710573738811E-20, +2.85458592629073152182E-20, -7.12725445137377009753E-21, +5.25419393758902871947E-22, +1.24299023131490990316E-22, -4.04419210566489645405E-23 },
4598 - { -1.27981254388583500631E-12, +9.1347204083645933588E-12, -3.19715214292760767584E-11, +7.30777632669167468738E-11, -1.22557498812224960902E-10, +1.60618833847077433236E-10, -1.71047639646627010648E-10, +1.51926349902927316213E-10, -1.14609023345779936276E-10, +7.43697341394886835864E-11, -4.18713451557949730558E-11, +2.05606050331840905587E-11, -8.82161466664564577599E-12, +3.30031395277698236679E-12, -1.06851205331295409813E-12, +2.94333808755089195146E-13, -6.64411715537625335642E-14, +1.11264855981436243262E-14, -8.52918435682649455145E-16, -2.38837813662069487819E-16, +1.23994634366691956599E-16, -3.05269770279941723219E-17, +4.34539596489459676621E-18, -5.55819387468189608390E-20, -1.56974672263484202926E-19, +4.60835492190702561464E-20, -6.61112150617493330405E-21, +7.28424268476803924831E-23, +2.09156005934313228089E-22, -5.29080328670107625978E-23, +5.61375000671507211726E-24, +3.82199410465700894394E-25 },
4599 - { -6.22096057427178413283E-16, +5.05227108353689229741E-15, -2.02090843341475691883E-14, +5.30488463771373691202E-14, -1.02729512031916810045E-13, +1.56409892294496290711E-13, -1.94849254788406146283E-13, +2.04064637342166989709E-13, -1.83187931471980616892E-13, +1.42994099344605424348E-13, -9.8111907789286062426E-14, +5.96545975367403288587E-14, -3.23370114040930933005E-14, +1.56932853967230342257E-14, -6.83548101324218922896E-15, +2.67410077774155118457E-15, -9.38313996431647887562E-16, +2.94090734842381109313E-16, -8.16448235152204729921E-17, +1.9758222496699617607E-17, -4.03590262164308783690E-18, +6.43662361965717426956E-19, -5.93446415094778572090E-20, -6.07164564350191039536E-21, +4.38906686886388095825E-21, -1.17175498170220204828E-21, +1.98482140750318604418E-22, -1.70803571702439545981E-23, -1.94600332107885234554E-24, +1.10477141319981582738E-24, -2.31975718243847439962E-25, +2.54148402104633283670E-26 },
4600 - { -1.12858840595384064928E-19, +1.02797735716689148111E-18, -4.62589810725101166456E-18, +1.37063647622252197466E-17, -3.0068337697131575822E-17, +5.2067053140503053517E-17, -7.40914680178037035E-17, +8.9062000172830588611E-17, -9.22563786210983011008E-17, +8.35975730487397716492E-17, -6.70372487553237232779E-17, +4.80088566412770650047E-17, -3.09280630297969106245E-17, +1.8026496052333452774E-17, -9.54924880090907168481E-18, +4.61362333444861021959E-18, -2.03812361224098073479E-18, +8.24578860830779678155E-19, -3.0572087552697254564E-19, +1.03827313453936543577E-19, -3.22407758977306397999E-20, +9.12052549039695437376E-21, -2.33541947993595580264E-21, +5.35339963891271164659E-22, -1.07674173853083520575E-22, +1.82413373046113374293E-23, -2.33864726317468746329E-24, +1.29928813344150027051E-25, +3.86668349205203745336E-26, -1.63203452712600670685E-26, +3.65165372186699607411E-27, -5.51243539825332137371E-28 },
4601 - { -7.61985302416052609616E-24, +7.69459862670641937159E-23, -3.84729931335320968601E-22, +1.26960877340655919637E-21, -3.10990027829384449637E-21, +6.02935924057670511377E-21, -9.6342786971886625897E-21, +1.30454744197246721374E-20, -1.52745988785284834672E-20, +1.57034665186695273938E-20, -1.43457243961336621961E-20, +1.17567385540485497556E-20, -8.7104848256363928121E-21, +5.87137214731944288587E-21, -3.61951956727412561213E-21, +2.04954715001535632502E-21, -1.06982832733527370879E-21, +5.1628428354196120786E-22, -2.30885865897937993512E-22, +9.58556229281154921137E-23, -3.69911125531027884646E-23, +1.32784897023484841369E-23, -4.43433027366044567275E-24, +1.37688611947822111040E-24, -3.96971995397574368025E-25, +1.06008163579031271153E-25, -2.61149430849477426613E-26, +5.89698164189548613154E-27, -1.20793190886658723050E-27, +2.20446342551066852143E-28, -3.46061447029252398335E-29, +4.28913922246949096952E-30 }
4604 -static const double tab3 [8] = { +1, -1, +3, -15, +105, -945, +10395, -135135.0 };
4608 - Calculated: oo
4609 - 1 | -x²/2
4610 - gauss(z) = --------- | e dx
4611 - sqrt(2pi) |
4612 - z
4614 - gauss ( 0) = 0.5
4615 - gauss ( 1) ~ 0.1586
4616 - gauss ( 2) ~ 0.02275
4617 - gauss ( 4) ~ 3.17e-5
4618 - gauss (10) ~ 7.62e-24
4619 - gauss (oo) = 0
4621 - Note: only for z>0
4623 -#include <stdio.h>
4624 -#include <math.h>
4626 -#define M_1_SQRT2PI 0.398942280401432686
4628 -static long double gauss ( double x )
4630 - unsigned int i = (unsigned int)(x + 0.5);
4631 - double y = x * x;
4633 - if ( i > 150 ) return 0.;
4634 - if ( i > 10 ) return M_1_SQRT2PI * exp (-0.5*y) / x * __poly (1./y, 7, tab3);
4635 - if ( i > 0 ) return -__poly ((x-i), 31, tab2 [i-1]);
4636 - return 0.5 - x * __poly (y, 9, tab1);
4639 -double erf ( double x )
4641 - return x < 0. ? -0.5 + gauss(-x) : 0.5 - gauss(x);
4644 -double erfc ( double x )
4646 - return x < 0. ? 1.0 - gauss(-x) : gauss(x);
4649 diff -urN dietlibc-0.30/libm/float_wrappers.c dietlibc-0.30-libm/libm/float_wrappers.c
4650 --- dietlibc-0.30/libm/float_wrappers.c 1970-01-01 00:00:00.000000000 +0000
4651 +++ dietlibc-0.30-libm/libm/float_wrappers.c 2006-06-25 11:20:09.000000000 +0000
4652 @@ -0,0 +1,563 @@
4653 +/* vi: set sw=4 ts=4: */
4655 + * Wrapper functions implementing all the float math functions
4656 + * defined by SuSv3 by actually calling the double version of
4657 + * each function and then casting the result back to a float
4658 + * to return to the user.
4660 + * Copyright (C) 2005 by Erik Andersen <andersen@uclibc.org>
4662 + * This program is free software; you can redistribute it and/or modify it
4663 + * under the terms of the GNU Library General Public License as published by
4664 + * the Free Software Foundation; either version 2 of the License, or (at your
4665 + * option) any later version.
4667 + * This program is distributed in the hope that it will be useful, but WITHOUT
4668 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4669 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
4670 + * for more details.
4672 + * You should have received a copy of the GNU Library General Public License
4673 + * along with this program; if not, write to the Free Software Foundation,
4674 + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
4675 + */
4677 +#include "math.h"
4679 +/* For the time being, do _NOT_ implement these functions
4680 + * that are defined by SuSv3 */
4681 +#if 0
4682 +float exp2f(float);
4683 +float fmaf(float, float, float);
4684 +float fmaxf(float, float);
4685 +float fminf(float, float);
4686 +float fdimf(float, float);
4687 +long long llrintf(float);
4688 +long long llroundf(float);
4689 +long lroundf(float);
4690 +float log2f(float);
4691 +long lrintf(float);
4692 +float nexttowardf(float, long double);
4693 +float remquof(float, float, int *);
4694 +float roundf(float);
4695 +float scalblnf(float, long);
4696 +float truncf(float);
4697 +float tgammaf(float);
4698 +#endif
4700 +/* Implement the following, as defined by SuSv3 */
4701 +#if 0
4702 +float acosf(float);
4703 +float acoshf(float);
4704 +float asinf(float);
4705 +float asinhf(float);
4706 +float atan2f(float, float);
4707 +float atanf(float);
4708 +float atanhf(float);
4709 +float cbrtf(float);
4710 +float ceilf(float);
4711 +float copysignf(float, float);
4712 +float cosf(float);
4713 +float coshf(float);
4714 +float erfcf(float);
4715 +float erff(float);
4716 +float expf(float);
4717 +float expm1f(float);
4718 +float fabsf(float);
4719 +float floorf(float);
4720 +float fmodf(float, float);
4721 +float frexpf(float value, int *);
4722 +float hypotf(float, float);
4723 +int ilogbf(float);
4724 +float ldexpf(float, int);
4725 +float lgammaf(float);
4726 +float log10f(float);
4727 +float log1pf(float);
4728 +float logbf(float);
4729 +float logf(float);
4730 +float modff(float, float *);
4731 +float nearbyintf(float);
4732 +float nextafterf(float, float);
4733 +float powf(float, float);
4734 +float remainderf(float, float);
4735 +float rintf(float);
4736 +float scalbnf(float, int);
4737 +float sinf(float);
4738 +float sinhf(float);
4739 +float sqrtf(float);
4740 +float tanf(float);
4741 +float tanhf(float);
4742 +#endif
4744 +#ifdef L_acosf
4745 +float acosf (float x)
4747 + return (float) acos( (double)x );
4749 +#endif
4752 +#ifdef L_acoshf
4753 +float acoshf (float x)
4755 + return (float) acosh( (double)x );
4757 +#endif
4760 +#ifdef L_asinf
4761 +float asinf (float x)
4763 + return (float) asin( (double)x );
4765 +#endif
4768 +#ifdef L_asinhf
4769 +float asinhf (float x)
4771 + return (float) asinh( (double)x );
4773 +#endif
4776 +#ifdef L_atan2f
4777 +float atan2f (float x, float y)
4779 + return (float) atan2( (double)x, (double)y );
4781 +#endif
4784 +#ifdef L_atanf
4785 +float atanf (float x)
4787 + return (float) atan( (double)x );
4789 +#endif
4792 +#ifdef L_atanhf
4793 +float atanhf (float x)
4795 + return (float) atanh( (double)x );
4797 +#endif
4800 +#ifdef L_cbrtf
4801 +float cbrtf (float x)
4803 + return (float) cbrt( (double)x );
4805 +#endif
4808 +#ifdef L_ceilf
4809 +float ceilf (float x)
4811 + return (float) ceil( (double)x );
4813 +#endif
4816 +#ifdef L_copysignf
4817 +float copysignf (float x, float y)
4819 + return (float) copysign( (double)x, (double)y );
4821 +#endif
4824 +#ifdef L_cosf
4825 +float cosf (float x)
4827 + return (float) cos( (double)x );
4829 +#endif
4832 +#ifdef L_coshf
4833 +float coshf (float x)
4835 + return (float) cosh( (double)x );
4837 +#endif
4840 +#ifdef L_erfcf
4841 +float erfcf (float x)
4843 + return (float) erfc( (double)x );
4845 +#endif
4848 +#ifdef L_erff
4849 +float erff (float x)
4851 + return (float) erf( (double)x );
4853 +#endif
4856 +#if 0
4857 +#ifdef L_exp2f
4858 +float exp2f (float x)
4860 + return (float) exp2( (double)x );
4862 +#endif
4863 +#endif
4866 +#ifdef L_expf
4867 +float expf (float x)
4869 + return (float) exp( (double)x );
4871 +#endif
4874 +#ifdef L_expm1f
4875 +float expm1f (float x)
4877 + return (float) expm1( (double)x );
4879 +#endif
4882 +#ifdef L_fabsf
4883 +float fabsf (float x)
4885 + return (float) fabs( (double)x );
4887 +#endif
4890 +#if 0
4891 +#ifdef L_fdimf
4892 +float fdimf (float x, float y)
4894 + return (float) fdim( (double)x, (double)y );
4896 +#endif
4897 +#endif
4900 +#ifdef L_floorf
4901 +float floorf (float x)
4903 + return (float) floor( (double)x );
4905 +#endif
4908 +#if 0
4909 +#ifdef L_fmaf
4910 +float fmaf (float x, float y, float z)
4912 + return (float) fma( (double)x, (double)y, (double)z );
4914 +#endif
4917 +#ifdef L_fmaxf
4918 +float fmaxf (float x, float y)
4920 + return (float) fmax( (double)x, (double)y );
4922 +#endif
4925 +#ifdef L_fminf
4926 +float fminf (float x, float y)
4928 + return (float) fmin( (double)x, (double)y );
4930 +#endif
4931 +#endif
4934 +#ifdef L_fmodf
4935 +float fmodf (float x, float y)
4937 + return (float) fmod( (double)x, (double)y );
4939 +#endif
4942 +#ifdef L_frexpf
4943 +float frexpf (float x, int *exp)
4945 + return (float) frexp( (double)x, exp );
4947 +#endif
4950 +#ifdef L_hypotf
4951 +float hypotf (float x, float y)
4953 + return (float) hypot( (double)x, (double)y );
4955 +#endif
4958 +#ifdef L_ilogbf
4959 +int ilogbf (float x)
4961 + return (float) ilogb( (double)x );
4963 +#endif
4966 +#ifdef L_ldexpf
4967 +float ldexpf (float x, int exp)
4969 + return (float) ldexp( (double)x, exp );
4971 +#endif
4974 +#ifdef L_lgammaf
4975 +float lgammaf (float x)
4977 + return (float) lgamma( (double)x );
4979 +#endif
4982 +#if 0
4983 +#ifdef L_llrintf
4984 +long long llrintf (float x)
4986 + return (float) llrint( (double)x );
4988 +#endif
4991 +#ifdef L_llroundf
4992 +long long llroundf (float x)
4994 + return (float) llround( (double)x );
4996 +#endif
4997 +#endif
4999 +#ifdef L_log10f
5000 +float log10f (float x)
5002 + return (float) log10( (double)x );
5004 +#endif
5007 +#ifdef L_log1pf
5008 +float log1pf (float x)
5010 + return (float) log1p( (double)x );
5012 +#endif
5015 +#if 0
5016 +#ifdef L_log2f
5017 +float log2f (float x)
5019 + return (float) log2( (double)x );
5021 +#endif
5022 +#endif
5025 +#ifdef L_logbf
5026 +float logbf (float x)
5028 + return (float) logb( (double)x );
5030 +#endif
5033 +#ifdef L_logf
5034 +float logf (float x)
5036 + return (float) log( (double)x );
5038 +#endif
5041 +#if 0
5042 +#ifdef L_lrintf
5043 +long lrintf (float x)
5045 + return (float) lrint( (double)x );
5047 +#endif
5050 +#ifdef L_lroundf
5051 +long lroundf (float x)
5053 + return (float) lround( (double)x );
5055 +#endif
5056 +#endif
5059 +#ifdef L_modff
5060 +float modff (float x, float *iptr)
5062 + double y, result;
5063 + result = modf ( x, &y );
5064 + *iptr = (float)y;
5065 + return (float) result;
5068 +#endif
5071 +#if 0
5072 +#ifdef L_nearbyintf
5073 +float nearbyintf (float x)
5075 + return (float) nearbyint( (double)x );
5077 +#endif
5078 +#endif
5081 +#ifdef L_nextafterf
5082 +float nextafterf (float x, float y)
5084 + return (float) nextafter( (double)x, (double)y );
5086 +#endif
5089 +#if 0
5090 +#ifdef L_nexttowardf
5091 +float nexttowardf (float x, long double y)
5093 + return (float) nexttoward( (double)x, (double)y );
5095 +#endif
5096 +#endif
5098 +#ifdef L_powf
5099 +float powf (float x, float y)
5101 + return (float) pow( (double)x, (double)y );
5103 +#endif
5106 +#ifdef L_remainderf
5107 +float remainderf (float x, float y)
5109 + return (float) remainder( (double)x, (double)y );
5111 +#endif
5114 +#if 0
5115 +#ifdef L_remquof
5116 +float remquof (float x, float y, int *quo)
5118 + return (float) remquo( (double)x, (double)y, quo );
5120 +#endif
5121 +#endif
5124 +#ifdef L_rintf
5125 +float rintf (float x)
5127 + return (float) rint( (double)x );
5129 +#endif
5132 +#if 0
5133 +#ifdef L_roundf
5134 +float roundf (float x)
5136 + return (float) round( (double)x );
5138 +#endif
5141 +#ifdef L_scalblnf
5142 +float scalblnf (float x, long exp)
5144 + return (float) scalbln( (double)x, exp );
5146 +#endif
5147 +#endif
5150 +#ifdef L_scalbnf
5151 +float scalbnf (float x, int exp)
5153 + return (float) scalbn( (double)x, exp );
5155 +#endif
5158 +#ifdef L_sinf
5159 +float sinf (float x)
5161 + return (float) sin( (double)x );
5163 +#endif
5166 +#ifdef L_sinhf
5167 +float sinhf (float x)
5169 + return (float) sinh( (double)x );
5171 +#endif
5174 +#ifdef L_sqrtf
5175 +float sqrtf (float x)
5177 + return (float) sqrt( (double)x );
5179 +#endif
5182 +#ifdef L_tanf
5183 +float tanf (float x)
5185 + return (float) tan( (double)x );
5187 +#endif
5190 +#ifdef L_tanhf
5191 +float tanhf (float x)
5193 + return (float) tanh( (double)x );
5195 +#endif
5198 +#if 0
5199 +#ifdef L_tgammaf
5200 +float tgammaf (float x)
5202 + return (float) tgamma( (double)x );
5204 +#endif
5207 +#ifdef L_truncf
5208 +float truncf (float x)
5210 + return (float) trunc( (double)x );
5212 +#endif
5213 +#endif
5216 diff -urN dietlibc-0.30/libm/fp_private.h dietlibc-0.30-libm/libm/fp_private.h
5217 --- dietlibc-0.30/libm/fp_private.h 1970-01-01 00:00:00.000000000 +0000
5218 +++ dietlibc-0.30-libm/libm/fp_private.h 2006-06-25 11:20:24.000000000 +0000
5219 @@ -0,0 +1,89 @@
5220 +/*******************************************************************************
5221 +* *
5222 +* File fp_private.h, *
5223 +* All pack 4 dependencies for the MathLib elems plus some defines used *
5224 +* throughout MathLib. *
5225 +* *
5226 +* Copyright © 1991 Apple Computer, Inc. All rights reserved. *
5227 +* *
5228 +* Written by Ali Sazegari, started on October 1991, *
5229 +* *
5230 +* W A R N I N G: This routine expects a 64 bit double model. *
5231 +* *
5232 +*******************************************************************************/
5234 +#define NoException 0
5236 +/*******************************************************************************
5237 +* Values of constants. *
5238 +*******************************************************************************/
5240 +//#define SgnMask 0x8000
5241 +#define dSgnMask 0x80000000
5242 +#define sSgnMask 0x7FFFFFFF
5244 +//#define ExpMask 0x7FFF
5245 +#define dExpMask 0x7FF00000
5246 +#define sExpMask 0xFF000000
5248 + /* according to rounding BIG & SMALL are: */
5249 +#define BIG 1.1e+300 /* used to deliver ±° or largest number, */
5250 +#define SMALL 1.1e-300 /* used to deliver ±0 or smallest number. */
5251 +#define InfExp 0x7FF
5252 +#define dMaxExp 0x7FF00000
5254 +#define MaxExpP1 1024
5255 +#define MaxExp 1023
5257 +#define DenormLimit -52
5259 +//#define ManMask 0x80000000
5260 +#define dManMask 0x00080000
5262 +//#define IsItDenorm 0x80000000
5263 +#define dIsItDenorm 0x00080000
5265 +//#define xIsItSNaN 0x40000000
5266 +#define dIsItSNaN 0x00080000
5268 +#define dHighMan 0x000FFFFF
5269 +#define dFirstBitSet 0x00080000
5270 +#define BIAS 0x3FF
5272 +//#define GetSign 0x8000
5273 +#define dGetSign 0x80000000
5274 +#define sGetSign 0x80000000
5276 +//#define Infinity(x) ( x.hex.exponent & ExpMask ) == ExpMask
5277 +#define dInfinity(x) ( x.hex.high & dExpMask ) == dExpMask
5278 +#define sInfinity(x) ( ( x.hexsgl << 1 ) & sExpMask ) == sExpMask
5280 +//#define Exponent(x) x.hex.exponent & ExpMask
5281 +#define dExponent(x) x.hex.high & dExpMask
5282 +#define sExponent(x) ( ( x.hexsgl << 1 ) & sExpMask )
5284 +#define sZero(x) ( x.hexsgl & sSgnMask ) == 0
5285 +//#define Sign(x) ( x.hex.exponent & SgnMask ) == SgnMask
5287 +/*******************************************************************************
5288 +* Types used in the auxiliary functions. *
5289 +*******************************************************************************/
5291 +#include <stdint.h>
5293 +typedef struct /* Hex representation of a double. */
5295 +#if defined(__BIG_ENDIAN__)
5296 + uint32_t high;
5297 + uint32_t low;
5298 +#else
5299 + uint32_t low;
5300 + uint32_t high;
5301 +#endif
5302 + } dHexParts;
5304 +typedef union
5306 + unsigned char byties[8];
5307 + double dbl;
5308 + } DblInHex;
5309 diff -urN dietlibc-0.30/libm/fpmacros.c dietlibc-0.30-libm/libm/fpmacros.c
5310 --- dietlibc-0.30/libm/fpmacros.c 1970-01-01 00:00:00.000000000 +0000
5311 +++ dietlibc-0.30-libm/libm/fpmacros.c 2006-06-25 11:20:12.000000000 +0000
5312 @@ -0,0 +1,291 @@
5313 +/***********************************************************************
5314 +** File: fpmacros.c
5316 +** Contains: C source code for implementations of floating-point
5317 +** functions which involve float format numbers, as
5318 +** defined in header <fp.h>. In particular, this file
5319 +** contains implementations of functions
5320 +** __fpclassify(d,f), __isnormal(d,f), __isfinite(d,f),
5321 +** __isnan(d,f), and __signbit(d,f). This file targets
5322 +** PowerPC platforms.
5324 +** Written by: Robert A. Murley, Ali Sazegari
5326 +** Copyright: c 2001 by Apple Computer, Inc., all rights reserved
5328 +** Change History (most recent first):
5330 +** 07 Jul 01 ram First created from fpfloatfunc.c, fp.c,
5331 +** classify.c and sign.c in MathLib v3 Mac OS9.
5333 +***********************************************************************/
5335 +#include <features.h>
5336 +#define _GNU_SOURCE
5337 +#include <sys/types.h>
5338 +#include <math.h>
5339 +#include "math_private.h"
5340 +#include "fp_private.h"
5342 +#define SIGN_MASK 0x80000000
5343 +#define NSIGN_MASK 0x7fffffff
5344 +#define FEXP_MASK 0x7f800000
5345 +#define FFRAC_MASK 0x007fffff
5347 +/***********************************************************************
5348 + int __fpclassifyf(float x) returns the classification code of the
5349 + argument x, as defined in <fp.h>.
5351 + Exceptions: INVALID signaled if x is a signaling NaN; in this case,
5352 + the FP_QNAN code is returned.
5354 + Calls: none
5355 +***********************************************************************/
5357 +int __fpclassifyf ( float x )
5359 + unsigned int iexp;
5361 + union {
5362 + u_int32_t lval;
5363 + float fval;
5364 + } z;
5366 + z.fval = x;
5367 + iexp = z.lval & FEXP_MASK; /* isolate float exponent */
5369 + if (iexp == FEXP_MASK) { /* NaN or INF case */
5370 + if ((z.lval & 0x007fffff) == 0)
5371 + return FP_INFINITE;
5372 + return FP_NAN;
5375 + if (iexp != 0) /* normal float */
5376 + return FP_NORMAL;
5378 + if (x == 0.0)
5379 + return FP_ZERO; /* zero */
5380 + else
5381 + return FP_SUBNORMAL; /* must be subnormal */
5385 +/***********************************************************************
5386 + Function __fpclassify,
5387 + Implementation of classify of a double number for the PowerPC.
5389 + Exceptions: INVALID signaled if x is a signaling NaN; in this case,
5390 + the FP_QNAN code is returned.
5392 + Calls: none
5393 +***********************************************************************/
5395 +int __fpclassify ( double arg )
5397 + register unsigned int exponent;
5398 + union
5400 + dHexParts hex;
5401 + double dbl;
5402 + } x;
5404 + x.dbl = arg;
5406 + exponent = x.hex.high & dExpMask;
5407 + if ( exponent == dExpMask )
5409 + if ( ( ( x.hex.high & dHighMan ) | x.hex.low ) == 0 )
5410 + return FP_INFINITE;
5411 + else
5412 + return FP_NAN;
5414 + else if ( exponent != 0)
5415 + return FP_NORMAL;
5416 + else {
5417 + if ( arg == 0.0 )
5418 + return FP_ZERO;
5419 + else
5420 + return FP_SUBNORMAL;
5425 +/***********************************************************************
5426 + int __isnormalf(float x) returns nonzero if and only if x is a
5427 + normalized float number and zero otherwise.
5429 + Exceptions: INVALID is raised if x is a signaling NaN; in this case,
5430 + zero is returned.
5432 + Calls: none
5433 +***********************************************************************/
5435 +int __isnormalf ( float x )
5437 + unsigned int iexp;
5438 + union {
5439 + u_int32_t lval;
5440 + float fval;
5441 + } z;
5443 + z.fval = x;
5444 + iexp = z.lval & FEXP_MASK; /* isolate float exponent */
5445 + return ((iexp != FEXP_MASK) && (iexp != 0));
5449 +int __isnormal ( double x )
5451 + return ( __fpclassify ( x ) == FP_NORMAL );
5455 +/***********************************************************************
5456 + int __isfinitef(float x) returns nonzero if and only if x is a
5457 + finite (normal, subnormal, or zero) float number and zero otherwise.
5459 + Exceptions: INVALID is raised if x is a signaling NaN; in this case,
5460 + zero is returned.
5462 + Calls: none
5463 +***********************************************************************/
5465 +int __finitef ( float x )
5467 + union {
5468 + u_int32_t lval;
5469 + float fval;
5470 + } z;
5472 + z.fval = x;
5473 + return ((z.lval & FEXP_MASK) != FEXP_MASK);
5475 +weak_alias (__finitef, finitef)
5477 +int __finite ( double x )
5479 + return ( __fpclassify ( x ) >= FP_ZERO );
5481 +weak_alias (__finite, finite)
5484 +/***********************************************************************
5485 + int __signbitf(float x) returns nonzero if and only if the sign
5486 + bit of x is set and zero otherwise.
5488 + Exceptions: INVALID is raised if x is a signaling NaN.
5490 + Calls: none
5491 +***********************************************************************/
5493 +int __signbitf ( float x )
5495 + union {
5496 + u_int32_t lval;
5497 + float fval;
5498 + } z;
5500 + z.fval = x;
5501 + return ((z.lval & SIGN_MASK) != 0);
5505 +/***********************************************************************
5506 + Function sign of a double.
5507 + Implementation of sign bit for the PowerPC.
5509 + Calls: none
5510 +***********************************************************************/
5512 +int __signbit ( double arg )
5514 + union
5516 + dHexParts hex;
5517 + double dbl;
5518 + } x;
5519 + int sign;
5521 + x.dbl = arg;
5522 + sign = ( ( x.hex.high & dSgnMask ) == dSgnMask ) ? 1 : 0;
5523 + return sign;
5527 +/***********************************************************************
5528 +* int __isinff(float x) returns -1 if value represents negative
5529 +* infinity, 1 if value represents positive infinity,
5530 +* and 0 otherwise.
5532 +* Calls: __signbit
5533 +* +***********************************************************************/
5534 +int __isinff ( float x )
5536 + int class = __fpclassifyf(x);
5537 + if ( class == FP_INFINITE ) {
5538 + return ( (__signbitf(x)) ? -1 : 1);
5540 + return 0;
5542 +weak_alias (__isinff, isinff)
5544 +int __isinf ( double x )
5546 + int class = __fpclassify(x);
5547 + if ( class == FP_INFINITE ) {
5548 + return ( (__signbit(x)) ? -1 : 1);
5550 + return 0;
5552 +weak_alias (__isinf, isinf)
5554 +#if 0
5555 +int __isinfl ( long double x )
5557 + int class = __fpclassify(x);
5558 + if ( class == FP_INFINITE ) {
5559 + return ( (__signbit(x)) ? -1 : 1);
5561 + return 0;
5563 +weak_alias (__isinfl, isinfl);
5564 +#endif
5566 +/***********************************************************************
5567 + int __isnanf(float x) returns nonzero if and only if x is a
5568 + NaN and zero otherwise.
5570 + Exceptions: INVALID is raised if x is a signaling NaN; in this case,
5571 + nonzero is returned.
5573 + Calls: none
5574 +***********************************************************************/
5576 +int __isnanf ( float x )
5578 + union {
5579 + u_int32_t lval;
5580 + float fval;
5581 + } z;
5583 + z.fval = x;
5584 + return (((z.lval&FEXP_MASK) == FEXP_MASK) && ((z.lval&FFRAC_MASK) != 0));
5586 +weak_alias (__isnanf, isnanf);
5588 +int __isnan ( double x )
5590 + int class = __fpclassify(x);
5591 + return ( class == FP_NAN );
5593 +weak_alias (__isnan, isnan);
5595 +#if 0
5596 +int __isnanl ( long double x )
5598 + int class = __fpclassify(x);
5599 + return ( class == FP_NAN );
5601 +weak_alias (__isnanl, isnanl);
5602 +#endif
5604 diff -urN dietlibc-0.30/libm/gamma.c dietlibc-0.30-libm/libm/gamma.c
5605 --- dietlibc-0.30/libm/gamma.c 2005-03-15 08:51:23.000000000 +0000
5606 +++ dietlibc-0.30-libm/libm/gamma.c 1970-01-01 00:00:00.000000000 +0000
5607 @@ -1,115 +0,0 @@
5608 -#include "dietlibm.h"
5610 -/*--------------------------------------------------------------------------*
5612 -Name gamma, lgamma - gamma function
5614 -Usage double gamma (double x);
5615 - double lgamma(double x);
5616 - extern int signgam;
5618 -Prototype in math.h
5620 -Description gamma returns the logarithm of the absolute value of the
5621 - gamma function. So it is possible â(x) for very large x.
5622 - The sign is stored in signgam, a extern variable
5623 - overwritten during every call to gamma(). lgamma() is
5624 - a synonym for gamma().
5625 - You can calculate â(x) by the following sequence:
5627 - double gammafunction(double x)
5628 - { double y=exp(gamma(x));
5630 - return signgam ? -y : +y;
5633 -Return value gamma returns a value in range (-0.1208, +oo). For a input
5634 - value of zero, it returns +oo and errno is set to:
5636 - ERANGE Result out of range
5638 -*---------------------------------------------------------------------------*/
5640 -#include <stdlib.h>
5641 -#include <math.h>
5643 -#if defined(__powerpc__)
5644 -/* workaround http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26374 */
5645 -#define B0 + 1.0/ 6/ 1/ 2
5646 -#define B1 - 1.0/ 30/ 3/ 4
5647 -#define B2 + 1.0/ 42/ 5/ 6
5648 -#define B3 - 1.0/ 30/ 7/ 8
5649 -#define B4 + 5.0/ 66/ 9/10
5650 -#define B5 - 691.0/2730/11/12
5651 -#define B6 + 7.0/ 6/13/14
5652 -#define B7 - 3617.0/ 510/15/16
5653 -#define B8 + 43867.0/ 798/17/18
5654 -#define B9 - 174611.0/ 330/19/20
5655 -#define B10 + 854513.0/ 138/21/22
5656 -#define B11 - 236364091.0/2730/23/24
5657 -#define B12 + 8553103.0/ 6/25/26
5658 -#else
5659 -#define B0 + 1.0l/ 6/ 1/ 2
5660 -#define B1 - 1.0l/ 30/ 3/ 4
5661 -#define B2 + 1.0l/ 42/ 5/ 6
5662 -#define B3 - 1.0l/ 30/ 7/ 8
5663 -#define B4 + 5.0l/ 66/ 9/10
5664 -#define B5 - 691.0l/2730/11/12
5665 -#define B6 + 7.0l/ 6/13/14
5666 -#define B7 - 3617.0l/ 510/15/16
5667 -#define B8 + 43867.0l/ 798/17/18
5668 -#define B9 - 174611.0l/ 330/19/20
5669 -#define B10 + 854513.0l/ 138/21/22
5670 -#define B11 - 236364091.0l/2730/23/24
5671 -#define B12 + 8553103.0l/ 6/25/26
5672 -#endif
5674 -static const double coeff[] = { B0, B1, B2, B3, B4, B5, B6, B7, B8, B9, B10 };
5675 -int signgam;
5677 -#define EXPL(x) (((short *)(void *)&x)[4] & 0x7FFF)
5679 -static double logfact ( long double x )
5681 - long double z = 2. * M_PI * x;
5682 - register int e = EXPL (x);
5684 - static unsigned char list [] = { 6, 4, 3, 3, 2, 2 };
5686 - return (log(x) - 1) * x + 0.5*log(z) + __poly (1./(x*x), e<0x4003 ? 10 : (e>0x4008 ? 1 : list [e-0x4003] ), coeff) / x;
5690 -double lgamma ( double x )
5692 - register int k = floor (x);
5693 - long double w;
5694 - long double y;
5695 - long double z;
5697 - signgam = 0;
5699 - if ( k >= 7 )
5700 - return logfact (x-1);
5702 - if ( k == x )
5703 - switch (k) {
5704 - case 1 :
5705 - case 2 : return 0.000000000000000000000000000l;
5706 - case 3 : return 0.693147180559945309432805516l;
5707 - case 4 : return 1.791759469228055000858148560l;
5708 - case 5 : return 3.178053830347945619723759592l;
5709 - case 6 : return 4.787491742782045994244981560l;
5710 - default: return 1./0.; /* ignore the gcc warning, this is intentional */
5713 - z = logfact (y = x - k + 7.0 - 1);
5714 - w = 1;
5715 - for ( k = 7 - k; k--; )
5716 - w *= y, y -= 1.;
5718 - signgam = k >= 0 ? 0 : k & 1;
5719 - return z - log (w);
5722 -double gamma ( double val ) __attribute__ ((weak,alias("lgamma")));
5723 diff -urN dietlibc-0.30/libm/ipow.c dietlibc-0.30-libm/libm/ipow.c
5724 --- dietlibc-0.30/libm/ipow.c 2002-03-04 18:25:54.000000000 +0000
5725 +++ dietlibc-0.30-libm/libm/ipow.c 1970-01-01 00:00:00.000000000 +0000
5726 @@ -1,29 +0,0 @@
5727 -#define _GNU_SOURCE
5728 -#include <math.h>
5730 - * This is not standard, but often you only need such this function
5731 - * which is much shorter than the generic pow() function.
5733 - * double ipow ( double mant, int expo );
5734 - */
5736 -double ipow ( double mant, int expo )
5738 - double ret = 1.;
5739 - unsigned int e = expo; /* Some attention is necessary for expo = 2^31 */
5741 - if ( (int)e < 0 ) {
5742 - e = -e;
5743 - mant = 1./mant;
5746 - while (1) {
5747 - if ( e & 1 )
5748 - ret *= mant;
5749 - if ( (e >>= 1) == 0 )
5750 - break;
5751 - mant *= mant;
5754 - return ret;
5756 diff -urN dietlibc-0.30/libm/k_cos.c dietlibc-0.30-libm/libm/k_cos.c
5757 --- dietlibc-0.30/libm/k_cos.c 1970-01-01 00:00:00.000000000 +0000
5758 +++ dietlibc-0.30-libm/libm/k_cos.c 2006-06-25 11:20:24.000000000 +0000
5759 @@ -0,0 +1,96 @@
5760 +/* @(#)k_cos.c 5.1 93/09/24 */
5762 + * ====================================================
5763 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5765 + * Developed at SunPro, a Sun Microsystems, Inc. business.
5766 + * Permission to use, copy, modify, and distribute this
5767 + * software is freely granted, provided that this notice
5768 + * is preserved.
5769 + * ====================================================
5770 + */
5772 +#if defined(LIBM_SCCS) && !defined(lint)
5773 +static char rcsid[] = "$NetBSD: k_cos.c,v 1.8 1995/05/10 20:46:22 jtc Exp $";
5774 +#endif
5777 + * __kernel_cos( x, y )
5778 + * kernel cos function on [-pi/4, pi/4], pi/4 ~ 0.785398164
5779 + * Input x is assumed to be bounded by ~pi/4 in magnitude.
5780 + * Input y is the tail of x.
5782 + * Algorithm
5783 + * 1. Since cos(-x) = cos(x), we need only to consider positive x.
5784 + * 2. if x < 2^-27 (hx<0x3e400000 0), return 1 with inexact if x!=0.
5785 + * 3. cos(x) is approximated by a polynomial of degree 14 on
5786 + * [0,pi/4]
5787 + * 4 14
5788 + * cos(x) ~ 1 - x*x/2 + C1*x + ... + C6*x
5789 + * where the remez error is
5791 + * | 2 4 6 8 10 12 14 | -58
5792 + * |cos(x)-(1-.5*x +C1*x +C2*x +C3*x +C4*x +C5*x +C6*x )| <= 2
5793 + * | |
5795 + * 4 6 8 10 12 14
5796 + * 4. let r = C1*x +C2*x +C3*x +C4*x +C5*x +C6*x , then
5797 + * cos(x) = 1 - x*x/2 + r
5798 + * since cos(x+y) ~ cos(x) - sin(x)*y
5799 + * ~ cos(x) - x*y,
5800 + * a correction term is necessary in cos(x) and hence
5801 + * cos(x+y) = 1 - (x*x/2 - (r - x*y))
5802 + * For better accuracy when x > 0.3, let qx = |x|/4 with
5803 + * the last 32 bits mask off, and if x > 0.78125, let qx = 0.28125.
5804 + * Then
5805 + * cos(x+y) = (1-qx) - ((x*x/2-qx) - (r-x*y)).
5806 + * Note that 1-qx and (x*x/2-qx) is EXACT here, and the
5807 + * magnitude of the latter is at least a quarter of x*x/2,
5808 + * thus, reducing the rounding error in the subtraction.
5809 + */
5811 +#include "math.h"
5812 +#include "math_private.h"
5814 +#ifdef __STDC__
5815 +static const double
5816 +#else
5817 +static double
5818 +#endif
5819 +one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
5820 +C1 = 4.16666666666666019037e-02, /* 0x3FA55555, 0x5555554C */
5821 +C2 = -1.38888888888741095749e-03, /* 0xBF56C16C, 0x16C15177 */
5822 +C3 = 2.48015872894767294178e-05, /* 0x3EFA01A0, 0x19CB1590 */
5823 +C4 = -2.75573143513906633035e-07, /* 0xBE927E4F, 0x809C52AD */
5824 +C5 = 2.08757232129817482790e-09, /* 0x3E21EE9E, 0xBDB4B1C4 */
5825 +C6 = -1.13596475577881948265e-11; /* 0xBDA8FAE9, 0xBE8838D4 */
5827 +#ifdef __STDC__
5828 + double __kernel_cos(double x, double y)
5829 +#else
5830 + double __kernel_cos(x, y)
5831 + double x,y;
5832 +#endif
5834 + double a,hz,z,r,qx;
5835 + int32_t ix;
5836 + GET_HIGH_WORD(ix,x);
5837 + ix &= 0x7fffffff; /* ix = |x|'s high word*/
5838 + if(ix<0x3e400000) { /* if x < 2**27 */
5839 + if(((int)x)==0) return one; /* generate inexact */
5841 + z = x*x;
5842 + r = z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*C6)))));
5843 + if(ix < 0x3FD33333) /* if |x| < 0.3 */
5844 + return one - (0.5*z - (z*r - x*y));
5845 + else {
5846 + if(ix > 0x3fe90000) { /* x > 0.78125 */
5847 + qx = 0.28125;
5848 + } else {
5849 + INSERT_WORDS(qx,ix-0x00200000,0); /* x/4 */
5851 + hz = 0.5*z-qx;
5852 + a = one-qx;
5853 + return a - (hz - (z*r-x*y));
5856 diff -urN dietlibc-0.30/libm/k_rem_pio2.c dietlibc-0.30-libm/libm/k_rem_pio2.c
5857 --- dietlibc-0.30/libm/k_rem_pio2.c 1970-01-01 00:00:00.000000000 +0000
5858 +++ dietlibc-0.30-libm/libm/k_rem_pio2.c 2006-06-25 11:20:07.000000000 +0000
5859 @@ -0,0 +1,320 @@
5860 +/* @(#)k_rem_pio2.c 5.1 93/09/24 */
5862 + * ====================================================
5863 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5865 + * Developed at SunPro, a Sun Microsystems, Inc. business.
5866 + * Permission to use, copy, modify, and distribute this
5867 + * software is freely granted, provided that this notice
5868 + * is preserved.
5869 + * ====================================================
5870 + */
5872 +#if defined(LIBM_SCCS) && !defined(lint)
5873 +static char rcsid[] = "$NetBSD: k_rem_pio2.c,v 1.7 1995/05/10 20:46:25 jtc Exp $";
5874 +#endif
5877 + * __kernel_rem_pio2(x,y,e0,nx,prec,ipio2)
5878 + * double x[],y[]; int e0,nx,prec; int ipio2[];
5880 + * __kernel_rem_pio2 return the last three digits of N with
5881 + * y = x - N*pi/2
5882 + * so that |y| < pi/2.
5884 + * The method is to compute the integer (mod 8) and fraction parts of
5885 + * (2/pi)*x without doing the full multiplication. In general we
5886 + * skip the part of the product that are known to be a huge integer (
5887 + * more accurately, = 0 mod 8 ). Thus the number of operations are
5888 + * independent of the exponent of the input.
5890 + * (2/pi) is represented by an array of 24-bit integers in ipio2[].
5892 + * Input parameters:
5893 + * x[] The input value (must be positive) is broken into nx
5894 + * pieces of 24-bit integers in double precision format.
5895 + * x[i] will be the i-th 24 bit of x. The scaled exponent
5896 + * of x[0] is given in input parameter e0 (i.e., x[0]*2^e0
5897 + * match x's up to 24 bits.
5899 + * Example of breaking a double positive z into x[0]+x[1]+x[2]:
5900 + * e0 = ilogb(z)-23
5901 + * z = scalbn(z,-e0)
5902 + * for i = 0,1,2
5903 + * x[i] = floor(z)
5904 + * z = (z-x[i])*2**24
5907 + * y[] ouput result in an array of double precision numbers.
5908 + * The dimension of y[] is:
5909 + * 24-bit precision 1
5910 + * 53-bit precision 2
5911 + * 64-bit precision 2
5912 + * 113-bit precision 3
5913 + * The actual value is the sum of them. Thus for 113-bit
5914 + * precison, one may have to do something like:
5916 + * long double t,w,r_head, r_tail;
5917 + * t = (long double)y[2] + (long double)y[1];
5918 + * w = (long double)y[0];
5919 + * r_head = t+w;
5920 + * r_tail = w - (r_head - t);
5922 + * e0 The exponent of x[0]
5924 + * nx dimension of x[]
5926 + * prec an integer indicating the precision:
5927 + * 0 24 bits (single)
5928 + * 1 53 bits (double)
5929 + * 2 64 bits (extended)
5930 + * 3 113 bits (quad)
5932 + * ipio2[]
5933 + * integer array, contains the (24*i)-th to (24*i+23)-th
5934 + * bit of 2/pi after binary point. The corresponding
5935 + * floating value is
5937 + * ipio2[i] * 2^(-24(i+1)).
5939 + * External function:
5940 + * double scalbn(), floor();
5943 + * Here is the description of some local variables:
5945 + * jk jk+1 is the initial number of terms of ipio2[] needed
5946 + * in the computation. The recommended value is 2,3,4,
5947 + * 6 for single, double, extended,and quad.
5949 + * jz local integer variable indicating the number of
5950 + * terms of ipio2[] used.
5952 + * jx nx - 1
5954 + * jv index for pointing to the suitable ipio2[] for the
5955 + * computation. In general, we want
5956 + * ( 2^e0*x[0] * ipio2[jv-1]*2^(-24jv) )/8
5957 + * is an integer. Thus
5958 + * e0-3-24*jv >= 0 or (e0-3)/24 >= jv
5959 + * Hence jv = max(0,(e0-3)/24).
5961 + * jp jp+1 is the number of terms in PIo2[] needed, jp = jk.
5963 + * q[] double array with integral value, representing the
5964 + * 24-bits chunk of the product of x and 2/pi.
5966 + * q0 the corresponding exponent of q[0]. Note that the
5967 + * exponent for q[i] would be q0-24*i.
5969 + * PIo2[] double precision array, obtained by cutting pi/2
5970 + * into 24 bits chunks.
5972 + * f[] ipio2[] in floating point
5974 + * iq[] integer array by breaking up q[] in 24-bits chunk.
5976 + * fq[] final product of x*(2/pi) in fq[0],..,fq[jk]
5978 + * ih integer. If >0 it indicates q[] is >= 0.5, hence
5979 + * it also indicates the *sign* of the result.
5981 + */
5985 + * Constants:
5986 + * The hexadecimal values are the intended ones for the following
5987 + * constants. The decimal values may be used, provided that the
5988 + * compiler will convert from decimal to binary accurately enough
5989 + * to produce the hexadecimal values shown.
5990 + */
5992 +#include "math.h"
5993 +#include "math_private.h"
5995 +#ifdef __STDC__
5996 +static const int init_jk[] = {2,3,4,6}; /* initial value for jk */
5997 +#else
5998 +static int init_jk[] = {2,3,4,6};
5999 +#endif
6001 +#ifdef __STDC__
6002 +static const double PIo2[] = {
6003 +#else
6004 +static double PIo2[] = {
6005 +#endif
6006 + 1.57079625129699707031e+00, /* 0x3FF921FB, 0x40000000 */
6007 + 7.54978941586159635335e-08, /* 0x3E74442D, 0x00000000 */
6008 + 5.39030252995776476554e-15, /* 0x3CF84698, 0x80000000 */
6009 + 3.28200341580791294123e-22, /* 0x3B78CC51, 0x60000000 */
6010 + 1.27065575308067607349e-29, /* 0x39F01B83, 0x80000000 */
6011 + 1.22933308981111328932e-36, /* 0x387A2520, 0x40000000 */
6012 + 2.73370053816464559624e-44, /* 0x36E38222, 0x80000000 */
6013 + 2.16741683877804819444e-51, /* 0x3569F31D, 0x00000000 */
6016 +#ifdef __STDC__
6017 +static const double
6018 +#else
6019 +static double
6020 +#endif
6021 +zero = 0.0,
6022 +one = 1.0,
6023 +two24 = 1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */
6024 +twon24 = 5.96046447753906250000e-08; /* 0x3E700000, 0x00000000 */
6026 +#ifdef __STDC__
6027 + int __kernel_rem_pio2(double *x, double *y, int e0, int nx, int prec, const int32_t *ipio2)
6028 +#else
6029 + int __kernel_rem_pio2(x,y,e0,nx,prec,ipio2)
6030 + double x[], y[]; int e0,nx,prec; int32_t ipio2[];
6031 +#endif
6033 + int32_t jz,jx,jv,jp,jk,carry,n,iq[20],i,j,k,m,q0,ih;
6034 + double z,fw,f[20],fq[20],q[20];
6036 + /* initialize jk*/
6037 + jk = init_jk[prec];
6038 + jp = jk;
6040 + /* determine jx,jv,q0, note that 3>q0 */
6041 + jx = nx-1;
6042 + jv = (e0-3)/24; if(jv<0) jv=0;
6043 + q0 = e0-24*(jv+1);
6045 + /* set up f[0] to f[jx+jk] where f[jx+jk] = ipio2[jv+jk] */
6046 + j = jv-jx; m = jx+jk;
6047 + for(i=0;i<=m;i++,j++) f[i] = (j<0)? zero : (double) ipio2[j];
6049 + /* compute q[0],q[1],...q[jk] */
6050 + for (i=0;i<=jk;i++) {
6051 + for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j]; q[i] = fw;
6054 + jz = jk;
6055 +recompute:
6056 + /* distill q[] into iq[] reversingly */
6057 + for(i=0,j=jz,z=q[jz];j>0;i++,j--) {
6058 + fw = (double)((int32_t)(twon24* z));
6059 + iq[i] = (int32_t)(z-two24*fw);
6060 + z = q[j-1]+fw;
6063 + /* compute n */
6064 + z = scalbn(z,q0); /* actual value of z */
6065 + z -= 8.0*floor(z*0.125); /* trim off integer >= 8 */
6066 + n = (int32_t) z;
6067 + z -= (double)n;
6068 + ih = 0;
6069 + if(q0>0) { /* need iq[jz-1] to determine n */
6070 + i = (iq[jz-1]>>(24-q0)); n += i;
6071 + iq[jz-1] -= i<<(24-q0);
6072 + ih = iq[jz-1]>>(23-q0);
6074 + else if(q0==0) ih = iq[jz-1]>>23;
6075 + else if(z>=0.5) ih=2;
6077 + if(ih>0) { /* q > 0.5 */
6078 + n += 1; carry = 0;
6079 + for(i=0;i<jz ;i++) { /* compute 1-q */
6080 + j = iq[i];
6081 + if(carry==0) {
6082 + if(j!=0) {
6083 + carry = 1; iq[i] = 0x1000000- j;
6085 + } else iq[i] = 0xffffff - j;
6087 + if(q0>0) { /* rare case: chance is 1 in 12 */
6088 + switch(q0) {
6089 + case 1:
6090 + iq[jz-1] &= 0x7fffff; break;
6091 + case 2:
6092 + iq[jz-1] &= 0x3fffff; break;
6095 + if(ih==2) {
6096 + z = one - z;
6097 + if(carry!=0) z -= scalbn(one,q0);
6101 + /* check if recomputation is needed */
6102 + if(z==zero) {
6103 + j = 0;
6104 + for (i=jz-1;i>=jk;i--) j |= iq[i];
6105 + if(j==0) { /* need recomputation */
6106 + for(k=1;iq[jk-k]==0;k++); /* k = no. of terms needed */
6108 + for(i=jz+1;i<=jz+k;i++) { /* add q[jz+1] to q[jz+k] */
6109 + f[jx+i] = (double) ipio2[jv+i];
6110 + for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j];
6111 + q[i] = fw;
6113 + jz += k;
6114 + goto recompute;
6118 + /* chop off zero terms */
6119 + if(z==0.0) {
6120 + jz -= 1; q0 -= 24;
6121 + while(iq[jz]==0) { jz--; q0-=24;}
6122 + } else { /* break z into 24-bit if necessary */
6123 + z = scalbn(z,-q0);
6124 + if(z>=two24) {
6125 + fw = (double)((int32_t)(twon24*z));
6126 + iq[jz] = (int32_t)(z-two24*fw);
6127 + jz += 1; q0 += 24;
6128 + iq[jz] = (int32_t) fw;
6129 + } else iq[jz] = (int32_t) z ;
6132 + /* convert integer "bit" chunk to floating-point value */
6133 + fw = scalbn(one,q0);
6134 + for(i=jz;i>=0;i--) {
6135 + q[i] = fw*(double)iq[i]; fw*=twon24;
6138 + /* compute PIo2[0,...,jp]*q[jz,...,0] */
6139 + for(i=jz;i>=0;i--) {
6140 + for(fw=0.0,k=0;k<=jp&&k<=jz-i;k++) fw += PIo2[k]*q[i+k];
6141 + fq[jz-i] = fw;
6144 + /* compress fq[] into y[] */
6145 + switch(prec) {
6146 + case 0:
6147 + fw = 0.0;
6148 + for (i=jz;i>=0;i--) fw += fq[i];
6149 + y[0] = (ih==0)? fw: -fw;
6150 + break;
6151 + case 1:
6152 + case 2:
6153 + fw = 0.0;
6154 + for (i=jz;i>=0;i--) fw += fq[i];
6155 + y[0] = (ih==0)? fw: -fw;
6156 + fw = fq[0]-fw;
6157 + for (i=1;i<=jz;i++) fw += fq[i];
6158 + y[1] = (ih==0)? fw: -fw;
6159 + break;
6160 + case 3: /* painful */
6161 + for (i=jz;i>0;i--) {
6162 + fw = fq[i-1]+fq[i];
6163 + fq[i] += fq[i-1]-fw;
6164 + fq[i-1] = fw;
6166 + for (i=jz;i>1;i--) {
6167 + fw = fq[i-1]+fq[i];
6168 + fq[i] += fq[i-1]-fw;
6169 + fq[i-1] = fw;
6171 + for (fw=0.0,i=jz;i>=2;i--) fw += fq[i];
6172 + if(ih==0) {
6173 + y[0] = fq[0]; y[1] = fq[1]; y[2] = fw;
6174 + } else {
6175 + y[0] = -fq[0]; y[1] = -fq[1]; y[2] = -fw;
6178 + return n&7;
6180 diff -urN dietlibc-0.30/libm/k_sin.c dietlibc-0.30-libm/libm/k_sin.c
6181 --- dietlibc-0.30/libm/k_sin.c 1970-01-01 00:00:00.000000000 +0000
6182 +++ dietlibc-0.30-libm/libm/k_sin.c 2006-06-25 11:20:25.000000000 +0000
6183 @@ -0,0 +1,79 @@
6184 +/* @(#)k_sin.c 5.1 93/09/24 */
6186 + * ====================================================
6187 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6189 + * Developed at SunPro, a Sun Microsystems, Inc. business.
6190 + * Permission to use, copy, modify, and distribute this
6191 + * software is freely granted, provided that this notice
6192 + * is preserved.
6193 + * ====================================================
6194 + */
6196 +#if defined(LIBM_SCCS) && !defined(lint)
6197 +static char rcsid[] = "$NetBSD: k_sin.c,v 1.8 1995/05/10 20:46:31 jtc Exp $";
6198 +#endif
6200 +/* __kernel_sin( x, y, iy)
6201 + * kernel sin function on [-pi/4, pi/4], pi/4 ~ 0.7854
6202 + * Input x is assumed to be bounded by ~pi/4 in magnitude.
6203 + * Input y is the tail of x.
6204 + * Input iy indicates whether y is 0. (if iy=0, y assume to be 0).
6206 + * Algorithm
6207 + * 1. Since sin(-x) = -sin(x), we need only to consider positive x.
6208 + * 2. if x < 2^-27 (hx<0x3e400000 0), return x with inexact if x!=0.
6209 + * 3. sin(x) is approximated by a polynomial of degree 13 on
6210 + * [0,pi/4]
6211 + * 3 13
6212 + * sin(x) ~ x + S1*x + ... + S6*x
6213 + * where
6215 + * |sin(x) 2 4 6 8 10 12 | -58
6216 + * |----- - (1+S1*x +S2*x +S3*x +S4*x +S5*x +S6*x )| <= 2
6217 + * | x |
6219 + * 4. sin(x+y) = sin(x) + sin'(x')*y
6220 + * ~ sin(x) + (1-x*x/2)*y
6221 + * For better accuracy, let
6222 + * 3 2 2 2 2
6223 + * r = x *(S2+x *(S3+x *(S4+x *(S5+x *S6))))
6224 + * then 3 2
6225 + * sin(x) = x + (S1*x + (x *(r-y/2)+y))
6226 + */
6228 +#include "math.h"
6229 +#include "math_private.h"
6231 +#ifdef __STDC__
6232 +static const double
6233 +#else
6234 +static double
6235 +#endif
6236 +half = 5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */
6237 +S1 = -1.66666666666666324348e-01, /* 0xBFC55555, 0x55555549 */
6238 +S2 = 8.33333333332248946124e-03, /* 0x3F811111, 0x1110F8A6 */
6239 +S3 = -1.98412698298579493134e-04, /* 0xBF2A01A0, 0x19C161D5 */
6240 +S4 = 2.75573137070700676789e-06, /* 0x3EC71DE3, 0x57B1FE7D */
6241 +S5 = -2.50507602534068634195e-08, /* 0xBE5AE5E6, 0x8A2B9CEB */
6242 +S6 = 1.58969099521155010221e-10; /* 0x3DE5D93A, 0x5ACFD57C */
6244 +#ifdef __STDC__
6245 + double __kernel_sin(double x, double y, int iy)
6246 +#else
6247 + double __kernel_sin(x, y, iy)
6248 + double x,y; int iy; /* iy=0 if y is zero */
6249 +#endif
6251 + double z,r,v;
6252 + int32_t ix;
6253 + GET_HIGH_WORD(ix,x);
6254 + ix &= 0x7fffffff; /* high word of x */
6255 + if(ix<0x3e400000) /* |x| < 2**-27 */
6256 + {if((int)x==0) return x;} /* generate inexact */
6257 + z = x*x;
6258 + v = z*x;
6259 + r = S2+z*(S3+z*(S4+z*(S5+z*S6)));
6260 + if(iy==0) return x+v*(S1+z*r);
6261 + else return x-((z*(half*y-v*r)-y)-v*S1);
6263 diff -urN dietlibc-0.30/libm/k_standard.c dietlibc-0.30-libm/libm/k_standard.c
6264 --- dietlibc-0.30/libm/k_standard.c 1970-01-01 00:00:00.000000000 +0000
6265 +++ dietlibc-0.30-libm/libm/k_standard.c 2006-06-25 11:20:23.000000000 +0000
6266 @@ -0,0 +1,782 @@
6267 +/* @(#)k_standard.c 5.1 93/09/24 */
6269 + * ====================================================
6270 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6272 + * Developed at SunPro, a Sun Microsystems, Inc. business.
6273 + * Permission to use, copy, modify, and distribute this
6274 + * software is freely granted, provided that this notice
6275 + * is preserved.
6276 + * ====================================================
6277 + */
6279 +#if defined(LIBM_SCCS) && !defined(lint)
6280 +static char rcsid[] = "$NetBSD: k_standard.c,v 1.6 1995/05/10 20:46:35 jtc Exp $";
6281 +#endif
6283 +#include "math.h"
6284 +#include "math_private.h"
6285 +#include <errno.h>
6287 +#ifndef _USE_WRITE
6288 +#include <stdio.h> /* fputs(), stderr */
6289 +#define WRITE2(u,v) fputs(u, stderr)
6290 +#else /* !defined(_USE_WRITE) */
6291 +#include <unistd.h> /* write */
6292 +#define WRITE2(u,v) write(2, u, v)
6293 +#undef fflush
6294 +#endif /* !defined(_USE_WRITE) */
6296 +#ifdef __STDC__
6297 +static const double zero = 0.0; /* used as const */
6298 +#else
6299 +static double zero = 0.0; /* used as const */
6300 +#endif
6303 + * Standard conformance (non-IEEE) on exception cases.
6304 + * Mapping:
6305 + * 1 -- acos(|x|>1)
6306 + * 2 -- asin(|x|>1)
6307 + * 3 -- atan2(+-0,+-0)
6308 + * 4 -- hypot overflow
6309 + * 5 -- cosh overflow
6310 + * 6 -- exp overflow
6311 + * 7 -- exp underflow
6312 + * 8 -- y0(0)
6313 + * 9 -- y0(-ve)
6314 + * 10-- y1(0)
6315 + * 11-- y1(-ve)
6316 + * 12-- yn(0)
6317 + * 13-- yn(-ve)
6318 + * 14-- lgamma(finite) overflow
6319 + * 15-- lgamma(-integer)
6320 + * 16-- log(0)
6321 + * 17-- log(x<0)
6322 + * 18-- log10(0)
6323 + * 19-- log10(x<0)
6324 + * 20-- pow(0.0,0.0)
6325 + * 21-- pow(x,y) overflow
6326 + * 22-- pow(x,y) underflow
6327 + * 23-- pow(0,negative)
6328 + * 24-- pow(neg,non-integral)
6329 + * 25-- sinh(finite) overflow
6330 + * 26-- sqrt(negative)
6331 + * 27-- fmod(x,0)
6332 + * 28-- remainder(x,0)
6333 + * 29-- acosh(x<1)
6334 + * 30-- atanh(|x|>1)
6335 + * 31-- atanh(|x|=1)
6336 + * 32-- scalb overflow
6337 + * 33-- scalb underflow
6338 + * 34-- j0(|x|>X_TLOSS)
6339 + * 35-- y0(x>X_TLOSS)
6340 + * 36-- j1(|x|>X_TLOSS)
6341 + * 37-- y1(x>X_TLOSS)
6342 + * 38-- jn(|x|>X_TLOSS, n)
6343 + * 39-- yn(x>X_TLOSS, n)
6344 + * 40-- gamma(finite) overflow
6345 + * 41-- gamma(-integer)
6346 + * 42-- pow(NaN,0.0)
6347 + */
6350 +#ifdef __STDC__
6351 + double __kernel_standard(double x, double y, int type)
6352 +#else
6353 + double __kernel_standard(x,y,type)
6354 + double x,y; int type;
6355 +#endif
6357 + struct exception exc;
6358 +#ifndef HUGE_VAL /* this is the only routine that uses HUGE_VAL */
6359 +#define HUGE_VAL inf
6360 + double inf = 0.0;
6362 + SET_HIGH_WORD(inf,0x7ff00000); /* set inf to infinite */
6363 +#endif
6365 +#ifdef _USE_WRITE
6366 + (void) fflush(stdout);
6367 +#endif
6368 + exc.arg1 = x;
6369 + exc.arg2 = y;
6370 + switch(type) {
6371 + case 1:
6372 + case 101:
6373 + /* acos(|x|>1) */
6374 + exc.type = DOMAIN;
6375 + exc.name = type < 100 ? "acos" : "acosf";
6376 + exc.retval = zero;
6377 + if (_LIB_VERSION == _POSIX_)
6378 + errno = EDOM;
6379 + else if (!matherr(&exc)) {
6380 + if(_LIB_VERSION == _SVID_) {
6381 + (void) WRITE2("acos: DOMAIN error\n", 19);
6383 + errno = EDOM;
6385 + break;
6386 + case 2:
6387 + case 102:
6388 + /* asin(|x|>1) */
6389 + exc.type = DOMAIN;
6390 + exc.name = type < 100 ? "asin" : "asinf";
6391 + exc.retval = zero;
6392 + if(_LIB_VERSION == _POSIX_)
6393 + errno = EDOM;
6394 + else if (!matherr(&exc)) {
6395 + if(_LIB_VERSION == _SVID_) {
6396 + (void) WRITE2("asin: DOMAIN error\n", 19);
6398 + errno = EDOM;
6400 + break;
6401 + case 3:
6402 + case 103:
6403 + /* atan2(+-0,+-0) */
6404 + exc.arg1 = y;
6405 + exc.arg2 = x;
6406 + exc.type = DOMAIN;
6407 + exc.name = type < 100 ? "atan2" : "atan2f";
6408 + exc.retval = zero;
6409 + if(_LIB_VERSION == _POSIX_)
6410 + errno = EDOM;
6411 + else if (!matherr(&exc)) {
6412 + if(_LIB_VERSION == _SVID_) {
6413 + (void) WRITE2("atan2: DOMAIN error\n", 20);
6415 + errno = EDOM;
6417 + break;
6418 + case 4:
6419 + case 104:
6420 + /* hypot(finite,finite) overflow */
6421 + exc.type = OVERFLOW;
6422 + exc.name = type < 100 ? "hypot" : "hypotf";
6423 + if (_LIB_VERSION == _SVID_)
6424 + exc.retval = HUGE;
6425 + else
6426 + exc.retval = HUGE_VAL;
6427 + if (_LIB_VERSION == _POSIX_)
6428 + errno = ERANGE;
6429 + else if (!matherr(&exc)) {
6430 + errno = ERANGE;
6432 + break;
6433 + case 5:
6434 + case 105:
6435 + /* cosh(finite) overflow */
6436 + exc.type = OVERFLOW;
6437 + exc.name = type < 100 ? "cosh" : "coshf";
6438 + if (_LIB_VERSION == _SVID_)
6439 + exc.retval = HUGE;
6440 + else
6441 + exc.retval = HUGE_VAL;
6442 + if (_LIB_VERSION == _POSIX_)
6443 + errno = ERANGE;
6444 + else if (!matherr(&exc)) {
6445 + errno = ERANGE;
6447 + break;
6448 + case 6:
6449 + case 106:
6450 + /* exp(finite) overflow */
6451 + exc.type = OVERFLOW;
6452 + exc.name = type < 100 ? "exp" : "expf";
6453 + if (_LIB_VERSION == _SVID_)
6454 + exc.retval = HUGE;
6455 + else
6456 + exc.retval = HUGE_VAL;
6457 + if (_LIB_VERSION == _POSIX_)
6458 + errno = ERANGE;
6459 + else if (!matherr(&exc)) {
6460 + errno = ERANGE;
6462 + break;
6463 + case 7:
6464 + case 107:
6465 + /* exp(finite) underflow */
6466 + exc.type = UNDERFLOW;
6467 + exc.name = type < 100 ? "exp" : "expf";
6468 + exc.retval = zero;
6469 + if (_LIB_VERSION == _POSIX_)
6470 + errno = ERANGE;
6471 + else if (!matherr(&exc)) {
6472 + errno = ERANGE;
6474 + break;
6475 + case 8:
6476 + case 108:
6477 + /* y0(0) = -inf */
6478 + exc.type = DOMAIN; /* should be SING for IEEE */
6479 + exc.name = type < 100 ? "y0" : "y0f";
6480 + if (_LIB_VERSION == _SVID_)
6481 + exc.retval = -HUGE;
6482 + else
6483 + exc.retval = -HUGE_VAL;
6484 + if (_LIB_VERSION == _POSIX_)
6485 + errno = EDOM;
6486 + else if (!matherr(&exc)) {
6487 + if (_LIB_VERSION == _SVID_) {
6488 + (void) WRITE2("y0: DOMAIN error\n", 17);
6490 + errno = EDOM;
6492 + break;
6493 + case 9:
6494 + case 109:
6495 + /* y0(x<0) = NaN */
6496 + exc.type = DOMAIN;
6497 + exc.name = type < 100 ? "y0" : "y0f";
6498 + if (_LIB_VERSION == _SVID_)
6499 + exc.retval = -HUGE;
6500 + else
6501 + exc.retval = -HUGE_VAL;
6502 + if (_LIB_VERSION == _POSIX_)
6503 + errno = EDOM;
6504 + else if (!matherr(&exc)) {
6505 + if (_LIB_VERSION == _SVID_) {
6506 + (void) WRITE2("y0: DOMAIN error\n", 17);
6508 + errno = EDOM;
6510 + break;
6511 + case 10:
6512 + case 110:
6513 + /* y1(0) = -inf */
6514 + exc.type = DOMAIN; /* should be SING for IEEE */
6515 + exc.name = type < 100 ? "y1" : "y1f";
6516 + if (_LIB_VERSION == _SVID_)
6517 + exc.retval = -HUGE;
6518 + else
6519 + exc.retval = -HUGE_VAL;
6520 + if (_LIB_VERSION == _POSIX_)
6521 + errno = EDOM;
6522 + else if (!matherr(&exc)) {
6523 + if (_LIB_VERSION == _SVID_) {
6524 + (void) WRITE2("y1: DOMAIN error\n", 17);
6526 + errno = EDOM;
6528 + break;
6529 + case 11:
6530 + case 111:
6531 + /* y1(x<0) = NaN */
6532 + exc.type = DOMAIN;
6533 + exc.name = type < 100 ? "y1" : "y1f";
6534 + if (_LIB_VERSION == _SVID_)
6535 + exc.retval = -HUGE;
6536 + else
6537 + exc.retval = -HUGE_VAL;
6538 + if (_LIB_VERSION == _POSIX_)
6539 + errno = EDOM;
6540 + else if (!matherr(&exc)) {
6541 + if (_LIB_VERSION == _SVID_) {
6542 + (void) WRITE2("y1: DOMAIN error\n", 17);
6544 + errno = EDOM;
6546 + break;
6547 + case 12:
6548 + case 112:
6549 + /* yn(n,0) = -inf */
6550 + exc.type = DOMAIN; /* should be SING for IEEE */
6551 + exc.name = type < 100 ? "yn" : "ynf";
6552 + if (_LIB_VERSION == _SVID_)
6553 + exc.retval = -HUGE;
6554 + else
6555 + exc.retval = -HUGE_VAL;
6556 + if (_LIB_VERSION == _POSIX_)
6557 + errno = EDOM;
6558 + else if (!matherr(&exc)) {
6559 + if (_LIB_VERSION == _SVID_) {
6560 + (void) WRITE2("yn: DOMAIN error\n", 17);
6562 + errno = EDOM;
6564 + break;
6565 + case 13:
6566 + case 113:
6567 + /* yn(x<0) = NaN */
6568 + exc.type = DOMAIN;
6569 + exc.name = type < 100 ? "yn" : "ynf";
6570 + if (_LIB_VERSION == _SVID_)
6571 + exc.retval = -HUGE;
6572 + else
6573 + exc.retval = -HUGE_VAL;
6574 + if (_LIB_VERSION == _POSIX_)
6575 + errno = EDOM;
6576 + else if (!matherr(&exc)) {
6577 + if (_LIB_VERSION == _SVID_) {
6578 + (void) WRITE2("yn: DOMAIN error\n", 17);
6580 + errno = EDOM;
6582 + break;
6583 + case 14:
6584 + case 114:
6585 + /* lgamma(finite) overflow */
6586 + exc.type = OVERFLOW;
6587 + exc.name = type < 100 ? "lgamma" : "lgammaf";
6588 + if (_LIB_VERSION == _SVID_)
6589 + exc.retval = HUGE;
6590 + else
6591 + exc.retval = HUGE_VAL;
6592 + if (_LIB_VERSION == _POSIX_)
6593 + errno = ERANGE;
6594 + else if (!matherr(&exc)) {
6595 + errno = ERANGE;
6597 + break;
6598 + case 15:
6599 + case 115:
6600 + /* lgamma(-integer) or lgamma(0) */
6601 + exc.type = SING;
6602 + exc.name = type < 100 ? "lgamma" : "lgammaf";
6603 + if (_LIB_VERSION == _SVID_)
6604 + exc.retval = HUGE;
6605 + else
6606 + exc.retval = HUGE_VAL;
6607 + if (_LIB_VERSION == _POSIX_)
6608 + errno = EDOM;
6609 + else if (!matherr(&exc)) {
6610 + if (_LIB_VERSION == _SVID_) {
6611 + (void) WRITE2("lgamma: SING error\n", 19);
6613 + errno = EDOM;
6615 + break;
6616 + case 16:
6617 + case 116:
6618 + /* log(0) */
6619 + exc.type = SING;
6620 + exc.name = type < 100 ? "log" : "logf";
6621 + if (_LIB_VERSION == _SVID_)
6622 + exc.retval = -HUGE;
6623 + else
6624 + exc.retval = -HUGE_VAL;
6625 + if (_LIB_VERSION == _POSIX_)
6626 + errno = ERANGE;
6627 + else if (!matherr(&exc)) {
6628 + if (_LIB_VERSION == _SVID_) {
6629 + (void) WRITE2("log: SING error\n", 16);
6631 + errno = EDOM;
6633 + break;
6634 + case 17:
6635 + case 117:
6636 + /* log(x<0) */
6637 + exc.type = DOMAIN;
6638 + exc.name = type < 100 ? "log" : "logf";
6639 + if (_LIB_VERSION == _SVID_)
6640 + exc.retval = -HUGE;
6641 + else
6642 + exc.retval = -HUGE_VAL;
6643 + if (_LIB_VERSION == _POSIX_)
6644 + errno = EDOM;
6645 + else if (!matherr(&exc)) {
6646 + if (_LIB_VERSION == _SVID_) {
6647 + (void) WRITE2("log: DOMAIN error\n", 18);
6649 + errno = EDOM;
6651 + break;
6652 + case 18:
6653 + case 118:
6654 + /* log10(0) */
6655 + exc.type = SING;
6656 + exc.name = type < 100 ? "log10" : "log10f";
6657 + if (_LIB_VERSION == _SVID_)
6658 + exc.retval = -HUGE;
6659 + else
6660 + exc.retval = -HUGE_VAL;
6661 + if (_LIB_VERSION == _POSIX_)
6662 + errno = ERANGE;
6663 + else if (!matherr(&exc)) {
6664 + if (_LIB_VERSION == _SVID_) {
6665 + (void) WRITE2("log10: SING error\n", 18);
6667 + errno = EDOM;
6669 + break;
6670 + case 19:
6671 + case 119:
6672 + /* log10(x<0) */
6673 + exc.type = DOMAIN;
6674 + exc.name = type < 100 ? "log10" : "log10f";
6675 + if (_LIB_VERSION == _SVID_)
6676 + exc.retval = -HUGE;
6677 + else
6678 + exc.retval = -HUGE_VAL;
6679 + if (_LIB_VERSION == _POSIX_)
6680 + errno = EDOM;
6681 + else if (!matherr(&exc)) {
6682 + if (_LIB_VERSION == _SVID_) {
6683 + (void) WRITE2("log10: DOMAIN error\n", 20);
6685 + errno = EDOM;
6687 + break;
6688 + case 20:
6689 + case 120:
6690 + /* pow(0.0,0.0) */
6691 + /* error only if _LIB_VERSION == _SVID_ */
6692 + exc.type = DOMAIN;
6693 + exc.name = type < 100 ? "pow" : "powf";
6694 + exc.retval = zero;
6695 + if (_LIB_VERSION != _SVID_) exc.retval = 1.0;
6696 + else if (!matherr(&exc)) {
6697 + (void) WRITE2("pow(0,0): DOMAIN error\n", 23);
6698 + errno = EDOM;
6700 + break;
6701 + case 21:
6702 + case 121:
6703 + /* pow(x,y) overflow */
6704 + exc.type = OVERFLOW;
6705 + exc.name = type < 100 ? "pow" : "powf";
6706 + if (_LIB_VERSION == _SVID_) {
6707 + exc.retval = HUGE;
6708 + y *= 0.5;
6709 + if(x<zero&&rint(y)!=y) exc.retval = -HUGE;
6710 + } else {
6711 + exc.retval = HUGE_VAL;
6712 + y *= 0.5;
6713 + if(x<zero&&rint(y)!=y) exc.retval = -HUGE_VAL;
6715 + if (_LIB_VERSION == _POSIX_)
6716 + errno = ERANGE;
6717 + else if (!matherr(&exc)) {
6718 + errno = ERANGE;
6720 + break;
6721 + case 22:
6722 + case 122:
6723 + /* pow(x,y) underflow */
6724 + exc.type = UNDERFLOW;
6725 + exc.name = type < 100 ? "pow" : "powf";
6726 + exc.retval = zero;
6727 + if (_LIB_VERSION == _POSIX_)
6728 + errno = ERANGE;
6729 + else if (!matherr(&exc)) {
6730 + errno = ERANGE;
6732 + break;
6733 + case 23:
6734 + case 123:
6735 + /* 0**neg */
6736 + exc.type = DOMAIN;
6737 + exc.name = type < 100 ? "pow" : "powf";
6738 + if (_LIB_VERSION == _SVID_)
6739 + exc.retval = zero;
6740 + else
6741 + exc.retval = -HUGE_VAL;
6742 + if (_LIB_VERSION == _POSIX_)
6743 + errno = EDOM;
6744 + else if (!matherr(&exc)) {
6745 + if (_LIB_VERSION == _SVID_) {
6746 + (void) WRITE2("pow(0,neg): DOMAIN error\n", 25);
6748 + errno = EDOM;
6750 + break;
6751 + case 24:
6752 + case 124:
6753 + /* neg**non-integral */
6754 + exc.type = DOMAIN;
6755 + exc.name = type < 100 ? "pow" : "powf";
6756 + if (_LIB_VERSION == _SVID_)
6757 + exc.retval = zero;
6758 + else
6759 + exc.retval = zero/zero; /* X/Open allow NaN */
6760 + if (_LIB_VERSION == _POSIX_)
6761 + errno = EDOM;
6762 + else if (!matherr(&exc)) {
6763 + if (_LIB_VERSION == _SVID_) {
6764 + (void) WRITE2("neg**non-integral: DOMAIN error\n", 32);
6766 + errno = EDOM;
6768 + break;
6769 + case 25:
6770 + case 125:
6771 + /* sinh(finite) overflow */
6772 + exc.type = OVERFLOW;
6773 + exc.name = type < 100 ? "sinh" : "sinhf";
6774 + if (_LIB_VERSION == _SVID_)
6775 + exc.retval = ( (x>zero) ? HUGE : -HUGE);
6776 + else
6777 + exc.retval = ( (x>zero) ? HUGE_VAL : -HUGE_VAL);
6778 + if (_LIB_VERSION == _POSIX_)
6779 + errno = ERANGE;
6780 + else if (!matherr(&exc)) {
6781 + errno = ERANGE;
6783 + break;
6784 + case 26:
6785 + case 126:
6786 + /* sqrt(x<0) */
6787 + exc.type = DOMAIN;
6788 + exc.name = type < 100 ? "sqrt" : "sqrtf";
6789 + if (_LIB_VERSION == _SVID_)
6790 + exc.retval = zero;
6791 + else
6792 + exc.retval = zero/zero;
6793 + if (_LIB_VERSION == _POSIX_)
6794 + errno = EDOM;
6795 + else if (!matherr(&exc)) {
6796 + if (_LIB_VERSION == _SVID_) {
6797 + (void) WRITE2("sqrt: DOMAIN error\n", 19);
6799 + errno = EDOM;
6801 + break;
6802 + case 27:
6803 + case 127:
6804 + /* fmod(x,0) */
6805 + exc.type = DOMAIN;
6806 + exc.name = type < 100 ? "fmod" : "fmodf";
6807 + if (_LIB_VERSION == _SVID_)
6808 + exc.retval = x;
6809 + else
6810 + exc.retval = zero/zero;
6811 + if (_LIB_VERSION == _POSIX_)
6812 + errno = EDOM;
6813 + else if (!matherr(&exc)) {
6814 + if (_LIB_VERSION == _SVID_) {
6815 + (void) WRITE2("fmod: DOMAIN error\n", 20);
6817 + errno = EDOM;
6819 + break;
6820 + case 28:
6821 + case 128:
6822 + /* remainder(x,0) */
6823 + exc.type = DOMAIN;
6824 + exc.name = type < 100 ? "remainder" : "remainderf";
6825 + exc.retval = zero/zero;
6826 + if (_LIB_VERSION == _POSIX_)
6827 + errno = EDOM;
6828 + else if (!matherr(&exc)) {
6829 + if (_LIB_VERSION == _SVID_) {
6830 + (void) WRITE2("remainder: DOMAIN error\n", 24);
6832 + errno = EDOM;
6834 + break;
6835 + case 29:
6836 + case 129:
6837 + /* acosh(x<1) */
6838 + exc.type = DOMAIN;
6839 + exc.name = type < 100 ? "acosh" : "acoshf";
6840 + exc.retval = zero/zero;
6841 + if (_LIB_VERSION == _POSIX_)
6842 + errno = EDOM;
6843 + else if (!matherr(&exc)) {
6844 + if (_LIB_VERSION == _SVID_) {
6845 + (void) WRITE2("acosh: DOMAIN error\n", 20);
6847 + errno = EDOM;
6849 + break;
6850 + case 30:
6851 + case 130:
6852 + /* atanh(|x|>1) */
6853 + exc.type = DOMAIN;
6854 + exc.name = type < 100 ? "atanh" : "atanhf";
6855 + exc.retval = zero/zero;
6856 + if (_LIB_VERSION == _POSIX_)
6857 + errno = EDOM;
6858 + else if (!matherr(&exc)) {
6859 + if (_LIB_VERSION == _SVID_) {
6860 + (void) WRITE2("atanh: DOMAIN error\n", 20);
6862 + errno = EDOM;
6864 + break;
6865 + case 31:
6866 + case 131:
6867 + /* atanh(|x|=1) */
6868 + exc.type = SING;
6869 + exc.name = type < 100 ? "atanh" : "atanhf";
6870 + exc.retval = x/zero; /* sign(x)*inf */
6871 + if (_LIB_VERSION == _POSIX_)
6872 + errno = EDOM;
6873 + else if (!matherr(&exc)) {
6874 + if (_LIB_VERSION == _SVID_) {
6875 + (void) WRITE2("atanh: SING error\n", 18);
6877 + errno = EDOM;
6879 + break;
6880 + case 32:
6881 + case 132:
6882 + /* scalb overflow; SVID also returns +-HUGE_VAL */
6883 + exc.type = OVERFLOW;
6884 + exc.name = type < 100 ? "scalb" : "scalbf";
6885 + exc.retval = x > zero ? HUGE_VAL : -HUGE_VAL;
6886 + if (_LIB_VERSION == _POSIX_)
6887 + errno = ERANGE;
6888 + else if (!matherr(&exc)) {
6889 + errno = ERANGE;
6891 + break;
6892 + case 33:
6893 + case 133:
6894 + /* scalb underflow */
6895 + exc.type = UNDERFLOW;
6896 + exc.name = type < 100 ? "scalb" : "scalbf";
6897 + exc.retval = copysign(zero,x);
6898 + if (_LIB_VERSION == _POSIX_)
6899 + errno = ERANGE;
6900 + else if (!matherr(&exc)) {
6901 + errno = ERANGE;
6903 + break;
6904 + case 34:
6905 + case 134:
6906 + /* j0(|x|>X_TLOSS) */
6907 + exc.type = TLOSS;
6908 + exc.name = type < 100 ? "j0" : "j0f";
6909 + exc.retval = zero;
6910 + if (_LIB_VERSION == _POSIX_)
6911 + errno = ERANGE;
6912 + else if (!matherr(&exc)) {
6913 + if (_LIB_VERSION == _SVID_) {
6914 + (void) WRITE2(exc.name, 2);
6915 + (void) WRITE2(": TLOSS error\n", 14);
6917 + errno = ERANGE;
6919 + break;
6920 + case 35:
6921 + case 135:
6922 + /* y0(x>X_TLOSS) */
6923 + exc.type = TLOSS;
6924 + exc.name = type < 100 ? "y0" : "y0f";
6925 + exc.retval = zero;
6926 + if (_LIB_VERSION == _POSIX_)
6927 + errno = ERANGE;
6928 + else if (!matherr(&exc)) {
6929 + if (_LIB_VERSION == _SVID_) {
6930 + (void) WRITE2(exc.name, 2);
6931 + (void) WRITE2(": TLOSS error\n", 14);
6933 + errno = ERANGE;
6935 + break;
6936 + case 36:
6937 + case 136:
6938 + /* j1(|x|>X_TLOSS) */
6939 + exc.type = TLOSS;
6940 + exc.name = type < 100 ? "j1" : "j1f";
6941 + exc.retval = zero;
6942 + if (_LIB_VERSION == _POSIX_)
6943 + errno = ERANGE;
6944 + else if (!matherr(&exc)) {
6945 + if (_LIB_VERSION == _SVID_) {
6946 + (void) WRITE2(exc.name, 2);
6947 + (void) WRITE2(": TLOSS error\n", 14);
6949 + errno = ERANGE;
6951 + break;
6952 + case 37:
6953 + case 137:
6954 + /* y1(x>X_TLOSS) */
6955 + exc.type = TLOSS;
6956 + exc.name = type < 100 ? "y1" : "y1f";
6957 + exc.retval = zero;
6958 + if (_LIB_VERSION == _POSIX_)
6959 + errno = ERANGE;
6960 + else if (!matherr(&exc)) {
6961 + if (_LIB_VERSION == _SVID_) {
6962 + (void) WRITE2(exc.name, 2);
6963 + (void) WRITE2(": TLOSS error\n", 14);
6965 + errno = ERANGE;
6967 + break;
6968 + case 38:
6969 + case 138:
6970 + /* jn(|x|>X_TLOSS) */
6971 + exc.type = TLOSS;
6972 + exc.name = type < 100 ? "jn" : "jnf";
6973 + exc.retval = zero;
6974 + if (_LIB_VERSION == _POSIX_)
6975 + errno = ERANGE;
6976 + else if (!matherr(&exc)) {
6977 + if (_LIB_VERSION == _SVID_) {
6978 + (void) WRITE2(exc.name, 2);
6979 + (void) WRITE2(": TLOSS error\n", 14);
6981 + errno = ERANGE;
6983 + break;
6984 + case 39:
6985 + case 139:
6986 + /* yn(x>X_TLOSS) */
6987 + exc.type = TLOSS;
6988 + exc.name = type < 100 ? "yn" : "ynf";
6989 + exc.retval = zero;
6990 + if (_LIB_VERSION == _POSIX_)
6991 + errno = ERANGE;
6992 + else if (!matherr(&exc)) {
6993 + if (_LIB_VERSION == _SVID_) {
6994 + (void) WRITE2(exc.name, 2);
6995 + (void) WRITE2(": TLOSS error\n", 14);
6997 + errno = ERANGE;
6999 + break;
7000 + case 40:
7001 + case 140:
7002 + /* gamma(finite) overflow */
7003 + exc.type = OVERFLOW;
7004 + exc.name = type < 100 ? "gamma" : "gammaf";
7005 + if (_LIB_VERSION == _SVID_)
7006 + exc.retval = HUGE;
7007 + else
7008 + exc.retval = HUGE_VAL;
7009 + if (_LIB_VERSION == _POSIX_)
7010 + errno = ERANGE;
7011 + else if (!matherr(&exc)) {
7012 + errno = ERANGE;
7014 + break;
7015 + case 41:
7016 + case 141:
7017 + /* gamma(-integer) or gamma(0) */
7018 + exc.type = SING;
7019 + exc.name = type < 100 ? "gamma" : "gammaf";
7020 + if (_LIB_VERSION == _SVID_)
7021 + exc.retval = HUGE;
7022 + else
7023 + exc.retval = HUGE_VAL;
7024 + if (_LIB_VERSION == _POSIX_)
7025 + errno = EDOM;
7026 + else if (!matherr(&exc)) {
7027 + if (_LIB_VERSION == _SVID_) {
7028 + (void) WRITE2("gamma: SING error\n", 18);
7030 + errno = EDOM;
7032 + break;
7033 + case 42:
7034 + case 142:
7035 + /* pow(NaN,0.0) */
7036 + /* error only if _LIB_VERSION == _SVID_ & _XOPEN_ */
7037 + exc.type = DOMAIN;
7038 + exc.name = type < 100 ? "pow" : "powf";
7039 + exc.retval = x;
7040 + if (_LIB_VERSION == _IEEE_ ||
7041 + _LIB_VERSION == _POSIX_) exc.retval = 1.0;
7042 + else if (!matherr(&exc)) {
7043 + errno = EDOM;
7045 + break;
7047 + return exc.retval;
7049 diff -urN dietlibc-0.30/libm/k_tan.c dietlibc-0.30-libm/libm/k_tan.c
7050 --- dietlibc-0.30/libm/k_tan.c 1970-01-01 00:00:00.000000000 +0000
7051 +++ dietlibc-0.30-libm/libm/k_tan.c 2006-06-25 11:20:25.000000000 +0000
7052 @@ -0,0 +1,131 @@
7053 +/* @(#)k_tan.c 5.1 93/09/24 */
7055 + * ====================================================
7056 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
7058 + * Developed at SunPro, a Sun Microsystems, Inc. business.
7059 + * Permission to use, copy, modify, and distribute this
7060 + * software is freely granted, provided that this notice
7061 + * is preserved.
7062 + * ====================================================
7063 + */
7065 +#if defined(LIBM_SCCS) && !defined(lint)
7066 +static char rcsid[] = "$NetBSD: k_tan.c,v 1.8 1995/05/10 20:46:37 jtc Exp $";
7067 +#endif
7069 +/* __kernel_tan( x, y, k )
7070 + * kernel tan function on [-pi/4, pi/4], pi/4 ~ 0.7854
7071 + * Input x is assumed to be bounded by ~pi/4 in magnitude.
7072 + * Input y is the tail of x.
7073 + * Input k indicates whether tan (if k=1) or
7074 + * -1/tan (if k= -1) is returned.
7076 + * Algorithm
7077 + * 1. Since tan(-x) = -tan(x), we need only to consider positive x.
7078 + * 2. if x < 2^-28 (hx<0x3e300000 0), return x with inexact if x!=0.
7079 + * 3. tan(x) is approximated by a odd polynomial of degree 27 on
7080 + * [0,0.67434]
7081 + * 3 27
7082 + * tan(x) ~ x + T1*x + ... + T13*x
7083 + * where
7085 + * |tan(x) 2 4 26 | -59.2
7086 + * |----- - (1+T1*x +T2*x +.... +T13*x )| <= 2
7087 + * | x |
7089 + * Note: tan(x+y) = tan(x) + tan'(x)*y
7090 + * ~ tan(x) + (1+x*x)*y
7091 + * Therefore, for better accuracy in computing tan(x+y), let
7092 + * 3 2 2 2 2
7093 + * r = x *(T2+x *(T3+x *(...+x *(T12+x *T13))))
7094 + * then
7095 + * 3 2
7096 + * tan(x+y) = x + (T1*x + (x *(r+y)+y))
7098 + * 4. For x in [0.67434,pi/4], let y = pi/4 - x, then
7099 + * tan(x) = tan(pi/4-y) = (1-tan(y))/(1+tan(y))
7100 + * = 1 - 2*(tan(y) - (tan(y)^2)/(1+tan(y)))
7101 + */
7103 +#include "math.h"
7104 +#include "math_private.h"
7105 +#ifdef __STDC__
7106 +static const double
7107 +#else
7108 +static double
7109 +#endif
7110 +one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
7111 +pio4 = 7.85398163397448278999e-01, /* 0x3FE921FB, 0x54442D18 */
7112 +pio4lo= 3.06161699786838301793e-17, /* 0x3C81A626, 0x33145C07 */
7113 +T[] = {
7114 + 3.33333333333334091986e-01, /* 0x3FD55555, 0x55555563 */
7115 + 1.33333333333201242699e-01, /* 0x3FC11111, 0x1110FE7A */
7116 + 5.39682539762260521377e-02, /* 0x3FABA1BA, 0x1BB341FE */
7117 + 2.18694882948595424599e-02, /* 0x3F9664F4, 0x8406D637 */
7118 + 8.86323982359930005737e-03, /* 0x3F8226E3, 0xE96E8493 */
7119 + 3.59207910759131235356e-03, /* 0x3F6D6D22, 0xC9560328 */
7120 + 1.45620945432529025516e-03, /* 0x3F57DBC8, 0xFEE08315 */
7121 + 5.88041240820264096874e-04, /* 0x3F4344D8, 0xF2F26501 */
7122 + 2.46463134818469906812e-04, /* 0x3F3026F7, 0x1A8D1068 */
7123 + 7.81794442939557092300e-05, /* 0x3F147E88, 0xA03792A6 */
7124 + 7.14072491382608190305e-05, /* 0x3F12B80F, 0x32F0A7E9 */
7125 + -1.85586374855275456654e-05, /* 0xBEF375CB, 0xDB605373 */
7126 + 2.59073051863633712884e-05, /* 0x3EFB2A70, 0x74BF7AD4 */
7129 +#ifdef __STDC__
7130 + double __kernel_tan(double x, double y, int iy)
7131 +#else
7132 + double __kernel_tan(x, y, iy)
7133 + double x,y; int iy;
7134 +#endif
7136 + double z,r,v,w,s;
7137 + int32_t ix,hx;
7138 + GET_HIGH_WORD(hx,x);
7139 + ix = hx&0x7fffffff; /* high word of |x| */
7140 + if(ix<0x3e300000) /* x < 2**-28 */
7141 + {if((int)x==0) { /* generate inexact */
7142 + u_int32_t low;
7143 + GET_LOW_WORD(low,x);
7144 + if(((ix|low)|(iy+1))==0) return one/fabs(x);
7145 + else return (iy==1)? x: -one/x;
7148 + if(ix>=0x3FE59428) { /* |x|>=0.6744 */
7149 + if(hx<0) {x = -x; y = -y;}
7150 + z = pio4-x;
7151 + w = pio4lo-y;
7152 + x = z+w; y = 0.0;
7154 + z = x*x;
7155 + w = z*z;
7156 + /* Break x^5*(T[1]+x^2*T[2]+...) into
7157 + * x^5(T[1]+x^4*T[3]+...+x^20*T[11]) +
7158 + * x^5(x^2*(T[2]+x^4*T[4]+...+x^22*[T12]))
7159 + */
7160 + r = T[1]+w*(T[3]+w*(T[5]+w*(T[7]+w*(T[9]+w*T[11]))));
7161 + v = z*(T[2]+w*(T[4]+w*(T[6]+w*(T[8]+w*(T[10]+w*T[12])))));
7162 + s = z*x;
7163 + r = y + z*(s*(r+v)+y);
7164 + r += T[0]*s;
7165 + w = x+r;
7166 + if(ix>=0x3FE59428) {
7167 + v = (double)iy;
7168 + return (double)(1-((hx>>30)&2))*(v-2.0*(x-(w*w/(w+v)-r)));
7170 + if(iy==1) return w;
7171 + else { /* if allow error up to 2 ulp,
7172 + simply return -1.0/(x+r) here */
7173 + /* compute -1.0/(x+r) accurately */
7174 + double a,t;
7175 + z = w;
7176 + SET_LOW_WORD(z,0);
7177 + v = r-(z - x); /* z+v = r+x */
7178 + t = a = -1.0/w; /* a = -1.0/w */
7179 + SET_LOW_WORD(t,0);
7180 + s = 1.0+t*z;
7181 + return t+a*(s+t*v);
7184 diff -urN dietlibc-0.30/libm/math_private.h dietlibc-0.30-libm/libm/math_private.h
7185 --- dietlibc-0.30/libm/math_private.h 1970-01-01 00:00:00.000000000 +0000
7186 +++ dietlibc-0.30-libm/libm/math_private.h 2006-06-25 11:26:34.000000000 +0000
7187 @@ -0,0 +1,236 @@
7189 + * ====================================================
7190 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
7192 + * Developed at SunPro, a Sun Microsystems, Inc. business.
7193 + * Permission to use, copy, modify, and distribute this
7194 + * software is freely granted, provided that this notice
7195 + * is preserved.
7196 + * ====================================================
7197 + */
7200 + * from: @(#)fdlibm.h 5.1 93/09/24
7201 + * $Id: math_private.h,v 1.3 2004/02/09 07:10:38 andersen Exp $
7202 + */
7204 +#ifndef _MATH_PRIVATE_H_
7205 +#define _MATH_PRIVATE_H_
7207 +# define weak_alias(name, aliasname) _weak_alias (name, aliasname)
7208 +# define _weak_alias(name, aliasname) \
7209 + extern __typeof (name) aliasname __attribute__ ((weak, alias (#name)));
7211 +#include <endian.h>
7212 +#include <sys/types.h>
7213 +#define u_int32_t uint32_t
7215 +/* The original fdlibm code used statements like:
7216 + n0 = ((*(int*)&one)>>29)^1; * index of high word *
7217 + ix0 = *(n0+(int*)&x); * high word of x *
7218 + ix1 = *((1-n0)+(int*)&x); * low word of x *
7219 + to dig two 32 bit words out of the 64 bit IEEE floating point
7220 + value. That is non-ANSI, and, moreover, the gcc instruction
7221 + scheduler gets it wrong. We instead use the following macros.
7222 + Unlike the original code, we determine the endianness at compile
7223 + time, not at run time; I don't see much benefit to selecting
7224 + endianness at run time. */
7226 +/* A union which permits us to convert between a double and two 32 bit
7227 + ints. */
7230 + * Math on arm is special:
7231 + * For FPA, float words are always big-endian.
7232 + * For VFP, floats words follow the memory system mode.
7233 + */
7235 +#if (__BYTE_ORDER == __BIG_ENDIAN) || \
7236 + (!defined(__VFP_FP__) && (defined(__arm__) || defined(__thumb__)))
7238 +typedef union
7240 + double value;
7241 + struct
7243 + u_int32_t msw;
7244 + u_int32_t lsw;
7245 + } parts;
7246 +} ieee_double_shape_type;
7248 +#else
7250 +typedef union
7252 + double value;
7253 + struct
7255 + u_int32_t lsw;
7256 + u_int32_t msw;
7257 + } parts;
7258 +} ieee_double_shape_type;
7260 +#endif
7262 +/* Get two 32 bit ints from a double. */
7264 +#define EXTRACT_WORDS(ix0,ix1,d) \
7265 +do { \
7266 + ieee_double_shape_type ew_u; \
7267 + ew_u.value = (d); \
7268 + (ix0) = ew_u.parts.msw; \
7269 + (ix1) = ew_u.parts.lsw; \
7270 +} while (0)
7272 +/* Get the more significant 32 bit int from a double. */
7274 +#define GET_HIGH_WORD(i,d) \
7275 +do { \
7276 + ieee_double_shape_type gh_u; \
7277 + gh_u.value = (d); \
7278 + (i) = gh_u.parts.msw; \
7279 +} while (0)
7281 +/* Get the less significant 32 bit int from a double. */
7283 +#define GET_LOW_WORD(i,d) \
7284 +do { \
7285 + ieee_double_shape_type gl_u; \
7286 + gl_u.value = (d); \
7287 + (i) = gl_u.parts.lsw; \
7288 +} while (0)
7290 +/* Set a double from two 32 bit ints. */
7292 +#define INSERT_WORDS(d,ix0,ix1) \
7293 +do { \
7294 + ieee_double_shape_type iw_u; \
7295 + iw_u.parts.msw = (ix0); \
7296 + iw_u.parts.lsw = (ix1); \
7297 + (d) = iw_u.value; \
7298 +} while (0)
7300 +/* Set the more significant 32 bits of a double from an int. */
7302 +#define SET_HIGH_WORD(d,v) \
7303 +do { \
7304 + ieee_double_shape_type sh_u; \
7305 + sh_u.value = (d); \
7306 + sh_u.parts.msw = (v); \
7307 + (d) = sh_u.value; \
7308 +} while (0)
7310 +/* Set the less significant 32 bits of a double from an int. */
7312 +#define SET_LOW_WORD(d,v) \
7313 +do { \
7314 + ieee_double_shape_type sl_u; \
7315 + sl_u.value = (d); \
7316 + sl_u.parts.lsw = (v); \
7317 + (d) = sl_u.value; \
7318 +} while (0)
7320 +/* A union which permits us to convert between a float and a 32 bit
7321 + int. */
7323 +typedef union
7325 + float value;
7326 + u_int32_t word;
7327 +} ieee_float_shape_type;
7329 +/* Get a 32 bit int from a float. */
7331 +#define GET_FLOAT_WORD(i,d) \
7332 +do { \
7333 + ieee_float_shape_type gf_u; \
7334 + gf_u.value = (d); \
7335 + (i) = gf_u.word; \
7336 +} while (0)
7338 +/* Set a float from a 32 bit int. */
7340 +#define SET_FLOAT_WORD(d,i) \
7341 +do { \
7342 + ieee_float_shape_type sf_u; \
7343 + sf_u.word = (i); \
7344 + (d) = sf_u.value; \
7345 +} while (0)
7347 +/* ieee style elementary functions */
7348 +extern double __ieee754_sqrt __P((double));
7349 +extern double __ieee754_acos __P((double));
7350 +extern double __ieee754_acosh __P((double));
7351 +extern double __ieee754_log __P((double));
7352 +extern double __ieee754_atanh __P((double));
7353 +extern double __ieee754_asin __P((double));
7354 +extern double __ieee754_atan2 __P((double,double));
7355 +extern double __ieee754_exp __P((double));
7356 +extern double __ieee754_cosh __P((double));
7357 +extern double __ieee754_fmod __P((double,double));
7358 +extern double __ieee754_pow __P((double,double));
7359 +extern double __ieee754_lgamma_r __P((double,int *));
7360 +extern double __ieee754_gamma_r __P((double,int *));
7361 +extern double __ieee754_lgamma __P((double));
7362 +extern double __ieee754_gamma __P((double));
7363 +extern double __ieee754_log10 __P((double));
7364 +extern double __ieee754_sinh __P((double));
7365 +extern double __ieee754_hypot __P((double,double));
7366 +extern double __ieee754_j0 __P((double));
7367 +extern double __ieee754_j1 __P((double));
7368 +extern double __ieee754_y0 __P((double));
7369 +extern double __ieee754_y1 __P((double));
7370 +extern double __ieee754_jn __P((int,double));
7371 +extern double __ieee754_yn __P((int,double));
7372 +extern double __ieee754_remainder __P((double,double));
7373 +extern int __ieee754_rem_pio2 __P((double,double*));
7374 +#if defined(_SCALB_INT)
7375 +extern double __ieee754_scalb __P((double,int));
7376 +#else
7377 +extern double __ieee754_scalb __P((double,double));
7378 +#endif
7380 +/* fdlibm kernel function */
7381 +extern double __kernel_standard __P((double,double,int));
7382 +extern double __kernel_sin __P((double,double,int));
7383 +extern double __kernel_cos __P((double,double));
7384 +extern double __kernel_tan __P((double,double,int));
7385 +extern int __kernel_rem_pio2 __P((double*,double*,int,int,int,const int*));
7388 +/* ieee style elementary float functions */
7389 +extern float __ieee754_sqrtf __P((float));
7390 +extern float __ieee754_acosf __P((float));
7391 +extern float __ieee754_acoshf __P((float));
7392 +extern float __ieee754_logf __P((float));
7393 +extern float __ieee754_atanhf __P((float));
7394 +extern float __ieee754_asinf __P((float));
7395 +extern float __ieee754_atan2f __P((float,float));
7396 +extern float __ieee754_expf __P((float));
7397 +extern float __ieee754_coshf __P((float));
7398 +extern float __ieee754_fmodf __P((float,float));
7399 +extern float __ieee754_powf __P((float,float));
7400 +extern float __ieee754_lgammaf_r __P((float,int *));
7401 +extern float __ieee754_gammaf_r __P((float,int *));
7402 +extern float __ieee754_lgammaf __P((float));
7403 +extern float __ieee754_gammaf __P((float));
7404 +extern float __ieee754_log10f __P((float));
7405 +extern float __ieee754_sinhf __P((float));
7406 +extern float __ieee754_hypotf __P((float,float));
7407 +extern float __ieee754_j0f __P((float));
7408 +extern float __ieee754_j1f __P((float));
7409 +extern float __ieee754_y0f __P((float));
7410 +extern float __ieee754_y1f __P((float));
7411 +extern float __ieee754_jnf __P((int,float));
7412 +extern float __ieee754_ynf __P((int,float));
7413 +extern float __ieee754_remainderf __P((float,float));
7414 +extern int __ieee754_rem_pio2f __P((float,float*));
7415 +extern float __ieee754_scalbf __P((float,float));
7417 +/* float versions of fdlibm kernel functions */
7418 +extern float __kernel_sinf __P((float,float,int));
7419 +extern float __kernel_cosf __P((float,float));
7420 +extern float __kernel_tanf __P((float,float,int));
7421 +extern int __kernel_rem_pio2f __P((float*,float*,int,int,int,const int*));
7423 +#endif /* _MATH_PRIVATE_H_ */
7424 diff -urN dietlibc-0.30/libm/modf.c dietlibc-0.30-libm/libm/modf.c
7425 --- dietlibc-0.30/libm/modf.c 2003-03-30 19:19:53.000000000 +0000
7426 +++ dietlibc-0.30-libm/libm/modf.c 1970-01-01 00:00:00.000000000 +0000
7427 @@ -1,7 +0,0 @@
7428 -#include <math.h>
7430 -double modf(double x, double *iptr) {
7431 - double fmod_result = fmod(x,1.0);
7432 - *iptr = x - fmod_result;
7433 - return fmod_result;
7435 diff -urN dietlibc-0.30/libm/nan.c dietlibc-0.30-libm/libm/nan.c
7436 --- dietlibc-0.30/libm/nan.c 1970-01-01 00:00:00.000000000 +0000
7437 +++ dietlibc-0.30-libm/libm/nan.c 2006-06-25 11:20:03.000000000 +0000
7438 @@ -0,0 +1,48 @@
7439 +/***********************************************************************
7440 + nan, nanf, nanl - return quiet NaN
7442 + These functions shall return a quiet NaN, if available, with content
7443 + indicated through tagp.
7445 + If the implementation does not support quiet NaNs, these functions
7446 + shall return zero.
7448 + Calls: strlen(), sprintf(), strtod()
7450 +***********************************************************************/
7451 +#include <math.h>
7452 +#include <string.h>
7453 +#include <stdlib.h>
7454 +#include <stdio.h>
7456 +double nan (const char *tagp)
7458 + if (tagp[0] != '\0') {
7459 + char buf[6 + strlen (tagp)];
7460 + sprintf (buf, "NAN(%s)", tagp);
7461 + return strtod (buf, NULL);
7463 + return NAN;
7466 +float nanf (const char *tagp)
7468 + if (tagp[0] != '\0') {
7469 + char buf[6 + strlen (tagp)];
7470 + sprintf (buf, "NAN(%s)", tagp);
7471 + return strtof (buf, NULL);
7473 + return NAN;
7476 +#if 0
7477 +long double nanl (const char *tagp)
7479 + if (tagp[0] != '\0') {
7480 + char buf[6 + strlen (tagp)];
7481 + sprintf (buf, "NAN(%s)", tagp);
7482 + return strtold (buf, NULL);
7484 + return NAN;
7486 +#endif
7487 diff -urN dietlibc-0.30/libm/poly.c dietlibc-0.30-libm/libm/poly.c
7488 --- dietlibc-0.30/libm/poly.c 2002-11-18 01:16:51.000000000 +0000
7489 +++ dietlibc-0.30-libm/libm/poly.c 1970-01-01 00:00:00.000000000 +0000
7490 @@ -1,41 +0,0 @@
7491 -/*--------------------------------------------------------------------------*
7493 -Name __poly - generates a polynomial from arguments
7495 -Usage double __poly ( double x, int n, const double* c );
7497 -Prototype in math.h
7499 -Description __poly generates a polynomial in x, of degree n, with
7500 - coefficients c[0], c[1], ..., c[n]. For example, if n=4,
7501 - the generated polynomial is
7503 - c[4]*x^4 + c[3]*x^3 + c[2]*x^2 + c[1]*x + c[0]
7505 - The polynomial is calculated using Horner's method:
7507 - polynom = (..((x*c[n] + c[n-1])*x + c[n-2])..)*x + c[0]
7509 -Return value __poly returns the value of the polynomial as evaluated for
7510 - the given x.
7511 - A range error occurs if the result exceeds double range.
7513 -*---------------------------------------------------------------------------*/
7515 -#include <stdio.h>
7516 -#include "dietlibm.h"
7518 -double __poly ( double x, size_t n, const double* c)
7520 - long double ret;
7521 - size_t i;
7523 - i = n;
7524 - c += n;
7525 - ret = 0;
7526 - do
7527 - ret = ret * x + *c--;
7528 - while ( i-- );
7530 - return ret;
7532 diff -urN dietlibc-0.30/libm/pow.c dietlibc-0.30-libm/libm/pow.c
7533 --- dietlibc-0.30/libm/pow.c 2003-10-10 13:37:34.000000000 +0000
7534 +++ dietlibc-0.30-libm/libm/pow.c 1970-01-01 00:00:00.000000000 +0000
7535 @@ -1,42 +0,0 @@
7537 -#include <math.h>
7538 -#include "dietlibm.h"
7540 -double pow ( double mant, double expo )
7542 - unsigned int e;
7543 - long double ret;
7545 - /* special cases 0^x */
7546 - if ( mant == 0. ) {
7547 - if ( expo > 0. )
7548 - return 0.;
7549 - else if ( expo == 0. )
7550 - return 1.;
7551 - else
7552 - return 1./mant;
7555 - /* special cases x^n with n is integer */
7556 - if ( expo == (int) (e = (int) expo) ) {
7558 - if ( (int)e < 0 ) {
7559 - e = -e;
7560 - mant = 1./mant;
7563 - ret = 1.;
7565 - while (1) {
7566 - if ( e & 1 )
7567 - ret *= mant;
7568 - if ( (e >>= 1) == 0 )
7569 - break;
7570 - mant *= mant;
7572 - return ret;
7575 - /* normal case */
7576 - return exp ( log (mant) * expo );
7578 diff -urN dietlibc-0.30/libm/rint.c dietlibc-0.30-libm/libm/rint.c
7579 --- dietlibc-0.30/libm/rint.c 2001-07-30 13:45:43.000000000 +0000
7580 +++ dietlibc-0.30-libm/libm/rint.c 1970-01-01 00:00:00.000000000 +0000
7581 @@ -1,5 +0,0 @@
7582 -#include <math.h>
7584 -double rint(double x) {
7585 - return floor(x+0.5);
7587 diff -urN dietlibc-0.30/libm/s_asinh.c dietlibc-0.30-libm/libm/s_asinh.c
7588 --- dietlibc-0.30/libm/s_asinh.c 1970-01-01 00:00:00.000000000 +0000
7589 +++ dietlibc-0.30-libm/libm/s_asinh.c 2006-06-25 11:19:59.000000000 +0000
7590 @@ -0,0 +1,65 @@
7591 +/* @(#)s_asinh.c 5.1 93/09/24 */
7593 + * ====================================================
7594 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
7596 + * Developed at SunPro, a Sun Microsystems, Inc. business.
7597 + * Permission to use, copy, modify, and distribute this
7598 + * software is freely granted, provided that this notice
7599 + * is preserved.
7600 + * ====================================================
7601 + */
7603 +#if defined(LIBM_SCCS) && !defined(lint)
7604 +static char rcsid[] = "$NetBSD: s_asinh.c,v 1.9 1995/05/12 04:57:37 jtc Exp $";
7605 +#endif
7607 +/* asinh(x)
7608 + * Method :
7609 + * Based on
7610 + * asinh(x) = sign(x) * log [ |x| + sqrt(x*x+1) ]
7611 + * we have
7612 + * asinh(x) := x if 1+x*x=1,
7613 + * := sign(x)*(log(x)+ln2)) for large |x|, else
7614 + * := sign(x)*log(2|x|+1/(|x|+sqrt(x*x+1))) if|x|>2, else
7615 + * := sign(x)*log1p(|x| + x^2/(1 + sqrt(1+x^2)))
7616 + */
7618 +#include "math.h"
7619 +#include "math_private.h"
7621 +#ifdef __STDC__
7622 +static const double
7623 +#else
7624 +static double
7625 +#endif
7626 +one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
7627 +ln2 = 6.93147180559945286227e-01, /* 0x3FE62E42, 0xFEFA39EF */
7628 +huge= 1.00000000000000000000e+300;
7630 +#ifdef __STDC__
7631 + double asinh(double x)
7632 +#else
7633 + double asinh(x)
7634 + double x;
7635 +#endif
7637 + double t,w;
7638 + int32_t hx,ix;
7639 + GET_HIGH_WORD(hx,x);
7640 + ix = hx&0x7fffffff;
7641 + if(ix>=0x7ff00000) return x+x; /* x is inf or NaN */
7642 + if(ix< 0x3e300000) { /* |x|<2**-28 */
7643 + if(huge+x>one) return x; /* return x inexact except 0 */
7645 + if(ix>0x41b00000) { /* |x| > 2**28 */
7646 + w = __ieee754_log(fabs(x))+ln2;
7647 + } else if (ix>0x40000000) { /* 2**28 > |x| > 2.0 */
7648 + t = fabs(x);
7649 + w = __ieee754_log(2.0*t+one/(__ieee754_sqrt(x*x+one)+t));
7650 + } else { /* 2.0 > |x| > 2**-28 */
7651 + t = x*x;
7652 + w =log1p(fabs(x)+t/(one+__ieee754_sqrt(one+t)));
7654 + if(hx>0) return w; else return -w;
7656 diff -urN dietlibc-0.30/libm/s_atan.c dietlibc-0.30-libm/libm/s_atan.c
7657 --- dietlibc-0.30/libm/s_atan.c 1970-01-01 00:00:00.000000000 +0000
7658 +++ dietlibc-0.30-libm/libm/s_atan.c 2006-06-25 11:20:16.000000000 +0000
7659 @@ -0,0 +1,139 @@
7660 +/* @(#)s_atan.c 5.1 93/09/24 */
7662 + * ====================================================
7663 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
7665 + * Developed at SunPro, a Sun Microsystems, Inc. business.
7666 + * Permission to use, copy, modify, and distribute this
7667 + * software is freely granted, provided that this notice
7668 + * is preserved.
7669 + * ====================================================
7670 + */
7672 +#if defined(LIBM_SCCS) && !defined(lint)
7673 +static char rcsid[] = "$NetBSD: s_atan.c,v 1.8 1995/05/10 20:46:45 jtc Exp $";
7674 +#endif
7676 +/* atan(x)
7677 + * Method
7678 + * 1. Reduce x to positive by atan(x) = -atan(-x).
7679 + * 2. According to the integer k=4t+0.25 chopped, t=x, the argument
7680 + * is further reduced to one of the following intervals and the
7681 + * arctangent of t is evaluated by the corresponding formula:
7683 + * [0,7/16] atan(x) = t-t^3*(a1+t^2*(a2+...(a10+t^2*a11)...)
7684 + * [7/16,11/16] atan(x) = atan(1/2) + atan( (t-0.5)/(1+t/2) )
7685 + * [11/16.19/16] atan(x) = atan( 1 ) + atan( (t-1)/(1+t) )
7686 + * [19/16,39/16] atan(x) = atan(3/2) + atan( (t-1.5)/(1+1.5t) )
7687 + * [39/16,INF] atan(x) = atan(INF) + atan( -1/t )
7689 + * Constants:
7690 + * The hexadecimal values are the intended ones for the following
7691 + * constants. The decimal values may be used, provided that the
7692 + * compiler will convert from decimal to binary accurately enough
7693 + * to produce the hexadecimal values shown.
7694 + */
7696 +#include "math.h"
7697 +#include "math_private.h"
7699 +#ifdef __STDC__
7700 +static const double atanhi[] = {
7701 +#else
7702 +static double atanhi[] = {
7703 +#endif
7704 + 4.63647609000806093515e-01, /* atan(0.5)hi 0x3FDDAC67, 0x0561BB4F */
7705 + 7.85398163397448278999e-01, /* atan(1.0)hi 0x3FE921FB, 0x54442D18 */
7706 + 9.82793723247329054082e-01, /* atan(1.5)hi 0x3FEF730B, 0xD281F69B */
7707 + 1.57079632679489655800e+00, /* atan(inf)hi 0x3FF921FB, 0x54442D18 */
7710 +#ifdef __STDC__
7711 +static const double atanlo[] = {
7712 +#else
7713 +static double atanlo[] = {
7714 +#endif
7715 + 2.26987774529616870924e-17, /* atan(0.5)lo 0x3C7A2B7F, 0x222F65E2 */
7716 + 3.06161699786838301793e-17, /* atan(1.0)lo 0x3C81A626, 0x33145C07 */
7717 + 1.39033110312309984516e-17, /* atan(1.5)lo 0x3C700788, 0x7AF0CBBD */
7718 + 6.12323399573676603587e-17, /* atan(inf)lo 0x3C91A626, 0x33145C07 */
7721 +#ifdef __STDC__
7722 +static const double aT[] = {
7723 +#else
7724 +static double aT[] = {
7725 +#endif
7726 + 3.33333333333329318027e-01, /* 0x3FD55555, 0x5555550D */
7727 + -1.99999999998764832476e-01, /* 0xBFC99999, 0x9998EBC4 */
7728 + 1.42857142725034663711e-01, /* 0x3FC24924, 0x920083FF */
7729 + -1.11111104054623557880e-01, /* 0xBFBC71C6, 0xFE231671 */
7730 + 9.09088713343650656196e-02, /* 0x3FB745CD, 0xC54C206E */
7731 + -7.69187620504482999495e-02, /* 0xBFB3B0F2, 0xAF749A6D */
7732 + 6.66107313738753120669e-02, /* 0x3FB10D66, 0xA0D03D51 */
7733 + -5.83357013379057348645e-02, /* 0xBFADDE2D, 0x52DEFD9A */
7734 + 4.97687799461593236017e-02, /* 0x3FA97B4B, 0x24760DEB */
7735 + -3.65315727442169155270e-02, /* 0xBFA2B444, 0x2C6A6C2F */
7736 + 1.62858201153657823623e-02, /* 0x3F90AD3A, 0xE322DA11 */
7739 +#ifdef __STDC__
7740 + static const double
7741 +#else
7742 + static double
7743 +#endif
7744 +one = 1.0,
7745 +huge = 1.0e300;
7747 +#ifdef __STDC__
7748 + double atan(double x)
7749 +#else
7750 + double atan(x)
7751 + double x;
7752 +#endif
7754 + double w,s1,s2,z;
7755 + int32_t ix,hx,id;
7757 + GET_HIGH_WORD(hx,x);
7758 + ix = hx&0x7fffffff;
7759 + if(ix>=0x44100000) { /* if |x| >= 2^66 */
7760 + u_int32_t low;
7761 + GET_LOW_WORD(low,x);
7762 + if(ix>0x7ff00000||
7763 + (ix==0x7ff00000&&(low!=0)))
7764 + return x+x; /* NaN */
7765 + if(hx>0) return atanhi[3]+atanlo[3];
7766 + else return -atanhi[3]-atanlo[3];
7767 + } if (ix < 0x3fdc0000) { /* |x| < 0.4375 */
7768 + if (ix < 0x3e200000) { /* |x| < 2^-29 */
7769 + if(huge+x>one) return x; /* raise inexact */
7771 + id = -1;
7772 + } else {
7773 + x = fabs(x);
7774 + if (ix < 0x3ff30000) { /* |x| < 1.1875 */
7775 + if (ix < 0x3fe60000) { /* 7/16 <=|x|<11/16 */
7776 + id = 0; x = (2.0*x-one)/(2.0+x);
7777 + } else { /* 11/16<=|x|< 19/16 */
7778 + id = 1; x = (x-one)/(x+one);
7780 + } else {
7781 + if (ix < 0x40038000) { /* |x| < 2.4375 */
7782 + id = 2; x = (x-1.5)/(one+1.5*x);
7783 + } else { /* 2.4375 <= |x| < 2^66 */
7784 + id = 3; x = -1.0/x;
7786 + }}
7787 + /* end of argument reduction */
7788 + z = x*x;
7789 + w = z*z;
7790 + /* break sum from i=0 to 10 aT[i]z**(i+1) into odd and even poly */
7791 + s1 = z*(aT[0]+w*(aT[2]+w*(aT[4]+w*(aT[6]+w*(aT[8]+w*aT[10])))));
7792 + s2 = w*(aT[1]+w*(aT[3]+w*(aT[5]+w*(aT[7]+w*aT[9]))));
7793 + if (id<0) return x - x*(s1+s2);
7794 + else {
7795 + z = atanhi[id] - ((x*(s1+s2) - atanlo[id]) - x);
7796 + return (hx<0)? -z:z;
7799 diff -urN dietlibc-0.30/libm/s_cbrt.c dietlibc-0.30-libm/libm/s_cbrt.c
7800 --- dietlibc-0.30/libm/s_cbrt.c 1970-01-01 00:00:00.000000000 +0000
7801 +++ dietlibc-0.30-libm/libm/s_cbrt.c 2006-06-25 11:20:16.000000000 +0000
7802 @@ -0,0 +1,93 @@
7803 +/* @(#)s_cbrt.c 5.1 93/09/24 */
7805 + * ====================================================
7806 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
7808 + * Developed at SunPro, a Sun Microsystems, Inc. business.
7809 + * Permission to use, copy, modify, and distribute this
7810 + * software is freely granted, provided that this notice
7811 + * is preserved.
7812 + * ====================================================
7813 + */
7815 +#if defined(LIBM_SCCS) && !defined(lint)
7816 +static char rcsid[] = "$NetBSD: s_cbrt.c,v 1.8 1995/05/10 20:46:49 jtc Exp $";
7817 +#endif
7819 +#include "math.h"
7820 +#include "math_private.h"
7822 +/* cbrt(x)
7823 + * Return cube root of x
7824 + */
7825 +#ifdef __STDC__
7826 +static const u_int32_t
7827 +#else
7828 +static u_int32_t
7829 +#endif
7830 + B1 = 715094163, /* B1 = (682-0.03306235651)*2**20 */
7831 + B2 = 696219795; /* B2 = (664-0.03306235651)*2**20 */
7833 +#ifdef __STDC__
7834 +static const double
7835 +#else
7836 +static double
7837 +#endif
7838 +C = 5.42857142857142815906e-01, /* 19/35 = 0x3FE15F15, 0xF15F15F1 */
7839 +D = -7.05306122448979611050e-01, /* -864/1225 = 0xBFE691DE, 0x2532C834 */
7840 +E = 1.41428571428571436819e+00, /* 99/70 = 0x3FF6A0EA, 0x0EA0EA0F */
7841 +F = 1.60714285714285720630e+00, /* 45/28 = 0x3FF9B6DB, 0x6DB6DB6E */
7842 +G = 3.57142857142857150787e-01; /* 5/14 = 0x3FD6DB6D, 0xB6DB6DB7 */
7844 +#ifdef __STDC__
7845 + double cbrt(double x)
7846 +#else
7847 + double cbrt(x)
7848 + double x;
7849 +#endif
7851 + int32_t hx;
7852 + double r,s,t=0.0,w;
7853 + u_int32_t sign;
7854 + u_int32_t high,low;
7856 + GET_HIGH_WORD(hx,x);
7857 + sign=hx&0x80000000; /* sign= sign(x) */
7858 + hx ^=sign;
7859 + if(hx>=0x7ff00000) return(x+x); /* cbrt(NaN,INF) is itself */
7860 + GET_LOW_WORD(low,x);
7861 + if((hx|low)==0)
7862 + return(x); /* cbrt(0) is itself */
7864 + SET_HIGH_WORD(x,hx); /* x <- |x| */
7865 + /* rough cbrt to 5 bits */
7866 + if(hx<0x00100000) /* subnormal number */
7867 + {SET_HIGH_WORD(t,0x43500000); /* set t= 2**54 */
7868 + t*=x; GET_HIGH_WORD(high,t); SET_HIGH_WORD(t,high/3+B2);
7870 + else
7871 + SET_HIGH_WORD(t,hx/3+B1);
7874 + /* new cbrt to 23 bits, may be implemented in single precision */
7875 + r=t*t/x;
7876 + s=C+r*t;
7877 + t*=G+F/(s+E+D/s);
7879 + /* chopped to 20 bits and make it larger than cbrt(x) */
7880 + GET_HIGH_WORD(high,t);
7881 + INSERT_WORDS(t,high+0x00000001,0);
7884 + /* one step newton iteration to 53 bits with error less than 0.667 ulps */
7885 + s=t*t; /* t*t is exact */
7886 + r=x/s;
7887 + w=t+t;
7888 + r=(r-t)/(w+r); /* r-s is exact */
7889 + t=t+t*r;
7891 + /* retore the sign bit */
7892 + GET_HIGH_WORD(high,t);
7893 + SET_HIGH_WORD(t,high|sign);
7894 + return(t);
7896 diff -urN dietlibc-0.30/libm/s_ceil.c dietlibc-0.30-libm/libm/s_ceil.c
7897 --- dietlibc-0.30/libm/s_ceil.c 1970-01-01 00:00:00.000000000 +0000
7898 +++ dietlibc-0.30-libm/libm/s_ceil.c 2006-06-25 11:29:20.000000000 +0000
7899 @@ -0,0 +1,81 @@
7900 +/* @(#)s_ceil.c 5.1 93/09/24 */
7902 + * ====================================================
7903 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
7905 + * Developed at SunPro, a Sun Microsystems, Inc. business.
7906 + * Permission to use, copy, modify, and distribute this
7907 + * software is freely granted, provided that this notice
7908 + * is preserved.
7909 + * ====================================================
7910 + */
7912 +#if defined(LIBM_SCCS) && !defined(lint)
7913 +static char rcsid[] = "$NetBSD: s_ceil.c,v 1.8 1995/05/10 20:46:53 jtc Exp $";
7914 +#endif
7917 + * ceil(x)
7918 + * Return x rounded toward -inf to integral value
7919 + * Method:
7920 + * Bit twiddling.
7921 + * Exception:
7922 + * Inexact flag raised if x not equal to ceil(x).
7923 + */
7925 +#include "math.h"
7926 +#include "math_private.h"
7928 +#ifdef __STDC__
7929 +static const double huge = 1.0e300;
7930 +#else
7931 +static double huge = 1.0e300;
7932 +#endif
7934 +#ifdef __STDC__
7935 + double __ceil(double x)
7936 +#else
7937 + double __ceil(x)
7938 + double x;
7939 +#endif
7941 + int32_t i0,i1,j0;
7942 + u_int32_t i,j;
7943 + EXTRACT_WORDS(i0,i1,x);
7944 + j0 = ((i0>>20)&0x7ff)-0x3ff;
7945 + if(j0<20) {
7946 + if(j0<0) { /* raise inexact if x != 0 */
7947 + if(huge+x>0.0) {/* return 0*sign(x) if |x|<1 */
7948 + if(i0<0) {i0=0x80000000;i1=0;}
7949 + else if((i0|i1)!=0) { i0=0x3ff00000;i1=0;}
7951 + } else {
7952 + i = (0x000fffff)>>j0;
7953 + if(((i0&i)|i1)==0) return x; /* x is integral */
7954 + if(huge+x>0.0) { /* raise inexact flag */
7955 + if(i0>0) i0 += (0x00100000)>>j0;
7956 + i0 &= (~i); i1=0;
7959 + } else if (j0>51) {
7960 + if(j0==0x400) return x+x; /* inf or NaN */
7961 + else return x; /* x is integral */
7962 + } else {
7963 + i = ((u_int32_t)(0xffffffff))>>(j0-20);
7964 + if((i1&i)==0) return x; /* x is integral */
7965 + if(huge+x>0.0) { /* raise inexact flag */
7966 + if(i0>0) {
7967 + if(j0==20) i0+=1;
7968 + else {
7969 + j = i1 + (1<<(52-j0));
7970 + if(j<i1) i0+=1; /* got a carry */
7971 + i1 = j;
7974 + i1 &= (~i);
7977 + INSERT_WORDS(x,i0,i1);
7978 + return x;
7980 +weak_alias (__ceil, ceil)
7981 diff -urN dietlibc-0.30/libm/s_ceilf.c dietlibc-0.30-libm/libm/s_ceilf.c
7982 --- dietlibc-0.30/libm/s_ceilf.c 1970-01-01 00:00:00.000000000 +0000
7983 +++ dietlibc-0.30-libm/libm/s_ceilf.c 2006-06-25 11:20:03.000000000 +0000
7984 @@ -0,0 +1,62 @@
7985 +/* s_ceilf.c -- float version of s_ceil.c.
7986 + * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
7987 + */
7990 + * ====================================================
7991 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
7993 + * Developed at SunPro, a Sun Microsystems, Inc. business.
7994 + * Permission to use, copy, modify, and distribute this
7995 + * software is freely granted, provided that this notice
7996 + * is preserved.
7997 + * ====================================================
7998 + */
8000 +#if defined(LIBM_SCCS) && !defined(lint)
8001 +static char rcsid[] = "$NetBSD: s_ceilf.c,v 1.4 1995/05/10 20:46:55 jtc Exp $";
8002 +#endif
8004 +#include "math.h"
8005 +#include "math_private.h"
8007 +#ifdef __STDC__
8008 +static const float huge = 1.0e30;
8009 +#else
8010 +static float huge = 1.0e30;
8011 +#endif
8013 +#ifdef __STDC__
8014 + float __ceilf(float x)
8015 +#else
8016 + float __ceilf(x)
8017 + float x;
8018 +#endif
8020 + int32_t i0,j0;
8021 + u_int32_t i;
8023 + GET_FLOAT_WORD(i0,x);
8024 + j0 = ((i0>>23)&0xff)-0x7f;
8025 + if(j0<23) {
8026 + if(j0<0) { /* raise inexact if x != 0 */
8027 + if(huge+x>(float)0.0) {/* return 0*sign(x) if |x|<1 */
8028 + if(i0<0) {i0=0x80000000;}
8029 + else if(i0!=0) { i0=0x3f800000;}
8031 + } else {
8032 + i = (0x007fffff)>>j0;
8033 + if((i0&i)==0) return x; /* x is integral */
8034 + if(huge+x>(float)0.0) { /* raise inexact flag */
8035 + if(i0>0) i0 += (0x00800000)>>j0;
8036 + i0 &= (~i);
8039 + } else {
8040 + if(j0==0x80) return x+x; /* inf or NaN */
8041 + else return x; /* x is integral */
8043 + SET_FLOAT_WORD(x,i0);
8044 + return x;
8046 +weak_alias (__ceilf, ceilf)
8047 diff -urN dietlibc-0.30/libm/s_copysign.c dietlibc-0.30-libm/libm/s_copysign.c
8048 --- dietlibc-0.30/libm/s_copysign.c 1970-01-01 00:00:00.000000000 +0000
8049 +++ dietlibc-0.30-libm/libm/s_copysign.c 2006-06-25 11:20:05.000000000 +0000
8050 @@ -0,0 +1,39 @@
8051 +/* @(#)s_copysign.c 5.1 93/09/24 */
8053 + * ====================================================
8054 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8056 + * Developed at SunPro, a Sun Microsystems, Inc. business.
8057 + * Permission to use, copy, modify, and distribute this
8058 + * software is freely granted, provided that this notice
8059 + * is preserved.
8060 + * ====================================================
8061 + */
8063 +#if defined(LIBM_SCCS) && !defined(lint)
8064 +static char rcsid[] = "$NetBSD: s_copysign.c,v 1.8 1995/05/10 20:46:57 jtc Exp $";
8065 +#endif
8068 + * copysign(double x, double y)
8069 + * copysign(x,y) returns a value with the magnitude of x and
8070 + * with the sign bit of y.
8071 + */
8073 +#include "math.h"
8074 +#include "math_private.h"
8076 +#ifdef __STDC__
8077 + double copysign(double x, double y)
8078 +#else
8079 + double copysign(x,y)
8080 + double x,y;
8081 +#endif
8083 + u_int32_t hx,hy;
8084 + GET_HIGH_WORD(hx,x);
8085 + GET_HIGH_WORD(hy,y);
8086 + SET_HIGH_WORD(x,(hx&0x7fffffff)|(hy&0x80000000));
8087 + return x;
8090 diff -urN dietlibc-0.30/libm/s_cos.c dietlibc-0.30-libm/libm/s_cos.c
8091 --- dietlibc-0.30/libm/s_cos.c 1970-01-01 00:00:00.000000000 +0000
8092 +++ dietlibc-0.30-libm/libm/s_cos.c 2006-06-25 11:20:04.000000000 +0000
8093 @@ -0,0 +1,82 @@
8094 +/* @(#)s_cos.c 5.1 93/09/24 */
8096 + * ====================================================
8097 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8099 + * Developed at SunPro, a Sun Microsystems, Inc. business.
8100 + * Permission to use, copy, modify, and distribute this
8101 + * software is freely granted, provided that this notice
8102 + * is preserved.
8103 + * ====================================================
8104 + */
8106 +#if defined(LIBM_SCCS) && !defined(lint)
8107 +static char rcsid[] = "$NetBSD: s_cos.c,v 1.7 1995/05/10 20:47:02 jtc Exp $";
8108 +#endif
8110 +/* cos(x)
8111 + * Return cosine function of x.
8113 + * kernel function:
8114 + * __kernel_sin ... sine function on [-pi/4,pi/4]
8115 + * __kernel_cos ... cosine function on [-pi/4,pi/4]
8116 + * __ieee754_rem_pio2 ... argument reduction routine
8118 + * Method.
8119 + * Let S,C and T denote the sin, cos and tan respectively on
8120 + * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
8121 + * in [-pi/4 , +pi/4], and let n = k mod 4.
8122 + * We have
8124 + * n sin(x) cos(x) tan(x)
8125 + * ----------------------------------------------------------
8126 + * 0 S C T
8127 + * 1 C -S -1/T
8128 + * 2 -S -C T
8129 + * 3 -C S -1/T
8130 + * ----------------------------------------------------------
8132 + * Special cases:
8133 + * Let trig be any of sin, cos, or tan.
8134 + * trig(+-INF) is NaN, with signals;
8135 + * trig(NaN) is that NaN;
8137 + * Accuracy:
8138 + * TRIG(x) returns trig(x) nearly rounded
8139 + */
8141 +#include "math.h"
8142 +#include "math_private.h"
8144 +#ifdef __STDC__
8145 + double cos(double x)
8146 +#else
8147 + double cos(x)
8148 + double x;
8149 +#endif
8151 + double y[2],z=0.0;
8152 + int32_t n, ix;
8154 + /* High word of x. */
8155 + GET_HIGH_WORD(ix,x);
8157 + /* |x| ~< pi/4 */
8158 + ix &= 0x7fffffff;
8159 + if(ix <= 0x3fe921fb) return __kernel_cos(x,z);
8161 + /* cos(Inf or NaN) is NaN */
8162 + else if (ix>=0x7ff00000) return x-x;
8164 + /* argument reduction needed */
8165 + else {
8166 + n = __ieee754_rem_pio2(x,y);
8167 + switch(n&3) {
8168 + case 0: return __kernel_cos(y[0],y[1]);
8169 + case 1: return -__kernel_sin(y[0],y[1],1);
8170 + case 2: return -__kernel_cos(y[0],y[1]);
8171 + default:
8172 + return __kernel_sin(y[0],y[1],1);
8176 diff -urN dietlibc-0.30/libm/s_erf.c dietlibc-0.30-libm/libm/s_erf.c
8177 --- dietlibc-0.30/libm/s_erf.c 1970-01-01 00:00:00.000000000 +0000
8178 +++ dietlibc-0.30-libm/libm/s_erf.c 2006-06-25 11:20:05.000000000 +0000
8179 @@ -0,0 +1,314 @@
8180 +/* @(#)s_erf.c 5.1 93/09/24 */
8182 + * ====================================================
8183 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8185 + * Developed at SunPro, a Sun Microsystems, Inc. business.
8186 + * Permission to use, copy, modify, and distribute this
8187 + * software is freely granted, provided that this notice
8188 + * is preserved.
8189 + * ====================================================
8190 + */
8192 +#if defined(LIBM_SCCS) && !defined(lint)
8193 +static char rcsid[] = "$NetBSD: s_erf.c,v 1.8 1995/05/10 20:47:05 jtc Exp $";
8194 +#endif
8196 +/* double erf(double x)
8197 + * double erfc(double x)
8198 + * x
8199 + * 2 |\
8200 + * erf(x) = --------- | exp(-t*t)dt
8201 + * sqrt(pi) \|
8202 + * 0
8204 + * erfc(x) = 1-erf(x)
8205 + * Note that
8206 + * erf(-x) = -erf(x)
8207 + * erfc(-x) = 2 - erfc(x)
8209 + * Method:
8210 + * 1. For |x| in [0, 0.84375]
8211 + * erf(x) = x + x*R(x^2)
8212 + * erfc(x) = 1 - erf(x) if x in [-.84375,0.25]
8213 + * = 0.5 + ((0.5-x)-x*R) if x in [0.25,0.84375]
8214 + * where R = P/Q where P is an odd poly of degree 8 and
8215 + * Q is an odd poly of degree 10.
8216 + * -57.90
8217 + * | R - (erf(x)-x)/x | <= 2
8220 + * Remark. The formula is derived by noting
8221 + * erf(x) = (2/sqrt(pi))*(x - x^3/3 + x^5/10 - x^7/42 + ....)
8222 + * and that
8223 + * 2/sqrt(pi) = 1.128379167095512573896158903121545171688
8224 + * is close to one. The interval is chosen because the fix
8225 + * point of erf(x) is near 0.6174 (i.e., erf(x)=x when x is
8226 + * near 0.6174), and by some experiment, 0.84375 is chosen to
8227 + * guarantee the error is less than one ulp for erf.
8229 + * 2. For |x| in [0.84375,1.25], let s = |x| - 1, and
8230 + * c = 0.84506291151 rounded to single (24 bits)
8231 + * erf(x) = sign(x) * (c + P1(s)/Q1(s))
8232 + * erfc(x) = (1-c) - P1(s)/Q1(s) if x > 0
8233 + * 1+(c+P1(s)/Q1(s)) if x < 0
8234 + * |P1/Q1 - (erf(|x|)-c)| <= 2**-59.06
8235 + * Remark: here we use the taylor series expansion at x=1.
8236 + * erf(1+s) = erf(1) + s*Poly(s)
8237 + * = 0.845.. + P1(s)/Q1(s)
8238 + * That is, we use rational approximation to approximate
8239 + * erf(1+s) - (c = (single)0.84506291151)
8240 + * Note that |P1/Q1|< 0.078 for x in [0.84375,1.25]
8241 + * where
8242 + * P1(s) = degree 6 poly in s
8243 + * Q1(s) = degree 6 poly in s
8245 + * 3. For x in [1.25,1/0.35(~2.857143)],
8246 + * erfc(x) = (1/x)*exp(-x*x-0.5625+R1/S1)
8247 + * erf(x) = 1 - erfc(x)
8248 + * where
8249 + * R1(z) = degree 7 poly in z, (z=1/x^2)
8250 + * S1(z) = degree 8 poly in z
8252 + * 4. For x in [1/0.35,28]
8253 + * erfc(x) = (1/x)*exp(-x*x-0.5625+R2/S2) if x > 0
8254 + * = 2.0 - (1/x)*exp(-x*x-0.5625+R2/S2) if -6<x<0
8255 + * = 2.0 - tiny (if x <= -6)
8256 + * erf(x) = sign(x)*(1.0 - erfc(x)) if x < 6, else
8257 + * erf(x) = sign(x)*(1.0 - tiny)
8258 + * where
8259 + * R2(z) = degree 6 poly in z, (z=1/x^2)
8260 + * S2(z) = degree 7 poly in z
8262 + * Note1:
8263 + * To compute exp(-x*x-0.5625+R/S), let s be a single
8264 + * precision number and s := x; then
8265 + * -x*x = -s*s + (s-x)*(s+x)
8266 + * exp(-x*x-0.5626+R/S) =
8267 + * exp(-s*s-0.5625)*exp((s-x)*(s+x)+R/S);
8268 + * Note2:
8269 + * Here 4 and 5 make use of the asymptotic series
8270 + * exp(-x*x)
8271 + * erfc(x) ~ ---------- * ( 1 + Poly(1/x^2) )
8272 + * x*sqrt(pi)
8273 + * We use rational approximation to approximate
8274 + * g(s)=f(1/x^2) = log(erfc(x)*x) - x*x + 0.5625
8275 + * Here is the error bound for R1/S1 and R2/S2
8276 + * |R1/S1 - f(x)| < 2**(-62.57)
8277 + * |R2/S2 - f(x)| < 2**(-61.52)
8279 + * 5. For inf > x >= 28
8280 + * erf(x) = sign(x) *(1 - tiny) (raise inexact)
8281 + * erfc(x) = tiny*tiny (raise underflow) if x > 0
8282 + * = 2 - tiny if x<0
8284 + * 7. Special case:
8285 + * erf(0) = 0, erf(inf) = 1, erf(-inf) = -1,
8286 + * erfc(0) = 1, erfc(inf) = 0, erfc(-inf) = 2,
8287 + * erfc/erf(NaN) is NaN
8288 + */
8291 +#include "math.h"
8292 +#include "math_private.h"
8294 +#ifdef __STDC__
8295 +static const double
8296 +#else
8297 +static double
8298 +#endif
8299 +tiny = 1e-300,
8300 +half= 5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */
8301 +one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
8302 +two = 2.00000000000000000000e+00, /* 0x40000000, 0x00000000 */
8303 + /* c = (float)0.84506291151 */
8304 +erx = 8.45062911510467529297e-01, /* 0x3FEB0AC1, 0x60000000 */
8306 + * Coefficients for approximation to erf on [0,0.84375]
8307 + */
8308 +efx = 1.28379167095512586316e-01, /* 0x3FC06EBA, 0x8214DB69 */
8309 +efx8= 1.02703333676410069053e+00, /* 0x3FF06EBA, 0x8214DB69 */
8310 +pp0 = 1.28379167095512558561e-01, /* 0x3FC06EBA, 0x8214DB68 */
8311 +pp1 = -3.25042107247001499370e-01, /* 0xBFD4CD7D, 0x691CB913 */
8312 +pp2 = -2.84817495755985104766e-02, /* 0xBF9D2A51, 0xDBD7194F */
8313 +pp3 = -5.77027029648944159157e-03, /* 0xBF77A291, 0x236668E4 */
8314 +pp4 = -2.37630166566501626084e-05, /* 0xBEF8EAD6, 0x120016AC */
8315 +qq1 = 3.97917223959155352819e-01, /* 0x3FD97779, 0xCDDADC09 */
8316 +qq2 = 6.50222499887672944485e-02, /* 0x3FB0A54C, 0x5536CEBA */
8317 +qq3 = 5.08130628187576562776e-03, /* 0x3F74D022, 0xC4D36B0F */
8318 +qq4 = 1.32494738004321644526e-04, /* 0x3F215DC9, 0x221C1A10 */
8319 +qq5 = -3.96022827877536812320e-06, /* 0xBED09C43, 0x42A26120 */
8321 + * Coefficients for approximation to erf in [0.84375,1.25]
8322 + */
8323 +pa0 = -2.36211856075265944077e-03, /* 0xBF6359B8, 0xBEF77538 */
8324 +pa1 = 4.14856118683748331666e-01, /* 0x3FDA8D00, 0xAD92B34D */
8325 +pa2 = -3.72207876035701323847e-01, /* 0xBFD7D240, 0xFBB8C3F1 */
8326 +pa3 = 3.18346619901161753674e-01, /* 0x3FD45FCA, 0x805120E4 */
8327 +pa4 = -1.10894694282396677476e-01, /* 0xBFBC6398, 0x3D3E28EC */
8328 +pa5 = 3.54783043256182359371e-02, /* 0x3FA22A36, 0x599795EB */
8329 +pa6 = -2.16637559486879084300e-03, /* 0xBF61BF38, 0x0A96073F */
8330 +qa1 = 1.06420880400844228286e-01, /* 0x3FBB3E66, 0x18EEE323 */
8331 +qa2 = 5.40397917702171048937e-01, /* 0x3FE14AF0, 0x92EB6F33 */
8332 +qa3 = 7.18286544141962662868e-02, /* 0x3FB2635C, 0xD99FE9A7 */
8333 +qa4 = 1.26171219808761642112e-01, /* 0x3FC02660, 0xE763351F */
8334 +qa5 = 1.36370839120290507362e-02, /* 0x3F8BEDC2, 0x6B51DD1C */
8335 +qa6 = 1.19844998467991074170e-02, /* 0x3F888B54, 0x5735151D */
8337 + * Coefficients for approximation to erfc in [1.25,1/0.35]
8338 + */
8339 +ra0 = -9.86494403484714822705e-03, /* 0xBF843412, 0x600D6435 */
8340 +ra1 = -6.93858572707181764372e-01, /* 0xBFE63416, 0xE4BA7360 */
8341 +ra2 = -1.05586262253232909814e+01, /* 0xC0251E04, 0x41B0E726 */
8342 +ra3 = -6.23753324503260060396e+01, /* 0xC04F300A, 0xE4CBA38D */
8343 +ra4 = -1.62396669462573470355e+02, /* 0xC0644CB1, 0x84282266 */
8344 +ra5 = -1.84605092906711035994e+02, /* 0xC067135C, 0xEBCCABB2 */
8345 +ra6 = -8.12874355063065934246e+01, /* 0xC0545265, 0x57E4D2F2 */
8346 +ra7 = -9.81432934416914548592e+00, /* 0xC023A0EF, 0xC69AC25C */
8347 +sa1 = 1.96512716674392571292e+01, /* 0x4033A6B9, 0xBD707687 */
8348 +sa2 = 1.37657754143519042600e+02, /* 0x4061350C, 0x526AE721 */
8349 +sa3 = 4.34565877475229228821e+02, /* 0x407B290D, 0xD58A1A71 */
8350 +sa4 = 6.45387271733267880336e+02, /* 0x40842B19, 0x21EC2868 */
8351 +sa5 = 4.29008140027567833386e+02, /* 0x407AD021, 0x57700314 */
8352 +sa6 = 1.08635005541779435134e+02, /* 0x405B28A3, 0xEE48AE2C */
8353 +sa7 = 6.57024977031928170135e+00, /* 0x401A47EF, 0x8E484A93 */
8354 +sa8 = -6.04244152148580987438e-02, /* 0xBFAEEFF2, 0xEE749A62 */
8356 + * Coefficients for approximation to erfc in [1/.35,28]
8357 + */
8358 +rb0 = -9.86494292470009928597e-03, /* 0xBF843412, 0x39E86F4A */
8359 +rb1 = -7.99283237680523006574e-01, /* 0xBFE993BA, 0x70C285DE */
8360 +rb2 = -1.77579549177547519889e+01, /* 0xC031C209, 0x555F995A */
8361 +rb3 = -1.60636384855821916062e+02, /* 0xC064145D, 0x43C5ED98 */
8362 +rb4 = -6.37566443368389627722e+02, /* 0xC083EC88, 0x1375F228 */
8363 +rb5 = -1.02509513161107724954e+03, /* 0xC0900461, 0x6A2E5992 */
8364 +rb6 = -4.83519191608651397019e+02, /* 0xC07E384E, 0x9BDC383F */
8365 +sb1 = 3.03380607434824582924e+01, /* 0x403E568B, 0x261D5190 */
8366 +sb2 = 3.25792512996573918826e+02, /* 0x40745CAE, 0x221B9F0A */
8367 +sb3 = 1.53672958608443695994e+03, /* 0x409802EB, 0x189D5118 */
8368 +sb4 = 3.19985821950859553908e+03, /* 0x40A8FFB7, 0x688C246A */
8369 +sb5 = 2.55305040643316442583e+03, /* 0x40A3F219, 0xCEDF3BE6 */
8370 +sb6 = 4.74528541206955367215e+02, /* 0x407DA874, 0xE79FE763 */
8371 +sb7 = -2.24409524465858183362e+01; /* 0xC03670E2, 0x42712D62 */
8373 +#ifdef __STDC__
8374 + double erf(double x)
8375 +#else
8376 + double erf(x)
8377 + double x;
8378 +#endif
8380 + int32_t hx,ix,i;
8381 + double R,S,P,Q,s,y,z,r;
8382 + GET_HIGH_WORD(hx,x);
8383 + ix = hx&0x7fffffff;
8384 + if(ix>=0x7ff00000) { /* erf(nan)=nan */
8385 + i = ((u_int32_t)hx>>31)<<1;
8386 + return (double)(1-i)+one/x; /* erf(+-inf)=+-1 */
8389 + if(ix < 0x3feb0000) { /* |x|<0.84375 */
8390 + if(ix < 0x3e300000) { /* |x|<2**-28 */
8391 + if (ix < 0x00800000)
8392 + return 0.125*(8.0*x+efx8*x); /*avoid underflow */
8393 + return x + efx*x;
8395 + z = x*x;
8396 + r = pp0+z*(pp1+z*(pp2+z*(pp3+z*pp4)));
8397 + s = one+z*(qq1+z*(qq2+z*(qq3+z*(qq4+z*qq5))));
8398 + y = r/s;
8399 + return x + x*y;
8401 + if(ix < 0x3ff40000) { /* 0.84375 <= |x| < 1.25 */
8402 + s = fabs(x)-one;
8403 + P = pa0+s*(pa1+s*(pa2+s*(pa3+s*(pa4+s*(pa5+s*pa6)))));
8404 + Q = one+s*(qa1+s*(qa2+s*(qa3+s*(qa4+s*(qa5+s*qa6)))));
8405 + if(hx>=0) return erx + P/Q; else return -erx - P/Q;
8407 + if (ix >= 0x40180000) { /* inf>|x|>=6 */
8408 + if(hx>=0) return one-tiny; else return tiny-one;
8410 + x = fabs(x);
8411 + s = one/(x*x);
8412 + if(ix< 0x4006DB6E) { /* |x| < 1/0.35 */
8413 + R=ra0+s*(ra1+s*(ra2+s*(ra3+s*(ra4+s*(
8414 + ra5+s*(ra6+s*ra7))))));
8415 + S=one+s*(sa1+s*(sa2+s*(sa3+s*(sa4+s*(
8416 + sa5+s*(sa6+s*(sa7+s*sa8)))))));
8417 + } else { /* |x| >= 1/0.35 */
8418 + R=rb0+s*(rb1+s*(rb2+s*(rb3+s*(rb4+s*(
8419 + rb5+s*rb6)))));
8420 + S=one+s*(sb1+s*(sb2+s*(sb3+s*(sb4+s*(
8421 + sb5+s*(sb6+s*sb7))))));
8423 + z = x;
8424 + SET_LOW_WORD(z,0);
8425 + r = __ieee754_exp(-z*z-0.5625)*__ieee754_exp((z-x)*(z+x)+R/S);
8426 + if(hx>=0) return one-r/x; else return r/x-one;
8429 +#ifdef __STDC__
8430 + double erfc(double x)
8431 +#else
8432 + double erfc(x)
8433 + double x;
8434 +#endif
8436 + int32_t hx,ix;
8437 + double R,S,P,Q,s,y,z,r;
8438 + GET_HIGH_WORD(hx,x);
8439 + ix = hx&0x7fffffff;
8440 + if(ix>=0x7ff00000) { /* erfc(nan)=nan */
8441 + /* erfc(+-inf)=0,2 */
8442 + return (double)(((u_int32_t)hx>>31)<<1)+one/x;
8445 + if(ix < 0x3feb0000) { /* |x|<0.84375 */
8446 + if(ix < 0x3c700000) /* |x|<2**-56 */
8447 + return one-x;
8448 + z = x*x;
8449 + r = pp0+z*(pp1+z*(pp2+z*(pp3+z*pp4)));
8450 + s = one+z*(qq1+z*(qq2+z*(qq3+z*(qq4+z*qq5))));
8451 + y = r/s;
8452 + if(hx < 0x3fd00000) { /* x<1/4 */
8453 + return one-(x+x*y);
8454 + } else {
8455 + r = x*y;
8456 + r += (x-half);
8457 + return half - r ;
8460 + if(ix < 0x3ff40000) { /* 0.84375 <= |x| < 1.25 */
8461 + s = fabs(x)-one;
8462 + P = pa0+s*(pa1+s*(pa2+s*(pa3+s*(pa4+s*(pa5+s*pa6)))));
8463 + Q = one+s*(qa1+s*(qa2+s*(qa3+s*(qa4+s*(qa5+s*qa6)))));
8464 + if(hx>=0) {
8465 + z = one-erx; return z - P/Q;
8466 + } else {
8467 + z = erx+P/Q; return one+z;
8470 + if (ix < 0x403c0000) { /* |x|<28 */
8471 + x = fabs(x);
8472 + s = one/(x*x);
8473 + if(ix< 0x4006DB6D) { /* |x| < 1/.35 ~ 2.857143*/
8474 + R=ra0+s*(ra1+s*(ra2+s*(ra3+s*(ra4+s*(
8475 + ra5+s*(ra6+s*ra7))))));
8476 + S=one+s*(sa1+s*(sa2+s*(sa3+s*(sa4+s*(
8477 + sa5+s*(sa6+s*(sa7+s*sa8)))))));
8478 + } else { /* |x| >= 1/.35 ~ 2.857143 */
8479 + if(hx<0&&ix>=0x40180000) return two-tiny;/* x < -6 */
8480 + R=rb0+s*(rb1+s*(rb2+s*(rb3+s*(rb4+s*(
8481 + rb5+s*rb6)))));
8482 + S=one+s*(sb1+s*(sb2+s*(sb3+s*(sb4+s*(
8483 + sb5+s*(sb6+s*sb7))))));
8485 + z = x;
8486 + SET_LOW_WORD(z,0);
8487 + r = __ieee754_exp(-z*z-0.5625)*
8488 + __ieee754_exp((z-x)*(z+x)+R/S);
8489 + if(hx>0) return r/x; else return two-r/x;
8490 + } else {
8491 + if(hx>0) return tiny*tiny; else return two-tiny;
8494 diff -urN dietlibc-0.30/libm/s_expm1.c dietlibc-0.30-libm/libm/s_expm1.c
8495 --- dietlibc-0.30/libm/s_expm1.c 1970-01-01 00:00:00.000000000 +0000
8496 +++ dietlibc-0.30-libm/libm/s_expm1.c 2006-06-25 11:20:18.000000000 +0000
8497 @@ -0,0 +1,229 @@
8498 +/* @(#)s_expm1.c 5.1 93/09/24 */
8500 + * ====================================================
8501 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8503 + * Developed at SunPro, a Sun Microsystems, Inc. business.
8504 + * Permission to use, copy, modify, and distribute this
8505 + * software is freely granted, provided that this notice
8506 + * is preserved.
8507 + * ====================================================
8508 + */
8510 +#if defined(LIBM_SCCS) && !defined(lint)
8511 +static char rcsid[] = "$NetBSD: s_expm1.c,v 1.8 1995/05/10 20:47:09 jtc Exp $";
8512 +#endif
8514 +/* expm1(x)
8515 + * Returns exp(x)-1, the exponential of x minus 1.
8517 + * Method
8518 + * 1. Argument reduction:
8519 + * Given x, find r and integer k such that
8521 + * x = k*ln2 + r, |r| <= 0.5*ln2 ~ 0.34658
8523 + * Here a correction term c will be computed to compensate
8524 + * the error in r when rounded to a floating-point number.
8526 + * 2. Approximating expm1(r) by a special rational function on
8527 + * the interval [0,0.34658]:
8528 + * Since
8529 + * r*(exp(r)+1)/(exp(r)-1) = 2+ r^2/6 - r^4/360 + ...
8530 + * we define R1(r*r) by
8531 + * r*(exp(r)+1)/(exp(r)-1) = 2+ r^2/6 * R1(r*r)
8532 + * That is,
8533 + * R1(r**2) = 6/r *((exp(r)+1)/(exp(r)-1) - 2/r)
8534 + * = 6/r * ( 1 + 2.0*(1/(exp(r)-1) - 1/r))
8535 + * = 1 - r^2/60 + r^4/2520 - r^6/100800 + ...
8536 + * We use a special Reme algorithm on [0,0.347] to generate
8537 + * a polynomial of degree 5 in r*r to approximate R1. The
8538 + * maximum error of this polynomial approximation is bounded
8539 + * by 2**-61. In other words,
8540 + * R1(z) ~ 1.0 + Q1*z + Q2*z**2 + Q3*z**3 + Q4*z**4 + Q5*z**5
8541 + * where Q1 = -1.6666666666666567384E-2,
8542 + * Q2 = 3.9682539681370365873E-4,
8543 + * Q3 = -9.9206344733435987357E-6,
8544 + * Q4 = 2.5051361420808517002E-7,
8545 + * Q5 = -6.2843505682382617102E-9;
8546 + * (where z=r*r, and the values of Q1 to Q5 are listed below)
8547 + * with error bounded by
8548 + * | 5 | -61
8549 + * | 1.0+Q1*z+...+Q5*z - R1(z) | <= 2
8550 + * | |
8552 + * expm1(r) = exp(r)-1 is then computed by the following
8553 + * specific way which minimize the accumulation rounding error:
8554 + * 2 3
8555 + * r r [ 3 - (R1 + R1*r/2) ]
8556 + * expm1(r) = r + --- + --- * [--------------------]
8557 + * 2 2 [ 6 - r*(3 - R1*r/2) ]
8559 + * To compensate the error in the argument reduction, we use
8560 + * expm1(r+c) = expm1(r) + c + expm1(r)*c
8561 + * ~ expm1(r) + c + r*c
8562 + * Thus c+r*c will be added in as the correction terms for
8563 + * expm1(r+c). Now rearrange the term to avoid optimization
8564 + * screw up:
8565 + * ( 2 2 )
8566 + * ({ ( r [ R1 - (3 - R1*r/2) ] ) } r )
8567 + * expm1(r+c)~r - ({r*(--- * [--------------------]-c)-c} - --- )
8568 + * ({ ( 2 [ 6 - r*(3 - R1*r/2) ] ) } 2 )
8569 + * ( )
8571 + * = r - E
8572 + * 3. Scale back to obtain expm1(x):
8573 + * From step 1, we have
8574 + * expm1(x) = either 2^k*[expm1(r)+1] - 1
8575 + * = or 2^k*[expm1(r) + (1-2^-k)]
8576 + * 4. Implementation notes:
8577 + * (A). To save one multiplication, we scale the coefficient Qi
8578 + * to Qi*2^i, and replace z by (x^2)/2.
8579 + * (B). To achieve maximum accuracy, we compute expm1(x) by
8580 + * (i) if x < -56*ln2, return -1.0, (raise inexact if x!=inf)
8581 + * (ii) if k=0, return r-E
8582 + * (iii) if k=-1, return 0.5*(r-E)-0.5
8583 + * (iv) if k=1 if r < -0.25, return 2*((r+0.5)- E)
8584 + * else return 1.0+2.0*(r-E);
8585 + * (v) if (k<-2||k>56) return 2^k(1-(E-r)) - 1 (or exp(x)-1)
8586 + * (vi) if k <= 20, return 2^k((1-2^-k)-(E-r)), else
8587 + * (vii) return 2^k(1-((E+2^-k)-r))
8589 + * Special cases:
8590 + * expm1(INF) is INF, expm1(NaN) is NaN;
8591 + * expm1(-INF) is -1, and
8592 + * for finite argument, only expm1(0)=0 is exact.
8594 + * Accuracy:
8595 + * according to an error analysis, the error is always less than
8596 + * 1 ulp (unit in the last place).
8598 + * Misc. info.
8599 + * For IEEE double
8600 + * if x > 7.09782712893383973096e+02 then expm1(x) overflow
8602 + * Constants:
8603 + * The hexadecimal values are the intended ones for the following
8604 + * constants. The decimal values may be used, provided that the
8605 + * compiler will convert from decimal to binary accurately enough
8606 + * to produce the hexadecimal values shown.
8607 + */
8609 +#include "math.h"
8610 +#include "math_private.h"
8612 +#ifdef __STDC__
8613 +static const double
8614 +#else
8615 +static double
8616 +#endif
8617 +one = 1.0,
8618 +huge = 1.0e+300,
8619 +tiny = 1.0e-300,
8620 +o_threshold = 7.09782712893383973096e+02,/* 0x40862E42, 0xFEFA39EF */
8621 +ln2_hi = 6.93147180369123816490e-01,/* 0x3fe62e42, 0xfee00000 */
8622 +ln2_lo = 1.90821492927058770002e-10,/* 0x3dea39ef, 0x35793c76 */
8623 +invln2 = 1.44269504088896338700e+00,/* 0x3ff71547, 0x652b82fe */
8624 + /* scaled coefficients related to expm1 */
8625 +Q1 = -3.33333333333331316428e-02, /* BFA11111 111110F4 */
8626 +Q2 = 1.58730158725481460165e-03, /* 3F5A01A0 19FE5585 */
8627 +Q3 = -7.93650757867487942473e-05, /* BF14CE19 9EAADBB7 */
8628 +Q4 = 4.00821782732936239552e-06, /* 3ED0CFCA 86E65239 */
8629 +Q5 = -2.01099218183624371326e-07; /* BE8AFDB7 6E09C32D */
8631 +#ifdef __STDC__
8632 + double expm1(double x)
8633 +#else
8634 + double expm1(x)
8635 + double x;
8636 +#endif
8638 + double y,hi,lo,c=0.0,t,e,hxs,hfx,r1;
8639 + int32_t k,xsb;
8640 + u_int32_t hx;
8642 + GET_HIGH_WORD(hx,x);
8643 + xsb = hx&0x80000000; /* sign bit of x */
8644 + if(xsb==0) y=x; else y= -x; /* y = |x| */
8645 + hx &= 0x7fffffff; /* high word of |x| */
8647 + /* filter out huge and non-finite argument */
8648 + if(hx >= 0x4043687A) { /* if |x|>=56*ln2 */
8649 + if(hx >= 0x40862E42) { /* if |x|>=709.78... */
8650 + if(hx>=0x7ff00000) {
8651 + u_int32_t low;
8652 + GET_LOW_WORD(low,x);
8653 + if(((hx&0xfffff)|low)!=0)
8654 + return x+x; /* NaN */
8655 + else return (xsb==0)? x:-1.0;/* exp(+-inf)={inf,-1} */
8657 + if(x > o_threshold) return huge*huge; /* overflow */
8659 + if(xsb!=0) { /* x < -56*ln2, return -1.0 with inexact */
8660 + if(x+tiny<0.0) /* raise inexact */
8661 + return tiny-one; /* return -1 */
8665 + /* argument reduction */
8666 + if(hx > 0x3fd62e42) { /* if |x| > 0.5 ln2 */
8667 + if(hx < 0x3FF0A2B2) { /* and |x| < 1.5 ln2 */
8668 + if(xsb==0)
8669 + {hi = x - ln2_hi; lo = ln2_lo; k = 1;}
8670 + else
8671 + {hi = x + ln2_hi; lo = -ln2_lo; k = -1;}
8672 + } else {
8673 + k = invln2*x+((xsb==0)?0.5:-0.5);
8674 + t = k;
8675 + hi = x - t*ln2_hi; /* t*ln2_hi is exact here */
8676 + lo = t*ln2_lo;
8678 + x = hi - lo;
8679 + c = (hi-x)-lo;
8681 + else if(hx < 0x3c900000) { /* when |x|<2**-54, return x */
8682 + t = huge+x; /* return x with inexact flags when x!=0 */
8683 + return x - (t-(huge+x));
8685 + else k = 0;
8687 + /* x is now in primary range */
8688 + hfx = 0.5*x;
8689 + hxs = x*hfx;
8690 + r1 = one+hxs*(Q1+hxs*(Q2+hxs*(Q3+hxs*(Q4+hxs*Q5))));
8691 + t = 3.0-r1*hfx;
8692 + e = hxs*((r1-t)/(6.0 - x*t));
8693 + if(k==0) return x - (x*e-hxs); /* c is 0 */
8694 + else {
8695 + e = (x*(e-c)-c);
8696 + e -= hxs;
8697 + if(k== -1) return 0.5*(x-e)-0.5;
8698 + if(k==1) {
8699 + if(x < -0.25) return -2.0*(e-(x+0.5));
8700 + else return one+2.0*(x-e);
8702 + if (k <= -2 || k>56) { /* suffice to return exp(x)-1 */
8703 + u_int32_t high;
8704 + y = one-(e-x);
8705 + GET_HIGH_WORD(high,y);
8706 + SET_HIGH_WORD(y,high+(k<<20)); /* add k to y's exponent */
8707 + return y-one;
8709 + t = one;
8710 + if(k<20) {
8711 + u_int32_t high;
8712 + SET_HIGH_WORD(t,0x3ff00000 - (0x200000>>k)); /* t=1-2^-k */
8713 + y = t-(e-x);
8714 + GET_HIGH_WORD(high,y);
8715 + SET_HIGH_WORD(y,high+(k<<20)); /* add k to y's exponent */
8716 + } else {
8717 + u_int32_t high;
8718 + SET_HIGH_WORD(t,((0x3ff-k)<<20)); /* 2^-k */
8719 + y = x-(e+t);
8720 + y += one;
8721 + GET_HIGH_WORD(high,y);
8722 + SET_HIGH_WORD(y,high+(k<<20)); /* add k to y's exponent */
8725 + return y;
8727 diff -urN dietlibc-0.30/libm/s_fabs.c dietlibc-0.30-libm/libm/s_fabs.c
8728 --- dietlibc-0.30/libm/s_fabs.c 1970-01-01 00:00:00.000000000 +0000
8729 +++ dietlibc-0.30-libm/libm/s_fabs.c 2006-06-25 11:20:17.000000000 +0000
8730 @@ -0,0 +1,35 @@
8731 +/* @(#)s_fabs.c 5.1 93/09/24 */
8733 + * ====================================================
8734 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8736 + * Developed at SunPro, a Sun Microsystems, Inc. business.
8737 + * Permission to use, copy, modify, and distribute this
8738 + * software is freely granted, provided that this notice
8739 + * is preserved.
8740 + * ====================================================
8741 + */
8743 +#if defined(LIBM_SCCS) && !defined(lint)
8744 +static char rcsid[] = "$NetBSD: s_fabs.c,v 1.7 1995/05/10 20:47:13 jtc Exp $";
8745 +#endif
8748 + * fabs(x) returns the absolute value of x.
8749 + */
8751 +#include "math.h"
8752 +#include "math_private.h"
8754 +#ifdef __STDC__
8755 + double fabs(double x)
8756 +#else
8757 + double fabs(x)
8758 + double x;
8759 +#endif
8761 + u_int32_t high;
8762 + GET_HIGH_WORD(high,x);
8763 + SET_HIGH_WORD(x,high&0x7fffffff);
8764 + return x;
8766 diff -urN dietlibc-0.30/libm/s_finite.c dietlibc-0.30-libm/libm/s_finite.c
8767 --- dietlibc-0.30/libm/s_finite.c 1970-01-01 00:00:00.000000000 +0000
8768 +++ dietlibc-0.30-libm/libm/s_finite.c 2006-06-25 11:19:58.000000000 +0000
8769 @@ -0,0 +1,35 @@
8770 +/* @(#)s_finite.c 5.1 93/09/24 */
8772 + * ====================================================
8773 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8775 + * Developed at SunPro, a Sun Microsystems, Inc. business.
8776 + * Permission to use, copy, modify, and distribute this
8777 + * software is freely granted, provided that this notice
8778 + * is preserved.
8779 + * ====================================================
8780 + */
8782 +#if defined(LIBM_SCCS) && !defined(lint)
8783 +static char rcsid[] = "$NetBSD: s_finite.c,v 1.8 1995/05/10 20:47:17 jtc Exp $";
8784 +#endif
8787 + * finite(x) returns 1 is x is finite, else 0;
8788 + * no branching!
8789 + */
8791 +#include "math.h"
8792 +#include "math_private.h"
8794 +#ifdef __STDC__
8795 + int finite(double x)
8796 +#else
8797 + int finite(x)
8798 + double x;
8799 +#endif
8801 + int32_t hx;
8802 + GET_HIGH_WORD(hx,x);
8803 + return (int)((u_int32_t)((hx&0x7fffffff)-0x7ff00000)>>31);
8805 diff -urN dietlibc-0.30/libm/s_floor.c dietlibc-0.30-libm/libm/s_floor.c
8806 --- dietlibc-0.30/libm/s_floor.c 1970-01-01 00:00:00.000000000 +0000
8807 +++ dietlibc-0.30-libm/libm/s_floor.c 2006-06-25 11:20:17.000000000 +0000
8808 @@ -0,0 +1,81 @@
8809 +/* @(#)s_floor.c 5.1 93/09/24 */
8811 + * ====================================================
8812 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8814 + * Developed at SunPro, a Sun Microsystems, Inc. business.
8815 + * Permission to use, copy, modify, and distribute this
8816 + * software is freely granted, provided that this notice
8817 + * is preserved.
8818 + * ====================================================
8819 + */
8821 +#if defined(LIBM_SCCS) && !defined(lint)
8822 +static char rcsid[] = "$NetBSD: s_floor.c,v 1.8 1995/05/10 20:47:20 jtc Exp $";
8823 +#endif
8826 + * floor(x)
8827 + * Return x rounded toward -inf to integral value
8828 + * Method:
8829 + * Bit twiddling.
8830 + * Exception:
8831 + * Inexact flag raised if x not equal to floor(x).
8832 + */
8834 +#include "math.h"
8835 +#include "math_private.h"
8837 +#ifdef __STDC__
8838 +static const double huge = 1.0e300;
8839 +#else
8840 +static double huge = 1.0e300;
8841 +#endif
8843 +#ifdef __STDC__
8844 + double floor(double x)
8845 +#else
8846 + double floor(x)
8847 + double x;
8848 +#endif
8850 + int32_t i0,i1,j0;
8851 + u_int32_t i,j;
8852 + EXTRACT_WORDS(i0,i1,x);
8853 + j0 = ((i0>>20)&0x7ff)-0x3ff;
8854 + if(j0<20) {
8855 + if(j0<0) { /* raise inexact if x != 0 */
8856 + if(huge+x>0.0) {/* return 0*sign(x) if |x|<1 */
8857 + if(i0>=0) {i0=i1=0;}
8858 + else if(((i0&0x7fffffff)|i1)!=0)
8859 + { i0=0xbff00000;i1=0;}
8861 + } else {
8862 + i = (0x000fffff)>>j0;
8863 + if(((i0&i)|i1)==0) return x; /* x is integral */
8864 + if(huge+x>0.0) { /* raise inexact flag */
8865 + if(i0<0) i0 += (0x00100000)>>j0;
8866 + i0 &= (~i); i1=0;
8869 + } else if (j0>51) {
8870 + if(j0==0x400) return x+x; /* inf or NaN */
8871 + else return x; /* x is integral */
8872 + } else {
8873 + i = ((u_int32_t)(0xffffffff))>>(j0-20);
8874 + if((i1&i)==0) return x; /* x is integral */
8875 + if(huge+x>0.0) { /* raise inexact flag */
8876 + if(i0<0) {
8877 + if(j0==20) i0+=1;
8878 + else {
8879 + j = i1+(1<<(52-j0));
8880 + if(j<i1) i0 +=1 ; /* got a carry */
8881 + i1=j;
8884 + i1 &= (~i);
8887 + INSERT_WORDS(x,i0,i1);
8888 + return x;
8890 diff -urN dietlibc-0.30/libm/s_floorf.c dietlibc-0.30-libm/libm/s_floorf.c
8891 --- dietlibc-0.30/libm/s_floorf.c 1970-01-01 00:00:00.000000000 +0000
8892 +++ dietlibc-0.30-libm/libm/s_floorf.c 2006-06-25 11:20:14.000000000 +0000
8893 @@ -0,0 +1,71 @@
8894 +/* s_floorf.c -- float version of s_floor.c.
8895 + * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
8896 + */
8899 + * ====================================================
8900 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8902 + * Developed at SunPro, a Sun Microsystems, Inc. business.
8903 + * Permission to use, copy, modify, and distribute this
8904 + * software is freely granted, provided that this notice
8905 + * is preserved.
8906 + * ====================================================
8907 + */
8909 +#if defined(LIBM_SCCS) && !defined(lint)
8910 +static char rcsid[] = "$NetBSD: s_floorf.c,v 1.4 1995/05/10 20:47:22 jtc Exp $";
8911 +#endif
8914 + * floorf(x)
8915 + * Return x rounded toward -inf to integral value
8916 + * Method:
8917 + * Bit twiddling.
8918 + * Exception:
8919 + * Inexact flag raised if x not equal to floorf(x).
8920 + */
8922 +#include "math.h"
8923 +#include "math_private.h"
8925 +#ifdef __STDC__
8926 +static const float huge = 1.0e30;
8927 +#else
8928 +static float huge = 1.0e30;
8929 +#endif
8931 +#ifdef __STDC__
8932 + float __floorf(float x)
8933 +#else
8934 + float __floorf(x)
8935 + float x;
8936 +#endif
8938 + int32_t i0,j0;
8939 + u_int32_t i;
8940 + GET_FLOAT_WORD(i0,x);
8941 + j0 = ((i0>>23)&0xff)-0x7f;
8942 + if(j0<23) {
8943 + if(j0<0) { /* raise inexact if x != 0 */
8944 + if(huge+x>(float)0.0) {/* return 0*sign(x) if |x|<1 */
8945 + if(i0>=0) {i0=0;}
8946 + else if((i0&0x7fffffff)!=0)
8947 + { i0=0xbf800000;}
8949 + } else {
8950 + i = (0x007fffff)>>j0;
8951 + if((i0&i)==0) return x; /* x is integral */
8952 + if(huge+x>(float)0.0) { /* raise inexact flag */
8953 + if(i0<0) i0 += (0x00800000)>>j0;
8954 + i0 &= (~i);
8957 + } else {
8958 + if(j0==0x80) return x+x; /* inf or NaN */
8959 + else return x; /* x is integral */
8961 + SET_FLOAT_WORD(x,i0);
8962 + return x;
8964 +weak_alias (__floorf, floorf)
8965 diff -urN dietlibc-0.30/libm/s_frexp.c dietlibc-0.30-libm/libm/s_frexp.c
8966 --- dietlibc-0.30/libm/s_frexp.c 1970-01-01 00:00:00.000000000 +0000
8967 +++ dietlibc-0.30-libm/libm/s_frexp.c 2006-06-25 11:20:20.000000000 +0000
8968 @@ -0,0 +1,60 @@
8969 +/* @(#)s_frexp.c 5.1 93/09/24 */
8971 + * ====================================================
8972 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8974 + * Developed at SunPro, a Sun Microsystems, Inc. business.
8975 + * Permission to use, copy, modify, and distribute this
8976 + * software is freely granted, provided that this notice
8977 + * is preserved.
8978 + * ====================================================
8979 + */
8981 +#if defined(LIBM_SCCS) && !defined(lint)
8982 +static char rcsid[] = "$NetBSD: s_frexp.c,v 1.9 1995/05/10 20:47:24 jtc Exp $";
8983 +#endif
8986 + * for non-zero x
8987 + * x = frexp(arg,&exp);
8988 + * return a double fp quantity x such that 0.5 <= |x| <1.0
8989 + * and the corresponding binary exponent "exp". That is
8990 + * arg = x*2^exp.
8991 + * If arg is inf, 0.0, or NaN, then frexp(arg,&exp) returns arg
8992 + * with *exp=0.
8993 + */
8995 +#include "math.h"
8996 +#include "math_private.h"
8998 +#ifdef __STDC__
8999 +static const double
9000 +#else
9001 +static double
9002 +#endif
9003 +two54 = 1.80143985094819840000e+16; /* 0x43500000, 0x00000000 */
9005 +#ifdef __STDC__
9006 + double __frexp(double x, int *eptr)
9007 +#else
9008 + double __frexp(x, eptr)
9009 + double x; int *eptr;
9010 +#endif
9012 + int32_t hx, ix, lx;
9013 + EXTRACT_WORDS(hx,lx,x);
9014 + ix = 0x7fffffff&hx;
9015 + *eptr = 0;
9016 + if(ix>=0x7ff00000||((ix|lx)==0)) return x; /* 0,inf,nan */
9017 + if (ix<0x00100000) { /* subnormal */
9018 + x *= two54;
9019 + GET_HIGH_WORD(hx,x);
9020 + ix = hx&0x7fffffff;
9021 + *eptr = -54;
9023 + *eptr += (ix>>20)-1022;
9024 + hx = (hx&0x800fffff)|0x3fe00000;
9025 + SET_HIGH_WORD(x,hx);
9026 + return x;
9028 +weak_alias (__frexp, frexp)
9029 diff -urN dietlibc-0.30/libm/s_ilogb.c dietlibc-0.30-libm/libm/s_ilogb.c
9030 --- dietlibc-0.30/libm/s_ilogb.c 1970-01-01 00:00:00.000000000 +0000
9031 +++ dietlibc-0.30-libm/libm/s_ilogb.c 2006-06-25 11:20:02.000000000 +0000
9032 @@ -0,0 +1,51 @@
9033 +/* @(#)s_ilogb.c 5.1 93/09/24 */
9035 + * ====================================================
9036 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
9038 + * Developed at SunPro, a Sun Microsystems, Inc. business.
9039 + * Permission to use, copy, modify, and distribute this
9040 + * software is freely granted, provided that this notice
9041 + * is preserved.
9042 + * ====================================================
9043 + */
9045 +#if defined(LIBM_SCCS) && !defined(lint)
9046 +static char rcsid[] = "$NetBSD: s_ilogb.c,v 1.9 1995/05/10 20:47:28 jtc Exp $";
9047 +#endif
9049 +/* ilogb(double x)
9050 + * return the binary exponent of non-zero x
9051 + * ilogb(0) = 0x80000001
9052 + * ilogb(inf/NaN) = 0x7fffffff (no signal is raised)
9053 + */
9055 +#include "math.h"
9056 +#include "math_private.h"
9058 +#ifdef __STDC__
9059 + int ilogb(double x)
9060 +#else
9061 + int ilogb(x)
9062 + double x;
9063 +#endif
9065 + int32_t hx,lx,ix;
9067 + GET_HIGH_WORD(hx,x);
9068 + hx &= 0x7fffffff;
9069 + if(hx<0x00100000) {
9070 + GET_LOW_WORD(lx,x);
9071 + if((hx|lx)==0)
9072 + return 0x80000001; /* ilogb(0) = 0x80000001 */
9073 + else /* subnormal x */
9074 + if(hx==0) {
9075 + for (ix = -1043; lx>0; lx<<=1) ix -=1;
9076 + } else {
9077 + for (ix = -1022,hx<<=11; hx>0; hx<<=1) ix -=1;
9079 + return ix;
9081 + else if (hx<0x7ff00000) return (hx>>20)-1023;
9082 + else return 0x7fffffff;
9084 diff -urN dietlibc-0.30/libm/s_ldexp.c dietlibc-0.30-libm/libm/s_ldexp.c
9085 --- dietlibc-0.30/libm/s_ldexp.c 1970-01-01 00:00:00.000000000 +0000
9086 +++ dietlibc-0.30-libm/libm/s_ldexp.c 2006-06-25 11:20:12.000000000 +0000
9087 @@ -0,0 +1,32 @@
9088 +/* @(#)s_ldexp.c 5.1 93/09/24 */
9090 + * ====================================================
9091 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
9093 + * Developed at SunPro, a Sun Microsystems, Inc. business.
9094 + * Permission to use, copy, modify, and distribute this
9095 + * software is freely granted, provided that this notice
9096 + * is preserved.
9097 + * ====================================================
9098 + */
9100 +#if defined(LIBM_SCCS) && !defined(lint)
9101 +static char rcsid[] = "$NetBSD: s_ldexp.c,v 1.6 1995/05/10 20:47:40 jtc Exp $";
9102 +#endif
9104 +#include "math.h"
9105 +#include "math_private.h"
9106 +#include <errno.h>
9108 +#ifdef __STDC__
9109 + double ldexp(double value, int exp)
9110 +#else
9111 + double ldexp(value, exp)
9112 + double value; int exp;
9113 +#endif
9115 + if(!finite(value)||value==0.0) return value;
9116 + value = scalbn(value,exp);
9117 + if(!finite(value)||value==0.0) errno = ERANGE;
9118 + return value;
9120 diff -urN dietlibc-0.30/libm/s_lib_version.c dietlibc-0.30-libm/libm/s_lib_version.c
9121 --- dietlibc-0.30/libm/s_lib_version.c 1970-01-01 00:00:00.000000000 +0000
9122 +++ dietlibc-0.30-libm/libm/s_lib_version.c 2006-06-25 11:20:09.000000000 +0000
9123 @@ -0,0 +1,40 @@
9124 +/* @(#)s_lib_ver.c 5.1 93/09/24 */
9126 + * ====================================================
9127 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
9129 + * Developed at SunPro, a Sun Microsystems, Inc. business.
9130 + * Permission to use, copy, modify, and distribute this
9131 + * software is freely granted, provided that this notice
9132 + * is preserved.
9133 + * ====================================================
9134 + */
9136 +#if defined(LIBM_SCCS) && !defined(lint)
9137 +static char rcsid[] = "$NetBSD: s_lib_version.c,v 1.6 1995/05/10 20:47:44 jtc Exp $";
9138 +#endif
9141 + * MACRO for standards
9142 + */
9144 +#include "math.h"
9145 +#include "math_private.h"
9146 +#if 0
9148 + * define and initialize _LIB_VERSION
9149 + */
9150 +#ifdef _POSIX_MODE
9151 +_LIB_VERSION_TYPE _LIB_VERSION = _POSIX_;
9152 +#else
9153 +#ifdef _XOPEN_MODE
9154 +_LIB_VERSION_TYPE _LIB_VERSION = _XOPEN_;
9155 +#else
9156 +#ifdef _SVID3_MODE
9157 +_LIB_VERSION_TYPE _LIB_VERSION = _SVID_;
9158 +#else /* default _IEEE_MODE */
9159 +_LIB_VERSION_TYPE _LIB_VERSION = _IEEE_;
9160 +#endif
9161 +#endif
9162 +#endif
9163 +#endif
9164 diff -urN dietlibc-0.30/libm/s_log1p.c dietlibc-0.30-libm/libm/s_log1p.c
9165 --- dietlibc-0.30/libm/s_log1p.c 1970-01-01 00:00:00.000000000 +0000
9166 +++ dietlibc-0.30-libm/libm/s_log1p.c 2006-06-25 11:20:15.000000000 +0000
9167 @@ -0,0 +1,174 @@
9168 +/* @(#)s_log1p.c 5.1 93/09/24 */
9170 + * ====================================================
9171 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
9173 + * Developed at SunPro, a Sun Microsystems, Inc. business.
9174 + * Permission to use, copy, modify, and distribute this
9175 + * software is freely granted, provided that this notice
9176 + * is preserved.
9177 + * ====================================================
9178 + */
9180 +#if defined(LIBM_SCCS) && !defined(lint)
9181 +static char rcsid[] = "$NetBSD: s_log1p.c,v 1.8 1995/05/10 20:47:46 jtc Exp $";
9182 +#endif
9184 +/* double log1p(double x)
9186 + * Method :
9187 + * 1. Argument Reduction: find k and f such that
9188 + * 1+x = 2^k * (1+f),
9189 + * where sqrt(2)/2 < 1+f < sqrt(2) .
9191 + * Note. If k=0, then f=x is exact. However, if k!=0, then f
9192 + * may not be representable exactly. In that case, a correction
9193 + * term is need. Let u=1+x rounded. Let c = (1+x)-u, then
9194 + * log(1+x) - log(u) ~ c/u. Thus, we proceed to compute log(u),
9195 + * and add back the correction term c/u.
9196 + * (Note: when x > 2**53, one can simply return log(x))
9198 + * 2. Approximation of log1p(f).
9199 + * Let s = f/(2+f) ; based on log(1+f) = log(1+s) - log(1-s)
9200 + * = 2s + 2/3 s**3 + 2/5 s**5 + .....,
9201 + * = 2s + s*R
9202 + * We use a special Reme algorithm on [0,0.1716] to generate
9203 + * a polynomial of degree 14 to approximate R The maximum error
9204 + * of this polynomial approximation is bounded by 2**-58.45. In
9205 + * other words,
9206 + * 2 4 6 8 10 12 14
9207 + * R(z) ~ Lp1*s +Lp2*s +Lp3*s +Lp4*s +Lp5*s +Lp6*s +Lp7*s
9208 + * (the values of Lp1 to Lp7 are listed in the program)
9209 + * and
9210 + * | 2 14 | -58.45
9211 + * | Lp1*s +...+Lp7*s - R(z) | <= 2
9212 + * | |
9213 + * Note that 2s = f - s*f = f - hfsq + s*hfsq, where hfsq = f*f/2.
9214 + * In order to guarantee error in log below 1ulp, we compute log
9215 + * by
9216 + * log1p(f) = f - (hfsq - s*(hfsq+R)).
9218 + * 3. Finally, log1p(x) = k*ln2 + log1p(f).
9219 + * = k*ln2_hi+(f-(hfsq-(s*(hfsq+R)+k*ln2_lo)))
9220 + * Here ln2 is split into two floating point number:
9221 + * ln2_hi + ln2_lo,
9222 + * where n*ln2_hi is always exact for |n| < 2000.
9224 + * Special cases:
9225 + * log1p(x) is NaN with signal if x < -1 (including -INF) ;
9226 + * log1p(+INF) is +INF; log1p(-1) is -INF with signal;
9227 + * log1p(NaN) is that NaN with no signal.
9229 + * Accuracy:
9230 + * according to an error analysis, the error is always less than
9231 + * 1 ulp (unit in the last place).
9233 + * Constants:
9234 + * The hexadecimal values are the intended ones for the following
9235 + * constants. The decimal values may be used, provided that the
9236 + * compiler will convert from decimal to binary accurately enough
9237 + * to produce the hexadecimal values shown.
9239 + * Note: Assuming log() return accurate answer, the following
9240 + * algorithm can be used to compute log1p(x) to within a few ULP:
9242 + * u = 1+x;
9243 + * if(u==1.0) return x ; else
9244 + * return log(u)*(x/(u-1.0));
9246 + * See HP-15C Advanced Functions Handbook, p.193.
9247 + */
9249 +#include "math.h"
9250 +#include "math_private.h"
9252 +#ifdef __STDC__
9253 +static const double
9254 +#else
9255 +static double
9256 +#endif
9257 +ln2_hi = 6.93147180369123816490e-01, /* 3fe62e42 fee00000 */
9258 +ln2_lo = 1.90821492927058770002e-10, /* 3dea39ef 35793c76 */
9259 +two54 = 1.80143985094819840000e+16, /* 43500000 00000000 */
9260 +Lp1 = 6.666666666666735130e-01, /* 3FE55555 55555593 */
9261 +Lp2 = 3.999999999940941908e-01, /* 3FD99999 9997FA04 */
9262 +Lp3 = 2.857142874366239149e-01, /* 3FD24924 94229359 */
9263 +Lp4 = 2.222219843214978396e-01, /* 3FCC71C5 1D8E78AF */
9264 +Lp5 = 1.818357216161805012e-01, /* 3FC74664 96CB03DE */
9265 +Lp6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */
9266 +Lp7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */
9268 +#ifdef __STDC__
9269 +static const double zero = 0.0;
9270 +#else
9271 +static double zero = 0.0;
9272 +#endif
9274 +#ifdef __STDC__
9275 + double log1p(double x)
9276 +#else
9277 + double log1p(x)
9278 + double x;
9279 +#endif
9281 + double hfsq,f=0,c=0,s,z,R,u;
9282 + int32_t k,hx,hu=0,ax;
9284 + GET_HIGH_WORD(hx,x);
9285 + ax = hx&0x7fffffff;
9287 + k = 1;
9288 + if (hx < 0x3FDA827A) { /* x < 0.41422 */
9289 + if(ax>=0x3ff00000) { /* x <= -1.0 */
9290 + if(x==-1.0) return -two54/zero; /* log1p(-1)=+inf */
9291 + else return (x-x)/(x-x); /* log1p(x<-1)=NaN */
9293 + if(ax<0x3e200000) { /* |x| < 2**-29 */
9294 + if(two54+x>zero /* raise inexact */
9295 + &&ax<0x3c900000) /* |x| < 2**-54 */
9296 + return x;
9297 + else
9298 + return x - x*x*0.5;
9300 + if(hx>0||hx<=((int32_t)0xbfd2bec3)) {
9301 + k=0;f=x;hu=1;} /* -0.2929<x<0.41422 */
9303 + if (hx >= 0x7ff00000) return x+x;
9304 + if(k!=0) {
9305 + if(hx<0x43400000) {
9306 + u = 1.0+x;
9307 + GET_HIGH_WORD(hu,u);
9308 + k = (hu>>20)-1023;
9309 + c = (k>0)? 1.0-(u-x):x-(u-1.0);/* correction term */
9310 + c /= u;
9311 + } else {
9312 + u = x;
9313 + GET_HIGH_WORD(hu,u);
9314 + k = (hu>>20)-1023;
9315 + c = 0;
9317 + hu &= 0x000fffff;
9318 + if(hu<0x6a09e) {
9319 + SET_HIGH_WORD(u,hu|0x3ff00000); /* normalize u */
9320 + } else {
9321 + k += 1;
9322 + SET_HIGH_WORD(u,hu|0x3fe00000); /* normalize u/2 */
9323 + hu = (0x00100000-hu)>>2;
9325 + f = u-1.0;
9327 + hfsq=0.5*f*f;
9328 + if(hu==0) { /* |f| < 2**-20 */
9329 + if(f==zero) {if(k==0) return zero;
9330 + else {c += k*ln2_lo; return k*ln2_hi+c;}
9332 + R = hfsq*(1.0-0.66666666666666666*f);
9333 + if(k==0) return f-R; else
9334 + return k*ln2_hi-((R-(k*ln2_lo+c))-f);
9336 + s = f/(2.0+f);
9337 + z = s*s;
9338 + R = z*(Lp1+z*(Lp2+z*(Lp3+z*(Lp4+z*(Lp5+z*(Lp6+z*Lp7))))));
9339 + if(k==0) return f-(hfsq-s*(hfsq+R)); else
9340 + return k*ln2_hi-((hfsq-(s*(hfsq+R)+(k*ln2_lo+c)))-f);
9342 diff -urN dietlibc-0.30/libm/s_logb.c dietlibc-0.30-libm/libm/s_logb.c
9343 --- dietlibc-0.30/libm/s_logb.c 1970-01-01 00:00:00.000000000 +0000
9344 +++ dietlibc-0.30-libm/libm/s_logb.c 2006-06-25 11:20:20.000000000 +0000
9345 @@ -0,0 +1,42 @@
9346 +/* @(#)s_logb.c 5.1 93/09/24 */
9348 + * ====================================================
9349 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
9351 + * Developed at SunPro, a Sun Microsystems, Inc. business.
9352 + * Permission to use, copy, modify, and distribute this
9353 + * software is freely granted, provided that this notice
9354 + * is preserved.
9355 + * ====================================================
9356 + */
9358 +#if defined(LIBM_SCCS) && !defined(lint)
9359 +static char rcsid[] = "$NetBSD: s_logb.c,v 1.8 1995/05/10 20:47:50 jtc Exp $";
9360 +#endif
9363 + * double logb(x)
9364 + * IEEE 754 logb. Included to pass IEEE test suite. Not recommend.
9365 + * Use ilogb instead.
9366 + */
9368 +#include "math.h"
9369 +#include "math_private.h"
9371 +#ifdef __STDC__
9372 + double logb(double x)
9373 +#else
9374 + double logb(x)
9375 + double x;
9376 +#endif
9378 + int32_t lx,ix;
9379 + EXTRACT_WORDS(ix,lx,x);
9380 + ix &= 0x7fffffff; /* high |x| */
9381 + if((ix|lx)==0) return -1.0/fabs(x);
9382 + if(ix>=0x7ff00000) return x*x;
9383 + if((ix>>=20)==0) /* IEEE 754 logb */
9384 + return -1022.0;
9385 + else
9386 + return (double) (ix-1023);
9388 diff -urN dietlibc-0.30/libm/s_matherr.c dietlibc-0.30-libm/libm/s_matherr.c
9389 --- dietlibc-0.30/libm/s_matherr.c 1970-01-01 00:00:00.000000000 +0000
9390 +++ dietlibc-0.30-libm/libm/s_matherr.c 2006-06-25 11:20:08.000000000 +0000
9391 @@ -0,0 +1,30 @@
9392 +/* @(#)s_matherr.c 5.1 93/09/24 */
9394 + * ====================================================
9395 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
9397 + * Developed at SunPro, a Sun Microsystems, Inc. business.
9398 + * Permission to use, copy, modify, and distribute this
9399 + * software is freely granted, provided that this notice
9400 + * is preserved.
9401 + * ====================================================
9402 + */
9404 +#if defined(LIBM_SCCS) && !defined(lint)
9405 +static char rcsid[] = "$NetBSD: s_matherr.c,v 1.6 1995/05/10 20:47:53 jtc Exp $";
9406 +#endif
9408 +#include "math.h"
9409 +#include "math_private.h"
9411 +#ifdef __STDC__
9412 + int matherr(struct exception *x)
9413 +#else
9414 + int matherr(x)
9415 + struct exception *x;
9416 +#endif
9418 + int n=0;
9419 + if(x->arg1!=x->arg1) return 0;
9420 + return n;
9422 diff -urN dietlibc-0.30/libm/s_modf.c dietlibc-0.30-libm/libm/s_modf.c
9423 --- dietlibc-0.30/libm/s_modf.c 1970-01-01 00:00:00.000000000 +0000
9424 +++ dietlibc-0.30-libm/libm/s_modf.c 2006-06-25 11:20:21.000000000 +0000
9425 @@ -0,0 +1,83 @@
9426 +/* @(#)s_modf.c 5.1 93/09/24 */
9428 + * ====================================================
9429 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
9431 + * Developed at SunPro, a Sun Microsystems, Inc. business.
9432 + * Permission to use, copy, modify, and distribute this
9433 + * software is freely granted, provided that this notice
9434 + * is preserved.
9435 + * ====================================================
9436 + */
9438 +#if defined(LIBM_SCCS) && !defined(lint)
9439 +static char rcsid[] = "$NetBSD: s_modf.c,v 1.8 1995/05/10 20:47:55 jtc Exp $";
9440 +#endif
9443 + * modf(double x, double *iptr)
9444 + * return fraction part of x, and return x's integral part in *iptr.
9445 + * Method:
9446 + * Bit twiddling.
9448 + * Exception:
9449 + * No exception.
9450 + */
9452 +#include "math.h"
9453 +#include "math_private.h"
9455 +#ifdef __STDC__
9456 +static const double one = 1.0;
9457 +#else
9458 +static double one = 1.0;
9459 +#endif
9461 +#ifdef __STDC__
9462 + double modf(double x, double *iptr)
9463 +#else
9464 + double modf(x, iptr)
9465 + double x,*iptr;
9466 +#endif
9468 + int32_t i0,i1,j0;
9469 + u_int32_t i;
9470 + EXTRACT_WORDS(i0,i1,x);
9471 + j0 = ((i0>>20)&0x7ff)-0x3ff; /* exponent of x */
9472 + if(j0<20) { /* integer part in high x */
9473 + if(j0<0) { /* |x|<1 */
9474 + INSERT_WORDS(*iptr,i0&0x80000000,0); /* *iptr = +-0 */
9475 + return x;
9476 + } else {
9477 + i = (0x000fffff)>>j0;
9478 + if(((i0&i)|i1)==0) { /* x is integral */
9479 + u_int32_t high;
9480 + *iptr = x;
9481 + GET_HIGH_WORD(high,x);
9482 + INSERT_WORDS(x,high&0x80000000,0); /* return +-0 */
9483 + return x;
9484 + } else {
9485 + INSERT_WORDS(*iptr,i0&(~i),0);
9486 + return x - *iptr;
9489 + } else if (j0>51) { /* no fraction part */
9490 + u_int32_t high;
9491 + *iptr = x*one;
9492 + GET_HIGH_WORD(high,x);
9493 + INSERT_WORDS(x,high&0x80000000,0); /* return +-0 */
9494 + return x;
9495 + } else { /* fraction part in low x */
9496 + i = ((u_int32_t)(0xffffffff))>>(j0-20);
9497 + if((i1&i)==0) { /* x is integral */
9498 + u_int32_t high;
9499 + *iptr = x;
9500 + GET_HIGH_WORD(high,x);
9501 + INSERT_WORDS(x,high&0x80000000,0); /* return +-0 */
9502 + return x;
9503 + } else {
9504 + INSERT_WORDS(*iptr,i0,i1&(~i));
9505 + return x - *iptr;
9509 diff -urN dietlibc-0.30/libm/s_nextafter.c dietlibc-0.30-libm/libm/s_nextafter.c
9510 --- dietlibc-0.30/libm/s_nextafter.c 1970-01-01 00:00:00.000000000 +0000
9511 +++ dietlibc-0.30-libm/libm/s_nextafter.c 2006-06-25 11:20:08.000000000 +0000
9512 @@ -0,0 +1,79 @@
9513 +/* @(#)s_nextafter.c 5.1 93/09/24 */
9515 + * ====================================================
9516 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
9518 + * Developed at SunPro, a Sun Microsystems, Inc. business.
9519 + * Permission to use, copy, modify, and distribute this
9520 + * software is freely granted, provided that this notice
9521 + * is preserved.
9522 + * ====================================================
9523 + */
9525 +#if defined(LIBM_SCCS) && !defined(lint)
9526 +static char rcsid[] = "$NetBSD: s_nextafter.c,v 1.8 1995/05/10 20:47:58 jtc Exp $";
9527 +#endif
9529 +/* IEEE functions
9530 + * nextafter(x,y)
9531 + * return the next machine floating-point number of x in the
9532 + * direction toward y.
9533 + * Special cases:
9534 + */
9536 +#include "math.h"
9537 +#include "math_private.h"
9539 +#ifdef __STDC__
9540 + double nextafter(double x, double y)
9541 +#else
9542 + double nextafter(x,y)
9543 + double x,y;
9544 +#endif
9546 + int32_t hx,hy,ix,iy;
9547 + u_int32_t lx,ly;
9549 + EXTRACT_WORDS(hx,lx,x);
9550 + EXTRACT_WORDS(hy,ly,y);
9551 + ix = hx&0x7fffffff; /* |x| */
9552 + iy = hy&0x7fffffff; /* |y| */
9554 + if(((ix>=0x7ff00000)&&((ix-0x7ff00000)|lx)!=0) || /* x is nan */
9555 + ((iy>=0x7ff00000)&&((iy-0x7ff00000)|ly)!=0)) /* y is nan */
9556 + return x+y;
9557 + if(x==y) return x; /* x=y, return x */
9558 + if((ix|lx)==0) { /* x == 0 */
9559 + INSERT_WORDS(x,hy&0x80000000,1); /* return +-minsubnormal */
9560 + y = x*x;
9561 + if(y==x) return y; else return x; /* raise underflow flag */
9563 + if(hx>=0) { /* x > 0 */
9564 + if(hx>hy||((hx==hy)&&(lx>ly))) { /* x > y, x -= ulp */
9565 + if(lx==0) hx -= 1;
9566 + lx -= 1;
9567 + } else { /* x < y, x += ulp */
9568 + lx += 1;
9569 + if(lx==0) hx += 1;
9571 + } else { /* x < 0 */
9572 + if(hy>=0||hx>hy||((hx==hy)&&(lx>ly))){/* x < y, x -= ulp */
9573 + if(lx==0) hx -= 1;
9574 + lx -= 1;
9575 + } else { /* x > y, x += ulp */
9576 + lx += 1;
9577 + if(lx==0) hx += 1;
9580 + hy = hx&0x7ff00000;
9581 + if(hy>=0x7ff00000) return x+x; /* overflow */
9582 + if(hy<0x00100000) { /* underflow */
9583 + y = x*x;
9584 + if(y!=x) { /* raise underflow flag */
9585 + INSERT_WORDS(y,hx,lx);
9586 + return y;
9589 + INSERT_WORDS(x,hx,lx);
9590 + return x;
9592 diff -urN dietlibc-0.30/libm/s_rint.c dietlibc-0.30-libm/libm/s_rint.c
9593 --- dietlibc-0.30/libm/s_rint.c 1970-01-01 00:00:00.000000000 +0000
9594 +++ dietlibc-0.30-libm/libm/s_rint.c 2006-06-25 11:20:22.000000000 +0000
9595 @@ -0,0 +1,86 @@
9596 +/* @(#)s_rint.c 5.1 93/09/24 */
9598 + * ====================================================
9599 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
9601 + * Developed at SunPro, a Sun Microsystems, Inc. business.
9602 + * Permission to use, copy, modify, and distribute this
9603 + * software is freely granted, provided that this notice
9604 + * is preserved.
9605 + * ====================================================
9606 + */
9608 +#if defined(LIBM_SCCS) && !defined(lint)
9609 +static char rcsid[] = "$NetBSD: s_rint.c,v 1.8 1995/05/10 20:48:04 jtc Exp $";
9610 +#endif
9613 + * rint(x)
9614 + * Return x rounded to integral value according to the prevailing
9615 + * rounding mode.
9616 + * Method:
9617 + * Using floating addition.
9618 + * Exception:
9619 + * Inexact flag raised if x not equal to rint(x).
9620 + */
9622 +#include "math.h"
9623 +#include "math_private.h"
9625 +#ifdef __STDC__
9626 +static const double
9627 +#else
9628 +static double
9629 +#endif
9630 +TWO52[2]={
9631 + 4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
9632 + -4.50359962737049600000e+15, /* 0xC3300000, 0x00000000 */
9635 +#ifdef __STDC__
9636 + double rint(double x)
9637 +#else
9638 + double rint(x)
9639 + double x;
9640 +#endif
9642 + int32_t i0,j0,sx;
9643 + u_int32_t i,i1;
9644 + double w,t;
9645 + EXTRACT_WORDS(i0,i1,x);
9646 + sx = (i0>>31)&1;
9647 + j0 = ((i0>>20)&0x7ff)-0x3ff;
9648 + if(j0<20) {
9649 + if(j0<0) {
9650 + if(((i0&0x7fffffff)|i1)==0) return x;
9651 + i1 |= (i0&0x0fffff);
9652 + i0 &= 0xfffe0000;
9653 + i0 |= ((i1|-i1)>>12)&0x80000;
9654 + SET_HIGH_WORD(x,i0);
9655 + w = TWO52[sx]+x;
9656 + t = w-TWO52[sx];
9657 + GET_HIGH_WORD(i0,t);
9658 + SET_HIGH_WORD(t,(i0&0x7fffffff)|(sx<<31));
9659 + return t;
9660 + } else {
9661 + i = (0x000fffff)>>j0;
9662 + if(((i0&i)|i1)==0) return x; /* x is integral */
9663 + i>>=1;
9664 + if(((i0&i)|i1)!=0) {
9665 + if(j0==19) i1 = 0x40000000; else
9666 + i0 = (i0&(~i))|((0x20000)>>j0);
9669 + } else if (j0>51) {
9670 + if(j0==0x400) return x+x; /* inf or NaN */
9671 + else return x; /* x is integral */
9672 + } else {
9673 + i = ((u_int32_t)(0xffffffff))>>(j0-20);
9674 + if((i1&i)==0) return x; /* x is integral */
9675 + i>>=1;
9676 + if((i1&i)!=0) i1 = (i1&(~i))|((0x40000000)>>(j0-20));
9678 + INSERT_WORDS(x,i0,i1);
9679 + w = TWO52[sx]+x;
9680 + return w-TWO52[sx];
9682 diff -urN dietlibc-0.30/libm/s_scalbn.c dietlibc-0.30-libm/libm/s_scalbn.c
9683 --- dietlibc-0.30/libm/s_scalbn.c 1970-01-01 00:00:00.000000000 +0000
9684 +++ dietlibc-0.30-libm/libm/s_scalbn.c 2006-06-25 11:20:21.000000000 +0000
9685 @@ -0,0 +1,67 @@
9686 +/* @(#)s_scalbn.c 5.1 93/09/24 */
9688 + * ====================================================
9689 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
9691 + * Developed at SunPro, a Sun Microsystems, Inc. business.
9692 + * Permission to use, copy, modify, and distribute this
9693 + * software is freely granted, provided that this notice
9694 + * is preserved.
9695 + * ====================================================
9696 + */
9698 +#if defined(LIBM_SCCS) && !defined(lint)
9699 +static char rcsid[] = "$NetBSD: s_scalbn.c,v 1.8 1995/05/10 20:48:08 jtc Exp $";
9700 +#endif
9703 + * scalbn (double x, int n)
9704 + * scalbn(x,n) returns x* 2**n computed by exponent
9705 + * manipulation rather than by actually performing an
9706 + * exponentiation or a multiplication.
9707 + */
9709 +#include "math.h"
9710 +#include "math_private.h"
9712 +#ifdef __STDC__
9713 +static const double
9714 +#else
9715 +static double
9716 +#endif
9717 +two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */
9718 +twom54 = 5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */
9719 +huge = 1.0e+300,
9720 +tiny = 1.0e-300;
9722 +#ifdef __STDC__
9723 + double scalbn (double x, int n)
9724 +#else
9725 + double scalbn (x,n)
9726 + double x; int n;
9727 +#endif
9729 + int32_t k,hx,lx;
9730 + EXTRACT_WORDS(hx,lx,x);
9731 + k = (hx&0x7ff00000)>>20; /* extract exponent */
9732 + if (k==0) { /* 0 or subnormal x */
9733 + if ((lx|(hx&0x7fffffff))==0) return x; /* +-0 */
9734 + x *= two54;
9735 + GET_HIGH_WORD(hx,x);
9736 + k = ((hx&0x7ff00000)>>20) - 54;
9737 + if (n< -50000) return tiny*x; /*underflow*/
9739 + if (k==0x7ff) return x+x; /* NaN or Inf */
9740 + k = k+n;
9741 + if (k > 0x7fe) return huge*copysign(huge,x); /* overflow */
9742 + if (k > 0) /* normal result */
9743 + {SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20)); return x;}
9744 + if (k <= -54) {
9745 + if (n > 50000) /* in case integer overflow in n+k */
9746 + return huge*copysign(huge,x); /*overflow*/
9747 + else return tiny*copysign(tiny,x); /*underflow*/
9749 + k += 54; /* subnormal result */
9750 + SET_HIGH_WORD(x,(hx&0x800fffff)|(k<<20));
9751 + return x*twom54;
9753 diff -urN dietlibc-0.30/libm/s_signgam.c dietlibc-0.30-libm/libm/s_signgam.c
9754 --- dietlibc-0.30/libm/s_signgam.c 1970-01-01 00:00:00.000000000 +0000
9755 +++ dietlibc-0.30-libm/libm/s_signgam.c 2006-06-25 11:20:20.000000000 +0000
9756 @@ -0,0 +1,3 @@
9757 +#include "math.h"
9758 +#include "math_private.h"
9759 +int signgam = 0;
9760 diff -urN dietlibc-0.30/libm/s_significand.c dietlibc-0.30-libm/libm/s_significand.c
9761 --- dietlibc-0.30/libm/s_significand.c 1970-01-01 00:00:00.000000000 +0000
9762 +++ dietlibc-0.30-libm/libm/s_significand.c 2006-06-25 11:19:59.000000000 +0000
9763 @@ -0,0 +1,34 @@
9764 +/* @(#)s_signif.c 5.1 93/09/24 */
9766 + * ====================================================
9767 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
9769 + * Developed at SunPro, a Sun Microsystems, Inc. business.
9770 + * Permission to use, copy, modify, and distribute this
9771 + * software is freely granted, provided that this notice
9772 + * is preserved.
9773 + * ====================================================
9774 + */
9776 +#if defined(LIBM_SCCS) && !defined(lint)
9777 +static char rcsid[] = "$NetBSD: s_significand.c,v 1.6 1995/05/10 20:48:11 jtc Exp $";
9778 +#endif
9781 + * significand(x) computes just
9782 + * scalb(x, (double) -ilogb(x)),
9783 + * for exercising the fraction-part(F) IEEE 754-1985 test vector.
9784 + */
9786 +#include "math.h"
9787 +#include "math_private.h"
9789 +#ifdef __STDC__
9790 + double significand(double x)
9791 +#else
9792 + double significand(x)
9793 + double x;
9794 +#endif
9796 + return __ieee754_scalb(x,(double) -ilogb(x));
9798 diff -urN dietlibc-0.30/libm/s_sin.c dietlibc-0.30-libm/libm/s_sin.c
9799 --- dietlibc-0.30/libm/s_sin.c 1970-01-01 00:00:00.000000000 +0000
9800 +++ dietlibc-0.30-libm/libm/s_sin.c 2006-06-25 11:20:05.000000000 +0000
9801 @@ -0,0 +1,82 @@
9802 +/* @(#)s_sin.c 5.1 93/09/24 */
9804 + * ====================================================
9805 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
9807 + * Developed at SunPro, a Sun Microsystems, Inc. business.
9808 + * Permission to use, copy, modify, and distribute this
9809 + * software is freely granted, provided that this notice
9810 + * is preserved.
9811 + * ====================================================
9812 + */
9814 +#if defined(LIBM_SCCS) && !defined(lint)
9815 +static char rcsid[] = "$NetBSD: s_sin.c,v 1.7 1995/05/10 20:48:15 jtc Exp $";
9816 +#endif
9818 +/* sin(x)
9819 + * Return sine function of x.
9821 + * kernel function:
9822 + * __kernel_sin ... sine function on [-pi/4,pi/4]
9823 + * __kernel_cos ... cose function on [-pi/4,pi/4]
9824 + * __ieee754_rem_pio2 ... argument reduction routine
9826 + * Method.
9827 + * Let S,C and T denote the sin, cos and tan respectively on
9828 + * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
9829 + * in [-pi/4 , +pi/4], and let n = k mod 4.
9830 + * We have
9832 + * n sin(x) cos(x) tan(x)
9833 + * ----------------------------------------------------------
9834 + * 0 S C T
9835 + * 1 C -S -1/T
9836 + * 2 -S -C T
9837 + * 3 -C S -1/T
9838 + * ----------------------------------------------------------
9840 + * Special cases:
9841 + * Let trig be any of sin, cos, or tan.
9842 + * trig(+-INF) is NaN, with signals;
9843 + * trig(NaN) is that NaN;
9845 + * Accuracy:
9846 + * TRIG(x) returns trig(x) nearly rounded
9847 + */
9849 +#include "math.h"
9850 +#include "math_private.h"
9852 +#ifdef __STDC__
9853 + double sin(double x)
9854 +#else
9855 + double sin(x)
9856 + double x;
9857 +#endif
9859 + double y[2],z=0.0;
9860 + int32_t n, ix;
9862 + /* High word of x. */
9863 + GET_HIGH_WORD(ix,x);
9865 + /* |x| ~< pi/4 */
9866 + ix &= 0x7fffffff;
9867 + if(ix <= 0x3fe921fb) return __kernel_sin(x,z,0);
9869 + /* sin(Inf or NaN) is NaN */
9870 + else if (ix>=0x7ff00000) return x-x;
9872 + /* argument reduction needed */
9873 + else {
9874 + n = __ieee754_rem_pio2(x,y);
9875 + switch(n&3) {
9876 + case 0: return __kernel_sin(y[0],y[1],1);
9877 + case 1: return __kernel_cos(y[0],y[1]);
9878 + case 2: return -__kernel_sin(y[0],y[1],1);
9879 + default:
9880 + return -__kernel_cos(y[0],y[1]);
9884 diff -urN dietlibc-0.30/libm/s_tan.c dietlibc-0.30-libm/libm/s_tan.c
9885 --- dietlibc-0.30/libm/s_tan.c 1970-01-01 00:00:00.000000000 +0000
9886 +++ dietlibc-0.30-libm/libm/s_tan.c 2006-06-25 11:20:06.000000000 +0000
9887 @@ -0,0 +1,76 @@
9888 +/* @(#)s_tan.c 5.1 93/09/24 */
9890 + * ====================================================
9891 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
9893 + * Developed at SunPro, a Sun Microsystems, Inc. business.
9894 + * Permission to use, copy, modify, and distribute this
9895 + * software is freely granted, provided that this notice
9896 + * is preserved.
9897 + * ====================================================
9898 + */
9900 +#if defined(LIBM_SCCS) && !defined(lint)
9901 +static char rcsid[] = "$NetBSD: s_tan.c,v 1.7 1995/05/10 20:48:18 jtc Exp $";
9902 +#endif
9904 +/* tan(x)
9905 + * Return tangent function of x.
9907 + * kernel function:
9908 + * __kernel_tan ... tangent function on [-pi/4,pi/4]
9909 + * __ieee754_rem_pio2 ... argument reduction routine
9911 + * Method.
9912 + * Let S,C and T denote the sin, cos and tan respectively on
9913 + * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
9914 + * in [-pi/4 , +pi/4], and let n = k mod 4.
9915 + * We have
9917 + * n sin(x) cos(x) tan(x)
9918 + * ----------------------------------------------------------
9919 + * 0 S C T
9920 + * 1 C -S -1/T
9921 + * 2 -S -C T
9922 + * 3 -C S -1/T
9923 + * ----------------------------------------------------------
9925 + * Special cases:
9926 + * Let trig be any of sin, cos, or tan.
9927 + * trig(+-INF) is NaN, with signals;
9928 + * trig(NaN) is that NaN;
9930 + * Accuracy:
9931 + * TRIG(x) returns trig(x) nearly rounded
9932 + */
9934 +#include "math.h"
9935 +#include "math_private.h"
9937 +#ifdef __STDC__
9938 + double tan(double x)
9939 +#else
9940 + double tan(x)
9941 + double x;
9942 +#endif
9944 + double y[2],z=0.0;
9945 + int32_t n, ix;
9947 + /* High word of x. */
9948 + GET_HIGH_WORD(ix,x);
9950 + /* |x| ~< pi/4 */
9951 + ix &= 0x7fffffff;
9952 + if(ix <= 0x3fe921fb) return __kernel_tan(x,z,1);
9954 + /* tan(Inf or NaN) is NaN */
9955 + else if (ix>=0x7ff00000) return x-x; /* NaN */
9957 + /* argument reduction needed */
9958 + else {
9959 + n = __ieee754_rem_pio2(x,y);
9960 + return __kernel_tan(y[0],y[1],1-((n&1)<<1)); /* 1 -- n even
9961 + -1 -- n odd */
9964 diff -urN dietlibc-0.30/libm/s_tanh.c dietlibc-0.30-libm/libm/s_tanh.c
9965 --- dietlibc-0.30/libm/s_tanh.c 1970-01-01 00:00:00.000000000 +0000
9966 +++ dietlibc-0.30-libm/libm/s_tanh.c 2006-06-25 11:20:22.000000000 +0000
9967 @@ -0,0 +1,86 @@
9968 +/* @(#)s_tanh.c 5.1 93/09/24 */
9970 + * ====================================================
9971 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
9973 + * Developed at SunPro, a Sun Microsystems, Inc. business.
9974 + * Permission to use, copy, modify, and distribute this
9975 + * software is freely granted, provided that this notice
9976 + * is preserved.
9977 + * ====================================================
9978 + */
9980 +#if defined(LIBM_SCCS) && !defined(lint)
9981 +static char rcsid[] = "$NetBSD: s_tanh.c,v 1.7 1995/05/10 20:48:22 jtc Exp $";
9982 +#endif
9984 +/* Tanh(x)
9985 + * Return the Hyperbolic Tangent of x
9987 + * Method :
9988 + * x -x
9989 + * e - e
9990 + * 0. tanh(x) is defined to be -----------
9991 + * x -x
9992 + * e + e
9993 + * 1. reduce x to non-negative by tanh(-x) = -tanh(x).
9994 + * 2. 0 <= x <= 2**-55 : tanh(x) := x*(one+x)
9995 + * -t
9996 + * 2**-55 < x <= 1 : tanh(x) := -----; t = expm1(-2x)
9997 + * t + 2
9998 + * 2
9999 + * 1 <= x <= 22.0 : tanh(x) := 1- ----- ; t=expm1(2x)
10000 + * t + 2
10001 + * 22.0 < x <= INF : tanh(x) := 1.
10003 + * Special cases:
10004 + * tanh(NaN) is NaN;
10005 + * only tanh(0)=0 is exact for finite argument.
10006 + */
10008 +#include "math.h"
10009 +#include "math_private.h"
10011 +#ifdef __STDC__
10012 +static const double one=1.0, two=2.0, tiny = 1.0e-300;
10013 +#else
10014 +static double one=1.0, two=2.0, tiny = 1.0e-300;
10015 +#endif
10017 +#ifdef __STDC__
10018 + double tanh(double x)
10019 +#else
10020 + double tanh(x)
10021 + double x;
10022 +#endif
10024 + double t,z;
10025 + int32_t jx,ix;
10027 + /* High word of |x|. */
10028 + GET_HIGH_WORD(jx,x);
10029 + ix = jx&0x7fffffff;
10031 + /* x is INF or NaN */
10032 + if(ix>=0x7ff00000) {
10033 + if (jx>=0) return one/x+one; /* tanh(+-inf)=+-1 */
10034 + else return one/x-one; /* tanh(NaN) = NaN */
10037 + /* |x| < 22 */
10038 + if (ix < 0x40360000) { /* |x|<22 */
10039 + if (ix<0x3c800000) /* |x|<2**-55 */
10040 + return x*(one+x); /* tanh(small) = small */
10041 + if (ix>=0x3ff00000) { /* |x|>=1 */
10042 + t = expm1(two*fabs(x));
10043 + z = one - two/(t+two);
10044 + } else {
10045 + t = expm1(-two*fabs(x));
10046 + z= -t/(t+two);
10048 + /* |x| > 22, return +-1 */
10049 + } else {
10050 + z = one - tiny; /* raised inexact flag */
10052 + return (jx>=0)? z: -z;
10054 diff -urN dietlibc-0.30/libm/sinh.c dietlibc-0.30-libm/libm/sinh.c
10055 --- dietlibc-0.30/libm/sinh.c 2001-07-27 20:30:34.000000000 +0000
10056 +++ dietlibc-0.30-libm/libm/sinh.c 1970-01-01 00:00:00.000000000 +0000
10057 @@ -1,9 +0,0 @@
10058 -#include <math.h>
10060 -extern const float __half;
10062 -double sinh ( double x )
10064 - long double y = exp (x);
10065 - return (y - 1./y) * __half;
10067 diff -urN dietlibc-0.30/libm/tanh.c dietlibc-0.30-libm/libm/tanh.c
10068 --- dietlibc-0.30/libm/tanh.c 2001-07-27 20:30:34.000000000 +0000
10069 +++ dietlibc-0.30-libm/libm/tanh.c 1970-01-01 00:00:00.000000000 +0000
10070 @@ -1,7 +0,0 @@
10071 -#include <math.h>
10073 -double tanh ( double x )
10075 - long double y = exp (x + x);
10076 - return (y - 1.) / (y + 1.);
10078 diff -urN dietlibc-0.30/libm/w_acos.c dietlibc-0.30-libm/libm/w_acos.c
10079 --- dietlibc-0.30/libm/w_acos.c 1970-01-01 00:00:00.000000000 +0000
10080 +++ dietlibc-0.30-libm/libm/w_acos.c 2006-06-25 11:19:58.000000000 +0000
10081 @@ -0,0 +1,43 @@
10082 +/* @(#)w_acos.c 5.1 93/09/24 */
10084 + * ====================================================
10085 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
10087 + * Developed at SunPro, a Sun Microsystems, Inc. business.
10088 + * Permission to use, copy, modify, and distribute this
10089 + * software is freely granted, provided that this notice
10090 + * is preserved.
10091 + * ====================================================
10092 + */
10094 +#if defined(LIBM_SCCS) && !defined(lint)
10095 +static char rcsid[] = "$NetBSD: w_acos.c,v 1.6 1995/05/10 20:48:26 jtc Exp $";
10096 +#endif
10099 + * wrap_acos(x)
10100 + */
10102 +#include "math.h"
10103 +#include "math_private.h"
10106 +#ifdef __STDC__
10107 + double acos(double x) /* wrapper acos */
10108 +#else
10109 + double acos(x) /* wrapper acos */
10110 + double x;
10111 +#endif
10113 +#ifdef _IEEE_LIBM
10114 + return __ieee754_acos(x);
10115 +#else
10116 + double z;
10117 + z = __ieee754_acos(x);
10118 + if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
10119 + if(fabs(x)>1.0) {
10120 + return __kernel_standard(x,x,1); /* acos(|x|>1) */
10121 + } else
10122 + return z;
10123 +#endif
10125 diff -urN dietlibc-0.30/libm/w_acosh.c dietlibc-0.30-libm/libm/w_acosh.c
10126 --- dietlibc-0.30/libm/w_acosh.c 1970-01-01 00:00:00.000000000 +0000
10127 +++ dietlibc-0.30-libm/libm/w_acosh.c 2006-06-25 11:20:01.000000000 +0000
10128 @@ -0,0 +1,42 @@
10129 +/* @(#)w_acosh.c 5.1 93/09/24 */
10131 + * ====================================================
10132 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
10134 + * Developed at SunPro, a Sun Microsystems, Inc. business.
10135 + * Permission to use, copy, modify, and distribute this
10136 + * software is freely granted, provided that this notice
10137 + * is preserved.
10138 + * ====================================================
10139 + */
10141 +#if defined(LIBM_SCCS) && !defined(lint)
10142 +static char rcsid[] = "$NetBSD: w_acosh.c,v 1.6 1995/05/10 20:48:31 jtc Exp $";
10143 +#endif
10146 + * wrapper acosh(x)
10147 + */
10149 +#include "math.h"
10150 +#include "math_private.h"
10152 +#ifdef __STDC__
10153 + double acosh(double x) /* wrapper acosh */
10154 +#else
10155 + double acosh(x) /* wrapper acosh */
10156 + double x;
10157 +#endif
10159 +#ifdef _IEEE_LIBM
10160 + return __ieee754_acosh(x);
10161 +#else
10162 + double z;
10163 + z = __ieee754_acosh(x);
10164 + if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
10165 + if(x<1.0) {
10166 + return __kernel_standard(x,x,29); /* acosh(x<1) */
10167 + } else
10168 + return z;
10169 +#endif
10171 diff -urN dietlibc-0.30/libm/w_asin.c dietlibc-0.30-libm/libm/w_asin.c
10172 --- dietlibc-0.30/libm/w_asin.c 1970-01-01 00:00:00.000000000 +0000
10173 +++ dietlibc-0.30-libm/libm/w_asin.c 2006-06-25 11:19:58.000000000 +0000
10174 @@ -0,0 +1,44 @@
10175 +/* @(#)w_asin.c 5.1 93/09/24 */
10177 + * ====================================================
10178 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
10180 + * Developed at SunPro, a Sun Microsystems, Inc. business.
10181 + * Permission to use, copy, modify, and distribute this
10182 + * software is freely granted, provided that this notice
10183 + * is preserved.
10184 + * ====================================================
10185 + */
10187 +#if defined(LIBM_SCCS) && !defined(lint)
10188 +static char rcsid[] = "$NetBSD: w_asin.c,v 1.6 1995/05/10 20:48:35 jtc Exp $";
10189 +#endif
10192 + * wrapper asin(x)
10193 + */
10196 +#include "math.h"
10197 +#include "math_private.h"
10200 +#ifdef __STDC__
10201 + double asin(double x) /* wrapper asin */
10202 +#else
10203 + double asin(x) /* wrapper asin */
10204 + double x;
10205 +#endif
10207 +#ifdef _IEEE_LIBM
10208 + return __ieee754_asin(x);
10209 +#else
10210 + double z;
10211 + z = __ieee754_asin(x);
10212 + if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
10213 + if(fabs(x)>1.0) {
10214 + return __kernel_standard(x,x,2); /* asin(|x|>1) */
10215 + } else
10216 + return z;
10217 +#endif
10219 diff -urN dietlibc-0.30/libm/w_atan2.c dietlibc-0.30-libm/libm/w_atan2.c
10220 --- dietlibc-0.30/libm/w_atan2.c 1970-01-01 00:00:00.000000000 +0000
10221 +++ dietlibc-0.30-libm/libm/w_atan2.c 2006-06-25 11:20:08.000000000 +0000
10222 @@ -0,0 +1,42 @@
10223 +/* @(#)w_atan2.c 5.1 93/09/24 */
10225 + * ====================================================
10226 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
10228 + * Developed at SunPro, a Sun Microsystems, Inc. business.
10229 + * Permission to use, copy, modify, and distribute this
10230 + * software is freely granted, provided that this notice
10231 + * is preserved.
10232 + * ====================================================
10233 + */
10235 +#if defined(LIBM_SCCS) && !defined(lint)
10236 +static char rcsid[] = "$NetBSD: w_atan2.c,v 1.6 1995/05/10 20:48:39 jtc Exp $";
10237 +#endif
10240 + * wrapper atan2(y,x)
10241 + */
10242 +#include "math.h"
10243 +#include "math_private.h"
10246 +#ifdef __STDC__
10247 + double atan2(double y, double x) /* wrapper atan2 */
10248 +#else
10249 + double atan2(y,x) /* wrapper atan2 */
10250 + double y,x;
10251 +#endif
10253 +#ifdef _IEEE_LIBM
10254 + return __ieee754_atan2(y,x);
10255 +#else
10256 + double z;
10257 + z = __ieee754_atan2(y,x);
10258 + if(_LIB_VERSION == _IEEE_||isnan(x)||isnan(y)) return z;
10259 + if(x==0.0&&y==0.0) {
10260 + return __kernel_standard(y,x,3); /* atan2(+-0,+-0) */
10261 + } else
10262 + return z;
10263 +#endif
10265 diff -urN dietlibc-0.30/libm/w_atanh.c dietlibc-0.30-libm/libm/w_atanh.c
10266 --- dietlibc-0.30/libm/w_atanh.c 1970-01-01 00:00:00.000000000 +0000
10267 +++ dietlibc-0.30-libm/libm/w_atanh.c 2006-06-25 11:20:09.000000000 +0000
10268 @@ -0,0 +1,47 @@
10269 +/* @(#)w_atanh.c 5.1 93/09/24 */
10271 + * ====================================================
10272 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
10274 + * Developed at SunPro, a Sun Microsystems, Inc. business.
10275 + * Permission to use, copy, modify, and distribute this
10276 + * software is freely granted, provided that this notice
10277 + * is preserved.
10278 + * ====================================================
10279 + */
10281 +#if defined(LIBM_SCCS) && !defined(lint)
10282 +static char rcsid[] = "$NetBSD: w_atanh.c,v 1.6 1995/05/10 20:48:43 jtc Exp $";
10283 +#endif
10286 + * wrapper atanh(x)
10287 + */
10289 +#include "math.h"
10290 +#include "math_private.h"
10293 +#ifdef __STDC__
10294 + double atanh(double x) /* wrapper atanh */
10295 +#else
10296 + double atanh(x) /* wrapper atanh */
10297 + double x;
10298 +#endif
10300 +#ifdef _IEEE_LIBM
10301 + return __ieee754_atanh(x);
10302 +#else
10303 + double z,y;
10304 + z = __ieee754_atanh(x);
10305 + if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
10306 + y = fabs(x);
10307 + if(y>=1.0) {
10308 + if(y>1.0)
10309 + return __kernel_standard(x,x,30); /* atanh(|x|>1) */
10310 + else
10311 + return __kernel_standard(x,x,31); /* atanh(|x|==1) */
10312 + } else
10313 + return z;
10314 +#endif
10316 diff -urN dietlibc-0.30/libm/w_cabs.c dietlibc-0.30-libm/libm/w_cabs.c
10317 --- dietlibc-0.30/libm/w_cabs.c 1970-01-01 00:00:00.000000000 +0000
10318 +++ dietlibc-0.30-libm/libm/w_cabs.c 2006-06-25 11:19:59.000000000 +0000
10319 @@ -0,0 +1,18 @@
10321 + * cabs() wrapper for hypot().
10323 + * Written by J.T. Conklin, <jtc@wimsey.com>
10324 + * Placed into the Public Domain, 1994.
10325 + */
10327 +#include <math.h>
10329 +struct complex {
10330 + double x;
10331 + double y;
10334 +double cabs(struct complex z)
10336 + return hypot(z.x, z.y);
10338 diff -urN dietlibc-0.30/libm/w_cosh.c dietlibc-0.30-libm/libm/w_cosh.c
10339 --- dietlibc-0.30/libm/w_cosh.c 1970-01-01 00:00:00.000000000 +0000
10340 +++ dietlibc-0.30-libm/libm/w_cosh.c 2006-06-25 11:19:59.000000000 +0000
10341 @@ -0,0 +1,42 @@
10342 +/* @(#)w_cosh.c 5.1 93/09/24 */
10344 + * ====================================================
10345 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
10347 + * Developed at SunPro, a Sun Microsystems, Inc. business.
10348 + * Permission to use, copy, modify, and distribute this
10349 + * software is freely granted, provided that this notice
10350 + * is preserved.
10351 + * ====================================================
10352 + */
10354 +#if defined(LIBM_SCCS) && !defined(lint)
10355 +static char rcsid[] = "$NetBSD: w_cosh.c,v 1.6 1995/05/10 20:48:47 jtc Exp $";
10356 +#endif
10359 + * wrapper cosh(x)
10360 + */
10362 +#include "math.h"
10363 +#include "math_private.h"
10365 +#ifdef __STDC__
10366 + double cosh(double x) /* wrapper cosh */
10367 +#else
10368 + double cosh(x) /* wrapper cosh */
10369 + double x;
10370 +#endif
10372 +#ifdef _IEEE_LIBM
10373 + return __ieee754_cosh(x);
10374 +#else
10375 + double z;
10376 + z = __ieee754_cosh(x);
10377 + if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
10378 + if(fabs(x)>7.10475860073943863426e+02) {
10379 + return __kernel_standard(x,x,5); /* cosh overflow */
10380 + } else
10381 + return z;
10382 +#endif
10384 diff -urN dietlibc-0.30/libm/w_drem.c dietlibc-0.30-libm/libm/w_drem.c
10385 --- dietlibc-0.30/libm/w_drem.c 1970-01-01 00:00:00.000000000 +0000
10386 +++ dietlibc-0.30-libm/libm/w_drem.c 2006-06-25 11:20:00.000000000 +0000
10387 @@ -0,0 +1,15 @@
10389 + * drem() wrapper for remainder().
10391 + * Written by J.T. Conklin, <jtc@wimsey.com>
10392 + * Placed into the Public Domain, 1994.
10393 + */
10395 +#include <math.h>
10397 +double
10398 +drem(x, y)
10399 + double x, y;
10401 + return remainder(x, y);
10403 diff -urN dietlibc-0.30/libm/w_exp.c dietlibc-0.30-libm/libm/w_exp.c
10404 --- dietlibc-0.30/libm/w_exp.c 1970-01-01 00:00:00.000000000 +0000
10405 +++ dietlibc-0.30-libm/libm/w_exp.c 2006-06-25 11:20:19.000000000 +0000
10406 @@ -0,0 +1,54 @@
10407 +/* @(#)w_exp.c 5.1 93/09/24 */
10409 + * ====================================================
10410 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
10412 + * Developed at SunPro, a Sun Microsystems, Inc. business.
10413 + * Permission to use, copy, modify, and distribute this
10414 + * software is freely granted, provided that this notice
10415 + * is preserved.
10416 + * ====================================================
10417 + */
10419 +#if defined(LIBM_SCCS) && !defined(lint)
10420 +static char rcsid[] = "$NetBSD: w_exp.c,v 1.6 1995/05/10 20:48:51 jtc Exp $";
10421 +#endif
10424 + * wrapper exp(x)
10425 + */
10427 +#include "math.h"
10428 +#include "math_private.h"
10430 +#ifdef __STDC__
10431 +static const double
10432 +#else
10433 +static double
10434 +#endif
10435 +o_threshold= 7.09782712893383973096e+02, /* 0x40862E42, 0xFEFA39EF */
10436 +u_threshold= -7.45133219101941108420e+02; /* 0xc0874910, 0xD52D3051 */
10438 +#ifdef __STDC__
10439 + double __exp(double x) /* wrapper exp */
10440 +#else
10441 + double __exp(x) /* wrapper exp */
10442 + double x;
10443 +#endif
10445 +#ifdef _IEEE_LIBM
10446 + return __ieee754_exp(x);
10447 +#else
10448 + double z;
10449 + z = __ieee754_exp(x);
10450 + if(_LIB_VERSION == _IEEE_) return z;
10451 + if(finite(x)) {
10452 + if(x>o_threshold)
10453 + return __kernel_standard(x,x,6); /* exp overflow */
10454 + else if(x<u_threshold)
10455 + return __kernel_standard(x,x,7); /* exp underflow */
10457 + return z;
10458 +#endif
10460 +weak_alias (__exp, exp)
10461 diff -urN dietlibc-0.30/libm/w_fmod.c dietlibc-0.30-libm/libm/w_fmod.c
10462 --- dietlibc-0.30/libm/w_fmod.c 1970-01-01 00:00:00.000000000 +0000
10463 +++ dietlibc-0.30-libm/libm/w_fmod.c 2006-06-25 11:20:00.000000000 +0000
10464 @@ -0,0 +1,43 @@
10465 +/* @(#)w_fmod.c 5.1 93/09/24 */
10467 + * ====================================================
10468 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
10470 + * Developed at SunPro, a Sun Microsystems, Inc. business.
10471 + * Permission to use, copy, modify, and distribute this
10472 + * software is freely granted, provided that this notice
10473 + * is preserved.
10474 + * ====================================================
10475 + */
10477 +#if defined(LIBM_SCCS) && !defined(lint)
10478 +static char rcsid[] = "$NetBSD: w_fmod.c,v 1.6 1995/05/10 20:48:55 jtc Exp $";
10479 +#endif
10482 + * wrapper fmod(x,y)
10483 + */
10485 +#include "math.h"
10486 +#include "math_private.h"
10489 +#ifdef __STDC__
10490 + double fmod(double x, double y) /* wrapper fmod */
10491 +#else
10492 + double fmod(x,y) /* wrapper fmod */
10493 + double x,y;
10494 +#endif
10496 +#ifdef _IEEE_LIBM
10497 + return __ieee754_fmod(x,y);
10498 +#else
10499 + double z;
10500 + z = __ieee754_fmod(x,y);
10501 + if(_LIB_VERSION == _IEEE_ ||isnan(y)||isnan(x)) return z;
10502 + if(y==0.0) {
10503 + return __kernel_standard(x,y,27); /* fmod(x,0) */
10504 + } else
10505 + return z;
10506 +#endif
10508 diff -urN dietlibc-0.30/libm/w_gamma.c dietlibc-0.30-libm/libm/w_gamma.c
10509 --- dietlibc-0.30/libm/w_gamma.c 1970-01-01 00:00:00.000000000 +0000
10510 +++ dietlibc-0.30-libm/libm/w_gamma.c 2006-06-25 11:20:23.000000000 +0000
10511 @@ -0,0 +1,49 @@
10512 +/* @(#)w_gamma.c 5.1 93/09/24 */
10514 + * ====================================================
10515 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
10517 + * Developed at SunPro, a Sun Microsystems, Inc. business.
10518 + * Permission to use, copy, modify, and distribute this
10519 + * software is freely granted, provided that this notice
10520 + * is preserved.
10521 + * ====================================================
10522 + */
10524 +#if defined(LIBM_SCCS) && !defined(lint)
10525 +static char rcsid[] = "$NetBSD: w_gamma.c,v 1.7 1995/11/20 22:06:43 jtc Exp $";
10526 +#endif
10528 +/* double gamma(double x)
10529 + * Return the logarithm of the Gamma function of x.
10531 + * Method: call gamma_r
10532 + */
10534 +#include "math.h"
10535 +#include "math_private.h"
10537 +extern int signgam;
10539 +#ifdef __STDC__
10540 + double gamma(double x)
10541 +#else
10542 + double gamma(x)
10543 + double x;
10544 +#endif
10546 +#ifdef _IEEE_LIBM
10547 + return __ieee754_lgamma_r(x,&signgam);
10548 +#else
10549 + double y;
10550 + y = __ieee754_lgamma_r(x,&signgam);
10551 + if(_LIB_VERSION == _IEEE_) return y;
10552 + if(!finite(y)&&finite(x)) {
10553 + if(floor(x)==x&&x<=0.0)
10554 + return __kernel_standard(x,x,41); /* gamma pole */
10555 + else
10556 + return __kernel_standard(x,x,40); /* gamma overflow */
10557 + } else
10558 + return y;
10559 +#endif
10561 diff -urN dietlibc-0.30/libm/w_gamma_r.c dietlibc-0.30-libm/libm/w_gamma_r.c
10562 --- dietlibc-0.30/libm/w_gamma_r.c 1970-01-01 00:00:00.000000000 +0000
10563 +++ dietlibc-0.30-libm/libm/w_gamma_r.c 2006-06-25 11:20:22.000000000 +0000
10564 @@ -0,0 +1,46 @@
10565 +/* @(#)wr_gamma.c 5.1 93/09/24 */
10567 + * ====================================================
10568 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
10570 + * Developed at SunPro, a Sun Microsystems, Inc. business.
10571 + * Permission to use, copy, modify, and distribute this
10572 + * software is freely granted, provided that this notice
10573 + * is preserved.
10574 + * ====================================================
10575 + */
10577 +#if defined(LIBM_SCCS) && !defined(lint)
10578 +static char rcsid[] = "$NetBSD: w_gamma_r.c,v 1.7 1995/11/20 22:06:45 jtc Exp $";
10579 +#endif
10582 + * wrapper double gamma_r(double x, int *signgamp)
10583 + */
10585 +#include "math.h"
10586 +#include "math_private.h"
10589 +#ifdef __STDC__
10590 + double gamma_r(double x, int *signgamp) /* wrapper lgamma_r */
10591 +#else
10592 + double gamma_r(x,signgamp) /* wrapper lgamma_r */
10593 + double x; int *signgamp;
10594 +#endif
10596 +#ifdef _IEEE_LIBM
10597 + return __ieee754_lgamma_r(x,signgamp);
10598 +#else
10599 + double y;
10600 + y = __ieee754_lgamma_r(x,signgamp);
10601 + if(_LIB_VERSION == _IEEE_) return y;
10602 + if(!finite(y)&&finite(x)) {
10603 + if(floor(x)==x&&x<=0.0)
10604 + return __kernel_standard(x,x,41); /* gamma pole */
10605 + else
10606 + return __kernel_standard(x,x,40); /* gamma overflow */
10607 + } else
10608 + return y;
10609 +#endif
10611 diff -urN dietlibc-0.30/libm/w_hypot.c dietlibc-0.30-libm/libm/w_hypot.c
10612 --- dietlibc-0.30/libm/w_hypot.c 1970-01-01 00:00:00.000000000 +0000
10613 +++ dietlibc-0.30-libm/libm/w_hypot.c 2006-06-25 11:20:11.000000000 +0000
10614 @@ -0,0 +1,43 @@
10615 +/* @(#)w_hypot.c 5.1 93/09/24 */
10617 + * ====================================================
10618 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
10620 + * Developed at SunPro, a Sun Microsystems, Inc. business.
10621 + * Permission to use, copy, modify, and distribute this
10622 + * software is freely granted, provided that this notice
10623 + * is preserved.
10624 + * ====================================================
10625 + */
10627 +#if defined(LIBM_SCCS) && !defined(lint)
10628 +static char rcsid[] = "$NetBSD: w_hypot.c,v 1.6 1995/05/10 20:49:07 jtc Exp $";
10629 +#endif
10632 + * wrapper hypot(x,y)
10633 + */
10635 +#include "math.h"
10636 +#include "math_private.h"
10639 +#ifdef __STDC__
10640 + double hypot(double x, double y)/* wrapper hypot */
10641 +#else
10642 + double hypot(x,y) /* wrapper hypot */
10643 + double x,y;
10644 +#endif
10646 +#ifdef _IEEE_LIBM
10647 + return __ieee754_hypot(x,y);
10648 +#else
10649 + double z;
10650 + z = __ieee754_hypot(x,y);
10651 + if(_LIB_VERSION == _IEEE_) return z;
10652 + if((!finite(z))&&finite(x)&&finite(y))
10653 + return __kernel_standard(x,y,4); /* hypot overflow */
10654 + else
10655 + return z;
10656 +#endif
10658 diff -urN dietlibc-0.30/libm/w_j0.c dietlibc-0.30-libm/libm/w_j0.c
10659 --- dietlibc-0.30/libm/w_j0.c 1970-01-01 00:00:00.000000000 +0000
10660 +++ dietlibc-0.30-libm/libm/w_j0.c 2006-06-25 11:20:18.000000000 +0000
10661 @@ -0,0 +1,69 @@
10662 +/* @(#)w_j0.c 5.1 93/09/24 */
10664 + * ====================================================
10665 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
10667 + * Developed at SunPro, a Sun Microsystems, Inc. business.
10668 + * Permission to use, copy, modify, and distribute this
10669 + * software is freely granted, provided that this notice
10670 + * is preserved.
10671 + * ====================================================
10672 + */
10674 +#if defined(LIBM_SCCS) && !defined(lint)
10675 +static char rcsid[] = "$NetBSD: w_j0.c,v 1.6 1995/05/10 20:49:11 jtc Exp $";
10676 +#endif
10679 + * wrapper j0(double x), y0(double x)
10680 + */
10682 +#include "math.h"
10683 +#include "math_private.h"
10685 +#ifdef __STDC__
10686 + double j0(double x) /* wrapper j0 */
10687 +#else
10688 + double j0(x) /* wrapper j0 */
10689 + double x;
10690 +#endif
10692 +#ifdef _IEEE_LIBM
10693 + return __ieee754_j0(x);
10694 +#else
10695 + double z = __ieee754_j0(x);
10696 + if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
10697 + if(fabs(x)>X_TLOSS) {
10698 + return __kernel_standard(x,x,34); /* j0(|x|>X_TLOSS) */
10699 + } else
10700 + return z;
10701 +#endif
10704 +#ifdef __STDC__
10705 + double y0(double x) /* wrapper y0 */
10706 +#else
10707 + double y0(x) /* wrapper y0 */
10708 + double x;
10709 +#endif
10711 +#ifdef _IEEE_LIBM
10712 + return __ieee754_y0(x);
10713 +#else
10714 + double z;
10715 + z = __ieee754_y0(x);
10716 + if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
10717 + if(x <= 0.0){
10718 + if(x==0.0)
10719 + /* d= -one/(x-x); */
10720 + return __kernel_standard(x,x,8);
10721 + else
10722 + /* d = zero/(x-x); */
10723 + return __kernel_standard(x,x,9);
10725 + if(x>X_TLOSS) {
10726 + return __kernel_standard(x,x,35); /* y0(x>X_TLOSS) */
10727 + } else
10728 + return z;
10729 +#endif
10731 diff -urN dietlibc-0.30/libm/w_j1.c dietlibc-0.30-libm/libm/w_j1.c
10732 --- dietlibc-0.30/libm/w_j1.c 1970-01-01 00:00:00.000000000 +0000
10733 +++ dietlibc-0.30-libm/libm/w_j1.c 2006-06-25 11:20:18.000000000 +0000
10734 @@ -0,0 +1,70 @@
10735 +/* @(#)w_j1.c 5.1 93/09/24 */
10737 + * ====================================================
10738 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
10740 + * Developed at SunPro, a Sun Microsystems, Inc. business.
10741 + * Permission to use, copy, modify, and distribute this
10742 + * software is freely granted, provided that this notice
10743 + * is preserved.
10744 + * ====================================================
10745 + */
10747 +#if defined(LIBM_SCCS) && !defined(lint)
10748 +static char rcsid[] = "$NetBSD: w_j1.c,v 1.6 1995/05/10 20:49:15 jtc Exp $";
10749 +#endif
10752 + * wrapper of j1,y1
10753 + */
10755 +#include "math.h"
10756 +#include "math_private.h"
10758 +#ifdef __STDC__
10759 + double j1(double x) /* wrapper j1 */
10760 +#else
10761 + double j1(x) /* wrapper j1 */
10762 + double x;
10763 +#endif
10765 +#ifdef _IEEE_LIBM
10766 + return __ieee754_j1(x);
10767 +#else
10768 + double z;
10769 + z = __ieee754_j1(x);
10770 + if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
10771 + if(fabs(x)>X_TLOSS) {
10772 + return __kernel_standard(x,x,36); /* j1(|x|>X_TLOSS) */
10773 + } else
10774 + return z;
10775 +#endif
10778 +#ifdef __STDC__
10779 + double y1(double x) /* wrapper y1 */
10780 +#else
10781 + double y1(x) /* wrapper y1 */
10782 + double x;
10783 +#endif
10785 +#ifdef _IEEE_LIBM
10786 + return __ieee754_y1(x);
10787 +#else
10788 + double z;
10789 + z = __ieee754_y1(x);
10790 + if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
10791 + if(x <= 0.0){
10792 + if(x==0.0)
10793 + /* d= -one/(x-x); */
10794 + return __kernel_standard(x,x,10);
10795 + else
10796 + /* d = zero/(x-x); */
10797 + return __kernel_standard(x,x,11);
10799 + if(x>X_TLOSS) {
10800 + return __kernel_standard(x,x,37); /* y1(x>X_TLOSS) */
10801 + } else
10802 + return z;
10803 +#endif
10805 diff -urN dietlibc-0.30/libm/w_jn.c dietlibc-0.30-libm/libm/w_jn.c
10806 --- dietlibc-0.30/libm/w_jn.c 1970-01-01 00:00:00.000000000 +0000
10807 +++ dietlibc-0.30-libm/libm/w_jn.c 2006-06-25 11:20:18.000000000 +0000
10808 @@ -0,0 +1,92 @@
10809 +/* @(#)w_jn.c 5.1 93/09/24 */
10811 + * ====================================================
10812 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
10814 + * Developed at SunPro, a Sun Microsystems, Inc. business.
10815 + * Permission to use, copy, modify, and distribute this
10816 + * software is freely granted, provided that this notice
10817 + * is preserved.
10818 + * ====================================================
10819 + */
10821 +#if defined(LIBM_SCCS) && !defined(lint)
10822 +static char rcsid[] = "$NetBSD: w_jn.c,v 1.6 1995/05/10 20:49:19 jtc Exp $";
10823 +#endif
10826 + * wrapper jn(int n, double x), yn(int n, double x)
10827 + * floating point Bessel's function of the 1st and 2nd kind
10828 + * of order n
10830 + * Special cases:
10831 + * y0(0)=y1(0)=yn(n,0) = -inf with division by zero signal;
10832 + * y0(-ve)=y1(-ve)=yn(n,-ve) are NaN with invalid signal.
10833 + * Note 2. About jn(n,x), yn(n,x)
10834 + * For n=0, j0(x) is called,
10835 + * for n=1, j1(x) is called,
10836 + * for n<x, forward recursion us used starting
10837 + * from values of j0(x) and j1(x).
10838 + * for n>x, a continued fraction approximation to
10839 + * j(n,x)/j(n-1,x) is evaluated and then backward
10840 + * recursion is used starting from a supposed value
10841 + * for j(n,x). The resulting value of j(0,x) is
10842 + * compared with the actual value to correct the
10843 + * supposed value of j(n,x).
10845 + * yn(n,x) is similar in all respects, except
10846 + * that forward recursion is used for all
10847 + * values of n>1.
10849 + */
10851 +#include "math.h"
10852 +#include "math_private.h"
10854 +#ifdef __STDC__
10855 + double jn(int n, double x) /* wrapper jn */
10856 +#else
10857 + double jn(n,x) /* wrapper jn */
10858 + double x; int n;
10859 +#endif
10861 +#ifdef _IEEE_LIBM
10862 + return __ieee754_jn(n,x);
10863 +#else
10864 + double z;
10865 + z = __ieee754_jn(n,x);
10866 + if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
10867 + if(fabs(x)>X_TLOSS) {
10868 + return __kernel_standard((double)n,x,38); /* jn(|x|>X_TLOSS,n) */
10869 + } else
10870 + return z;
10871 +#endif
10874 +#ifdef __STDC__
10875 + double yn(int n, double x) /* wrapper yn */
10876 +#else
10877 + double yn(n,x) /* wrapper yn */
10878 + double x; int n;
10879 +#endif
10881 +#ifdef _IEEE_LIBM
10882 + return __ieee754_yn(n,x);
10883 +#else
10884 + double z;
10885 + z = __ieee754_yn(n,x);
10886 + if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
10887 + if(x <= 0.0){
10888 + if(x==0.0)
10889 + /* d= -one/(x-x); */
10890 + return __kernel_standard((double)n,x,12);
10891 + else
10892 + /* d = zero/(x-x); */
10893 + return __kernel_standard((double)n,x,13);
10895 + if(x>X_TLOSS) {
10896 + return __kernel_standard((double)n,x,39); /* yn(x>X_TLOSS,n) */
10897 + } else
10898 + return z;
10899 +#endif
10901 diff -urN dietlibc-0.30/libm/w_lgamma.c dietlibc-0.30-libm/libm/w_lgamma.c
10902 --- dietlibc-0.30/libm/w_lgamma.c 1970-01-01 00:00:00.000000000 +0000
10903 +++ dietlibc-0.30-libm/libm/w_lgamma.c 2006-06-25 11:20:03.000000000 +0000
10904 @@ -0,0 +1,49 @@
10905 +/* @(#)w_lgamma.c 5.1 93/09/24 */
10907 + * ====================================================
10908 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
10910 + * Developed at SunPro, a Sun Microsystems, Inc. business.
10911 + * Permission to use, copy, modify, and distribute this
10912 + * software is freely granted, provided that this notice
10913 + * is preserved.
10914 + * ====================================================
10915 + */
10917 +#if defined(LIBM_SCCS) && !defined(lint)
10918 +static char rcsid[] = "$NetBSD: w_lgamma.c,v 1.6 1995/05/10 20:49:24 jtc Exp $";
10919 +#endif
10921 +/* double lgamma(double x)
10922 + * Return the logarithm of the Gamma function of x.
10924 + * Method: call __ieee754_lgamma_r
10925 + */
10927 +#include "math.h"
10928 +#include "math_private.h"
10930 +extern int signgam;
10932 +#ifdef __STDC__
10933 + double lgamma(double x)
10934 +#else
10935 + double lgamma(x)
10936 + double x;
10937 +#endif
10939 +#ifdef _IEEE_LIBM
10940 + return __ieee754_lgamma_r(x,&signgam);
10941 +#else
10942 + double y;
10943 + y = __ieee754_lgamma_r(x,&signgam);
10944 + if(_LIB_VERSION == _IEEE_) return y;
10945 + if(!finite(y)&&finite(x)) {
10946 + if(floor(x)==x&&x<=0.0)
10947 + return __kernel_standard(x,x,15); /* lgamma pole */
10948 + else
10949 + return __kernel_standard(x,x,14); /* lgamma overflow */
10950 + } else
10951 + return y;
10952 +#endif
10954 diff -urN dietlibc-0.30/libm/w_lgamma_r.c dietlibc-0.30-libm/libm/w_lgamma_r.c
10955 --- dietlibc-0.30/libm/w_lgamma_r.c 1970-01-01 00:00:00.000000000 +0000
10956 +++ dietlibc-0.30-libm/libm/w_lgamma_r.c 2006-06-25 11:20:11.000000000 +0000
10957 @@ -0,0 +1,46 @@
10958 +/* @(#)wr_lgamma.c 5.1 93/09/24 */
10960 + * ====================================================
10961 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
10963 + * Developed at SunPro, a Sun Microsystems, Inc. business.
10964 + * Permission to use, copy, modify, and distribute this
10965 + * software is freely granted, provided that this notice
10966 + * is preserved.
10967 + * ====================================================
10968 + */
10970 +#if defined(LIBM_SCCS) && !defined(lint)
10971 +static char rcsid[] = "$NetBSD: w_lgamma_r.c,v 1.6 1995/05/10 20:49:27 jtc Exp $";
10972 +#endif
10975 + * wrapper double lgamma_r(double x, int *signgamp)
10976 + */
10978 +#include "math.h"
10979 +#include "math_private.h"
10982 +#ifdef __STDC__
10983 + double lgamma_r(double x, int *signgamp) /* wrapper lgamma_r */
10984 +#else
10985 + double lgamma_r(x,signgamp) /* wrapper lgamma_r */
10986 + double x; int *signgamp;
10987 +#endif
10989 +#ifdef _IEEE_LIBM
10990 + return __ieee754_lgamma_r(x,signgamp);
10991 +#else
10992 + double y;
10993 + y = __ieee754_lgamma_r(x,signgamp);
10994 + if(_LIB_VERSION == _IEEE_) return y;
10995 + if(!finite(y)&&finite(x)) {
10996 + if(floor(x)==x&&x<=0.0)
10997 + return __kernel_standard(x,x,15); /* lgamma pole */
10998 + else
10999 + return __kernel_standard(x,x,14); /* lgamma overflow */
11000 + } else
11001 + return y;
11002 +#endif
11004 diff -urN dietlibc-0.30/libm/w_log.c dietlibc-0.30-libm/libm/w_log.c
11005 --- dietlibc-0.30/libm/w_log.c 1970-01-01 00:00:00.000000000 +0000
11006 +++ dietlibc-0.30-libm/libm/w_log.c 2006-06-25 11:20:19.000000000 +0000
11007 @@ -0,0 +1,43 @@
11008 +/* @(#)w_log.c 5.1 93/09/24 */
11010 + * ====================================================
11011 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
11013 + * Developed at SunPro, a Sun Microsystems, Inc. business.
11014 + * Permission to use, copy, modify, and distribute this
11015 + * software is freely granted, provided that this notice
11016 + * is preserved.
11017 + * ====================================================
11018 + */
11020 +#if defined(LIBM_SCCS) && !defined(lint)
11021 +static char rcsid[] = "$NetBSD: w_log.c,v 1.6 1995/05/10 20:49:33 jtc Exp $";
11022 +#endif
11025 + * wrapper log(x)
11026 + */
11028 +#include "math.h"
11029 +#include "math_private.h"
11032 +#ifdef __STDC__
11033 + double log(double x) /* wrapper log */
11034 +#else
11035 + double log(x) /* wrapper log */
11036 + double x;
11037 +#endif
11039 +#ifdef _IEEE_LIBM
11040 + return __ieee754_log(x);
11041 +#else
11042 + double z;
11043 + z = __ieee754_log(x);
11044 + if(_LIB_VERSION == _IEEE_ || isnan(x) || x > 0.0) return z;
11045 + if(x==0.0)
11046 + return __kernel_standard(x,x,16); /* log(0) */
11047 + else
11048 + return __kernel_standard(x,x,17); /* log(x<0) */
11049 +#endif
11051 diff -urN dietlibc-0.30/libm/w_log10.c dietlibc-0.30-libm/libm/w_log10.c
11052 --- dietlibc-0.30/libm/w_log10.c 1970-01-01 00:00:00.000000000 +0000
11053 +++ dietlibc-0.30-libm/libm/w_log10.c 2006-06-25 11:20:21.000000000 +0000
11054 @@ -0,0 +1,46 @@
11055 +/* @(#)w_log10.c 5.1 93/09/24 */
11057 + * ====================================================
11058 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
11060 + * Developed at SunPro, a Sun Microsystems, Inc. business.
11061 + * Permission to use, copy, modify, and distribute this
11062 + * software is freely granted, provided that this notice
11063 + * is preserved.
11064 + * ====================================================
11065 + */
11067 +#if defined(LIBM_SCCS) && !defined(lint)
11068 +static char rcsid[] = "$NetBSD: w_log10.c,v 1.6 1995/05/10 20:49:35 jtc Exp $";
11069 +#endif
11072 + * wrapper log10(X)
11073 + */
11075 +#include "math.h"
11076 +#include "math_private.h"
11079 +#ifdef __STDC__
11080 + double log10(double x) /* wrapper log10 */
11081 +#else
11082 + double log10(x) /* wrapper log10 */
11083 + double x;
11084 +#endif
11086 +#ifdef _IEEE_LIBM
11087 + return __ieee754_log10(x);
11088 +#else
11089 + double z;
11090 + z = __ieee754_log10(x);
11091 + if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
11092 + if(x<=0.0) {
11093 + if(x==0.0)
11094 + return __kernel_standard(x,x,18); /* log10(0) */
11095 + else
11096 + return __kernel_standard(x,x,19); /* log10(x<0) */
11097 + } else
11098 + return z;
11099 +#endif
11101 diff -urN dietlibc-0.30/libm/w_pow.c dietlibc-0.30-libm/libm/w_pow.c
11102 --- dietlibc-0.30/libm/w_pow.c 1970-01-01 00:00:00.000000000 +0000
11103 +++ dietlibc-0.30-libm/libm/w_pow.c 2006-06-25 11:20:19.000000000 +0000
11104 @@ -0,0 +1,61 @@
11107 +/* @(#)w_pow.c 5.2 93/10/01 */
11109 + * ====================================================
11110 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
11112 + * Developed at SunPro, a Sun Microsystems, Inc. business.
11113 + * Permission to use, copy, modify, and distribute this
11114 + * software is freely granted, provided that this notice
11115 + * is preserved.
11116 + * ====================================================
11117 + */
11120 + * wrapper pow(x,y) return x**y
11121 + */
11123 +#include "math.h"
11124 +#include "math_private.h"
11127 +#ifdef __STDC__
11128 + double pow(double x, double y) /* wrapper pow */
11129 +#else
11130 + double pow(x,y) /* wrapper pow */
11131 + double x,y;
11132 +#endif
11134 +#ifdef _IEEE_LIBM
11135 + return __ieee754_pow(x,y);
11136 +#else
11137 + double z;
11138 + z=__ieee754_pow(x,y);
11139 + if(_LIB_VERSION == _IEEE_|| isnan(y)) return z;
11140 + if(isnan(x)) {
11141 + if(y==0.0)
11142 + return __kernel_standard(x,y,42); /* pow(NaN,0.0) */
11143 + else
11144 + return z;
11146 + if(x==0.0){
11147 + if(y==0.0)
11148 + return __kernel_standard(x,y,20); /* pow(0.0,0.0) */
11149 + if(finite(y)&&y<0.0)
11150 + return __kernel_standard(x,y,23); /* pow(0.0,negative) */
11151 + return z;
11153 + if(!finite(z)) {
11154 + if(finite(x)&&finite(y)) {
11155 + if(isnan(z))
11156 + return __kernel_standard(x,y,24); /* pow neg**non-int */
11157 + else
11158 + return __kernel_standard(x,y,21); /* pow overflow */
11161 + if(z==0.0&&finite(x)&&finite(y))
11162 + return __kernel_standard(x,y,22); /* pow underflow */
11163 + return z;
11164 +#endif
11166 diff -urN dietlibc-0.30/libm/w_remainder.c dietlibc-0.30-libm/libm/w_remainder.c
11167 --- dietlibc-0.30/libm/w_remainder.c 1970-01-01 00:00:00.000000000 +0000
11168 +++ dietlibc-0.30-libm/libm/w_remainder.c 2006-06-25 11:20:14.000000000 +0000
11169 @@ -0,0 +1,42 @@
11170 +/* @(#)w_remainder.c 5.1 93/09/24 */
11172 + * ====================================================
11173 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
11175 + * Developed at SunPro, a Sun Microsystems, Inc. business.
11176 + * Permission to use, copy, modify, and distribute this
11177 + * software is freely granted, provided that this notice
11178 + * is preserved.
11179 + * ====================================================
11180 + */
11182 +#if defined(LIBM_SCCS) && !defined(lint)
11183 +static char rcsid[] = "$NetBSD: w_remainder.c,v 1.6 1995/05/10 20:49:44 jtc Exp $";
11184 +#endif
11187 + * wrapper remainder(x,p)
11188 + */
11190 +#include "math.h"
11191 +#include "math_private.h"
11193 +#ifdef __STDC__
11194 + double remainder(double x, double y) /* wrapper remainder */
11195 +#else
11196 + double remainder(x,y) /* wrapper remainder */
11197 + double x,y;
11198 +#endif
11200 +#ifdef _IEEE_LIBM
11201 + return __ieee754_remainder(x,y);
11202 +#else
11203 + double z;
11204 + z = __ieee754_remainder(x,y);
11205 + if(_LIB_VERSION == _IEEE_ || isnan(y)) return z;
11206 + if(y==0.0)
11207 + return __kernel_standard(x,y,28); /* remainder(x,0) */
11208 + else
11209 + return z;
11210 +#endif
11212 diff -urN dietlibc-0.30/libm/w_scalb.c dietlibc-0.30-libm/libm/w_scalb.c
11213 --- dietlibc-0.30/libm/w_scalb.c 1970-01-01 00:00:00.000000000 +0000
11214 +++ dietlibc-0.30-libm/libm/w_scalb.c 2006-06-25 11:20:19.000000000 +0000
11215 @@ -0,0 +1,60 @@
11216 +/* @(#)w_scalb.c 5.1 93/09/24 */
11218 + * ====================================================
11219 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
11221 + * Developed at SunPro, a Sun Microsystems, Inc. business.
11222 + * Permission to use, copy, modify, and distribute this
11223 + * software is freely granted, provided that this notice
11224 + * is preserved.
11225 + * ====================================================
11226 + */
11228 +#if defined(LIBM_SCCS) && !defined(lint)
11229 +static char rcsid[] = "$NetBSD: w_scalb.c,v 1.6 1995/05/10 20:49:48 jtc Exp $";
11230 +#endif
11233 + * wrapper scalb(double x, double fn) is provide for
11234 + * passing various standard test suite. One
11235 + * should use scalbn() instead.
11236 + */
11238 +#include "math.h"
11239 +#include "math_private.h"
11241 +#include <errno.h>
11243 +#ifdef __STDC__
11244 +#ifdef _SCALB_INT
11245 + double scalb(double x, int fn) /* wrapper scalb */
11246 +#else
11247 + double scalb(double x, double fn) /* wrapper scalb */
11248 +#endif
11249 +#else
11250 + double scalb(x,fn) /* wrapper scalb */
11251 +#ifdef _SCALB_INT
11252 + double x; int fn;
11253 +#else
11254 + double x,fn;
11255 +#endif
11256 +#endif
11258 +#ifdef _IEEE_LIBM
11259 + return __ieee754_scalb(x,fn);
11260 +#else
11261 + double z;
11262 + z = __ieee754_scalb(x,fn);
11263 + if(_LIB_VERSION == _IEEE_) return z;
11264 + if(!(finite(z)||isnan(z))&&finite(x)) {
11265 + return __kernel_standard(x,(double)fn,32); /* scalb overflow */
11267 + if(z==0.0&&z!=x) {
11268 + return __kernel_standard(x,(double)fn,33); /* scalb underflow */
11270 +#ifndef _SCALB_INT
11271 + if(!finite(fn)) errno = ERANGE;
11272 +#endif
11273 + return z;
11274 +#endif
11276 diff -urN dietlibc-0.30/libm/w_sinh.c dietlibc-0.30-libm/libm/w_sinh.c
11277 --- dietlibc-0.30/libm/w_sinh.c 1970-01-01 00:00:00.000000000 +0000
11278 +++ dietlibc-0.30-libm/libm/w_sinh.c 2006-06-25 11:20:07.000000000 +0000
11279 @@ -0,0 +1,42 @@
11280 +/* @(#)w_sinh.c 5.1 93/09/24 */
11282 + * ====================================================
11283 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
11285 + * Developed at SunPro, a Sun Microsystems, Inc. business.
11286 + * Permission to use, copy, modify, and distribute this
11287 + * software is freely granted, provided that this notice
11288 + * is preserved.
11289 + * ====================================================
11290 + */
11292 +#if defined(LIBM_SCCS) && !defined(lint)
11293 +static char rcsid[] = "$NetBSD: w_sinh.c,v 1.6 1995/05/10 20:49:51 jtc Exp $";
11294 +#endif
11297 + * wrapper sinh(x)
11298 + */
11300 +#include "math.h"
11301 +#include "math_private.h"
11303 +#ifdef __STDC__
11304 + double sinh(double x) /* wrapper sinh */
11305 +#else
11306 + double sinh(x) /* wrapper sinh */
11307 + double x;
11308 +#endif
11310 +#ifdef _IEEE_LIBM
11311 + return __ieee754_sinh(x);
11312 +#else
11313 + double z;
11314 + z = __ieee754_sinh(x);
11315 + if(_LIB_VERSION == _IEEE_) return z;
11316 + if(!finite(z)&&finite(x)) {
11317 + return __kernel_standard(x,x,25); /* sinh overflow */
11318 + } else
11319 + return z;
11320 +#endif
11322 diff -urN dietlibc-0.30/libm/w_sqrt.c dietlibc-0.30-libm/libm/w_sqrt.c
11323 --- dietlibc-0.30/libm/w_sqrt.c 1970-01-01 00:00:00.000000000 +0000
11324 +++ dietlibc-0.30-libm/libm/w_sqrt.c 2006-06-25 11:20:08.000000000 +0000
11325 @@ -0,0 +1,42 @@
11326 +/* @(#)w_sqrt.c 5.1 93/09/24 */
11328 + * ====================================================
11329 + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
11331 + * Developed at SunPro, a Sun Microsystems, Inc. business.
11332 + * Permission to use, copy, modify, and distribute this
11333 + * software is freely granted, provided that this notice
11334 + * is preserved.
11335 + * ====================================================
11336 + */
11338 +#if defined(LIBM_SCCS) && !defined(lint)
11339 +static char rcsid[] = "$NetBSD: w_sqrt.c,v 1.6 1995/05/10 20:49:55 jtc Exp $";
11340 +#endif
11343 + * wrapper sqrt(x)
11344 + */
11346 +#include "math.h"
11347 +#include "math_private.h"
11349 +#ifdef __STDC__
11350 + double sqrt(double x) /* wrapper sqrt */
11351 +#else
11352 + double sqrt(x) /* wrapper sqrt */
11353 + double x;
11354 +#endif
11356 +#ifdef _IEEE_LIBM
11357 + return __ieee754_sqrt(x);
11358 +#else
11359 + double z;
11360 + z = __ieee754_sqrt(x);
11361 + if(_LIB_VERSION == _IEEE_ || isnan(x)) return z;
11362 + if(x<0.0) {
11363 + return __kernel_standard(x,x,26); /* sqrt(negative) */
11364 + } else
11365 + return z;
11366 +#endif