1996-03-05 22:41:30 +01:00
|
|
|
/*
|
2001-03-12 01:04:52 +01:00
|
|
|
* IBM Accurate Mathematical Library
|
2002-07-06 08:36:39 +02:00
|
|
|
* written by International Business Machines Corp.
|
2004-01-23 14:17:52 +01:00
|
|
|
* Copyright (C) 2001, 2002, 2004 Free Software Foundation
|
1996-03-05 22:41:30 +01:00
|
|
|
*
|
2001-03-12 01:04:52 +01:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
2002-08-27 00:40:48 +02:00
|
|
|
* the Free Software Foundation; either version 2.1 of the License, or
|
2001-03-12 01:04:52 +01:00
|
|
|
* (at your option) any later version.
|
1996-03-05 22:41:30 +01:00
|
|
|
*
|
2001-03-12 01:04:52 +01:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2002-08-20 23:51:55 +02:00
|
|
|
* GNU Lesser General Public License for more details.
|
1996-03-05 22:41:30 +01:00
|
|
|
*
|
2001-03-12 01:04:52 +01:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1996-03-05 22:41:30 +01:00
|
|
|
*/
|
2001-03-12 01:04:52 +01:00
|
|
|
/***************************************************************************/
|
|
|
|
/* MODULE_NAME: upow.c */
|
|
|
|
/* */
|
|
|
|
/* FUNCTIONS: upow */
|
|
|
|
/* power1 */
|
2004-01-23 14:17:52 +01:00
|
|
|
/* my_log2 */
|
2001-03-12 01:04:52 +01:00
|
|
|
/* log1 */
|
|
|
|
/* checkint */
|
|
|
|
/* FILES NEEDED: dla.h endian.h mpa.h mydefs.h */
|
|
|
|
/* halfulp.c mpexp.c mplog.c slowexp.c slowpow.c mpa.c */
|
2001-05-12 16:32:12 +02:00
|
|
|
/* uexp.c upow.c */
|
2001-03-12 01:04:52 +01:00
|
|
|
/* root.tbl uexp.tbl upow.tbl */
|
|
|
|
/* An ultimate power routine. Given two IEEE double machine numbers y,x */
|
|
|
|
/* it computes the correctly rounded (to nearest) value of x^y. */
|
|
|
|
/* Assumption: Machine arithmetic operations are performed in */
|
|
|
|
/* round to nearest mode of IEEE 754 standard. */
|
|
|
|
/* */
|
|
|
|
/***************************************************************************/
|
|
|
|
#include "endian.h"
|
|
|
|
#include "upow.h"
|
|
|
|
#include "dla.h"
|
|
|
|
#include "mydefs.h"
|
|
|
|
#include "MathLib.h"
|
|
|
|
#include "upow.tbl"
|
2001-05-12 16:32:12 +02:00
|
|
|
#include "math_private.h"
|
1996-03-05 22:41:30 +01:00
|
|
|
|
|
|
|
|
2001-03-12 01:04:52 +01:00
|
|
|
double __exp1(double x, double xx, double error);
|
|
|
|
static double log1(double x, double *delta, double *error);
|
2004-01-23 14:17:52 +01:00
|
|
|
static double my_log2(double x, double *delta, double *error);
|
2001-03-13 03:01:34 +01:00
|
|
|
double __slowpow(double x, double y,double z);
|
2001-03-12 01:04:52 +01:00
|
|
|
static double power1(double x, double y);
|
|
|
|
static int checkint(double x);
|
1996-03-05 22:41:30 +01:00
|
|
|
|
2001-03-12 01:04:52 +01:00
|
|
|
/***************************************************************************/
|
|
|
|
/* An ultimate power routine. Given two IEEE double machine numbers y,x */
|
|
|
|
/* it computes the correctly rounded (to nearest) value of X^y. */
|
|
|
|
/***************************************************************************/
|
2001-03-12 19:22:49 +01:00
|
|
|
double __ieee754_pow(double x, double y) {
|
2001-03-12 08:57:09 +01:00
|
|
|
double z,a,aa,error, t,a1,a2,y1,y2;
|
|
|
|
#if 0
|
|
|
|
double gor=1.0;
|
|
|
|
#endif
|
2001-03-12 01:04:52 +01:00
|
|
|
mynumber u,v;
|
|
|
|
int k;
|
|
|
|
int4 qx,qy;
|
|
|
|
v.x=y;
|
|
|
|
u.x=x;
|
|
|
|
if (v.i[LOW_HALF] == 0) { /* of y */
|
|
|
|
qx = u.i[HIGH_HALF]&0x7fffffff;
|
|
|
|
/* Checking if x is not too small to compute */
|
|
|
|
if (((qx==0x7ff00000)&&(u.i[LOW_HALF]!=0))||(qx>0x7ff00000)) return NaNQ.x;
|
|
|
|
if (y == 1.0) return x;
|
|
|
|
if (y == 2.0) return x*x;
|
2001-03-13 03:01:34 +01:00
|
|
|
if (y == -1.0) return 1.0/x;
|
|
|
|
if (y == 0) return 1.0;
|
2001-03-12 01:04:52 +01:00
|
|
|
}
|
|
|
|
/* else */
|
|
|
|
if(((u.i[HIGH_HALF]>0 && u.i[HIGH_HALF]<0x7ff00000)|| /* x>0 and not x->0 */
|
|
|
|
(u.i[HIGH_HALF]==0 && u.i[LOW_HALF]!=0)) &&
|
|
|
|
/* 2^-1023< x<= 2^-1023 * 0x1.0000ffffffff */
|
|
|
|
(v.i[HIGH_HALF]&0x7fffffff) < 0x4ff00000) { /* if y<-1 or y>1 */
|
|
|
|
z = log1(x,&aa,&error); /* x^y =e^(y log (X)) */
|
|
|
|
t = y*134217729.0;
|
|
|
|
y1 = t - (t-y);
|
|
|
|
y2 = y - y1;
|
|
|
|
t = z*134217729.0;
|
|
|
|
a1 = t - (t-z);
|
|
|
|
a2 = (z - a1)+aa;
|
|
|
|
a = y1*a1;
|
|
|
|
aa = y2*a1 + y*a2;
|
|
|
|
a1 = a+aa;
|
|
|
|
a2 = (a-a1)+aa;
|
|
|
|
error = error*ABS(y);
|
|
|
|
t = __exp1(a1,a2,1.9e16*error); /* return -10 or 0 if wasn't computed exactly */
|
|
|
|
return (t>0)?t:power1(x,y);
|
|
|
|
}
|
1996-03-05 22:41:30 +01:00
|
|
|
|
2001-03-12 01:04:52 +01:00
|
|
|
if (x == 0) {
|
2001-03-13 03:01:34 +01:00
|
|
|
if (((v.i[HIGH_HALF] & 0x7fffffff) == 0x7ff00000 && v.i[LOW_HALF] != 0)
|
|
|
|
|| (v.i[HIGH_HALF] & 0x7fffffff) > 0x7ff00000)
|
|
|
|
return y;
|
|
|
|
if (ABS(y) > 1.0e20) return (y>0)?0:INF.x;
|
2001-03-12 01:04:52 +01:00
|
|
|
k = checkint(y);
|
2001-03-13 03:01:34 +01:00
|
|
|
if (k == -1)
|
|
|
|
return y < 0 ? 1.0/x : x;
|
|
|
|
else
|
|
|
|
return y < 0 ? 1.0/ABS(x) : 0.0; /* return 0 */
|
2001-03-12 01:04:52 +01:00
|
|
|
}
|
|
|
|
/* if x<0 */
|
|
|
|
if (u.i[HIGH_HALF] < 0) {
|
|
|
|
k = checkint(y);
|
2001-03-13 03:01:34 +01:00
|
|
|
if (k==0) {
|
|
|
|
if ((v.i[HIGH_HALF] & 0x7fffffff) == 0x7ff00000 && v.i[LOW_HALF] == 0) {
|
|
|
|
if (x == -1.0) return 1.0;
|
|
|
|
else if (x > -1.0) return v.i[HIGH_HALF] < 0 ? INF.x : 0.0;
|
|
|
|
else return v.i[HIGH_HALF] < 0 ? 0.0 : INF.x;
|
|
|
|
}
|
|
|
|
else if (u.i[HIGH_HALF] == 0xfff00000 && u.i[LOW_HALF] == 0)
|
|
|
|
return y < 0 ? 0.0 : INF.x;
|
|
|
|
return NaNQ.x; /* y not integer and x<0 */
|
|
|
|
}
|
|
|
|
else if (u.i[HIGH_HALF] == 0xfff00000 && u.i[LOW_HALF] == 0)
|
|
|
|
{
|
|
|
|
if (k < 0)
|
|
|
|
return y < 0 ? nZERO.x : nINF.x;
|
|
|
|
else
|
|
|
|
return y < 0 ? 0.0 : INF.x;
|
|
|
|
}
|
|
|
|
return (k==1)?__ieee754_pow(-x,y):-__ieee754_pow(-x,y); /* if y even or odd */
|
2001-03-12 01:04:52 +01:00
|
|
|
}
|
|
|
|
/* x>0 */
|
|
|
|
qx = u.i[HIGH_HALF]&0x7fffffff; /* no sign */
|
|
|
|
qy = v.i[HIGH_HALF]&0x7fffffff; /* no sign */
|
1996-03-05 22:41:30 +01:00
|
|
|
|
2001-03-12 01:04:52 +01:00
|
|
|
if (qx > 0x7ff00000 || (qx == 0x7ff00000 && u.i[LOW_HALF] != 0)) return NaNQ.x;
|
|
|
|
/* if 0<x<2^-0x7fe */
|
2001-03-13 03:01:34 +01:00
|
|
|
if (qy > 0x7ff00000 || (qy == 0x7ff00000 && v.i[LOW_HALF] != 0))
|
|
|
|
return x == 1.0 ? 1.0 : NaNQ.x;
|
2001-03-12 01:04:52 +01:00
|
|
|
/* if y<2^-0x7fe */
|
1996-03-05 22:41:30 +01:00
|
|
|
|
2001-03-12 01:04:52 +01:00
|
|
|
if (qx == 0x7ff00000) /* x= 2^-0x3ff */
|
|
|
|
{if (y == 0) return NaNQ.x;
|
|
|
|
return (y>0)?x:0; }
|
2001-02-20 00:16:05 +01:00
|
|
|
|
2001-03-12 01:04:52 +01:00
|
|
|
if (qy > 0x45f00000 && qy < 0x7ff00000) {
|
|
|
|
if (x == 1.0) return 1.0;
|
|
|
|
if (y>0) return (x>1.0)?INF.x:0;
|
|
|
|
if (y<0) return (x<1.0)?INF.x:0;
|
|
|
|
}
|
1996-03-05 22:41:30 +01:00
|
|
|
|
2001-03-13 03:01:34 +01:00
|
|
|
if (x == 1.0) return 1.0;
|
2001-03-12 01:04:52 +01:00
|
|
|
if (y>0) return (x>1.0)?INF.x:0;
|
|
|
|
if (y<0) return (x<1.0)?INF.x:0;
|
|
|
|
return 0; /* unreachable, to make the compiler happy */
|
|
|
|
}
|
1996-03-05 22:41:30 +01:00
|
|
|
|
2001-03-12 01:04:52 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
/* Computing x^y using more accurate but more slow log routine */
|
|
|
|
/**************************************************************************/
|
|
|
|
static double power1(double x, double y) {
|
|
|
|
double z,a,aa,error, t,a1,a2,y1,y2;
|
2004-01-23 14:17:52 +01:00
|
|
|
z = my_log2(x,&aa,&error);
|
2001-03-12 01:04:52 +01:00
|
|
|
t = y*134217729.0;
|
|
|
|
y1 = t - (t-y);
|
|
|
|
y2 = y - y1;
|
|
|
|
t = z*134217729.0;
|
|
|
|
a1 = t - (t-z);
|
|
|
|
a2 = z - a1;
|
|
|
|
a = y*z;
|
|
|
|
aa = ((y1*a1-a)+y1*a2+y2*a1)+y2*a2+aa*y;
|
|
|
|
a1 = a+aa;
|
|
|
|
a2 = (a-a1)+aa;
|
|
|
|
error = error*ABS(y);
|
|
|
|
t = __exp1(a1,a2,1.9e16*error);
|
2001-03-13 03:01:34 +01:00
|
|
|
return (t >= 0)?t:__slowpow(x,y,z);
|
2001-03-12 01:04:52 +01:00
|
|
|
}
|
1996-03-05 22:41:30 +01:00
|
|
|
|
2001-03-12 01:04:52 +01:00
|
|
|
/****************************************************************************/
|
|
|
|
/* Computing log(x) (x is left argument). The result is the returned double */
|
|
|
|
/* + the parameter delta. */
|
|
|
|
/* The result is bounded by error (rightmost argument) */
|
|
|
|
/****************************************************************************/
|
|
|
|
static double log1(double x, double *delta, double *error) {
|
2001-03-12 08:57:09 +01:00
|
|
|
int i,j,m;
|
|
|
|
#if 0
|
|
|
|
int n;
|
|
|
|
#endif
|
|
|
|
double uu,vv,eps,nx,e,e1,e2,t,t1,t2,res,add=0;
|
|
|
|
#if 0
|
|
|
|
double cor;
|
|
|
|
#endif
|
2001-03-12 01:04:52 +01:00
|
|
|
mynumber u,v;
|
2002-08-24 03:36:09 +02:00
|
|
|
#ifdef BIG_ENDI
|
|
|
|
mynumber
|
|
|
|
/**/ two52 = {{0x43300000, 0x00000000}}; /* 2**52 */
|
|
|
|
#else
|
|
|
|
#ifdef LITTLE_ENDI
|
|
|
|
mynumber
|
|
|
|
/**/ two52 = {{0x00000000, 0x43300000}}; /* 2**52 */
|
|
|
|
#endif
|
|
|
|
#endif
|
update from main archive 961030
Thu Oct 31 00:01:39 1996 Ulrich Drepper <drepper@cygnus.com>
* signal/Makefile (routines): Add sigwait.
* signal/signal.h: Add prototype for sigwait.
* sysdeps/posix/sigwait.c: New file. Implementation of sigwait
function from POSIX.1c.
* sysdeps/stub/sigwait.c: New file. Stub version of sigwait.
Wed Oct 30 02:01:17 1996 Richard Henderson <rth@tamu.edu>
* sunrpc/xdr_float.c (xdr_float): Handle sizeof(float)!=sizeof(long),
but don't bother going farther than sizeof(float)==sizeof(int).
(xdr_double): Handle little-endian machines! Handle sizeof(double)
!= 2*sizeof(long), though again don't bother with more than int.
Thu Oct 29 16:09:42 1996 Craig Metz <cmetz@inner.net>
* sysdeps/posix/getaddrinfo.c: Use buffer limits for inet_ntop
function.
Tue Oct 29 12:37:22 1996 Ulrich Drepper <drepper@cygnus.com>
* Makerules: Create symbolic links for linking in $(libdir).
(make-link): Use absolute path for destination if this is not in
the same directory.
* elf/rtld.c (dl_main): When verifying don't check the name of
the dynamic linker.
* shlib-versions: Change entries for Hurd specific libs from
*-*-gnu* to *-*-gnu?* so that i586-pc-linux-gnu does not match
these entries.
* assert/assert.h: Reformat copyright.
Change reference to ANSI into reference to ISO C.
* ctype/ctype.h: Likewise.
* errno.h: Likewise.
* limits.h: Likewise.
* math/math.h: Likewise.
* setjmp/setjmp.h: Likewise.
* stdio/stdio.h: Likewise.
* libio/stdio.h: Likewise.
* stdlib/stdlib.h: Likewise.
* string/string.h: Likewise.
* time/time.h: Likewise.
* string/argz.h: Use __const is definitions.
* elf/dlfcn.h: Use __const and __P. Reformat copyright.
* misc/err.h: Likewise.
* wctype/wctype.h (wctrans_t): Use __const instead of const.
* Makeconfig ($(common-objpfx)soversions.mk): Generate list of
sonames for versioned libraries.
* Makefile: Remove code to generate libc-version.h.
Generate gnu/lib-names.h with info from soversions.mk.
* features.h: Define __GLIBC__ and __GLIBC_MINOR__.
* dirent/tst-seekdir.c: Initialize save3.
* grp/testgrp.c: Initialize my_group.
* grp/fgetgrent_r.c: Change interface to follow POSIX.1c.
* grp/grp.h: Likewise.
* nss/getXXbyYY.c: Likewise.
* nss/getXXbyYY_r.c: Likewise.
* nss/getXXent.c: Likewise.
* nss/getXXent_r.c: Likewise.
* pwd/fgetpwent_r.c: Likewise.
* pwd/pwd.h: Likewise.
* shadow/fgetspent_r.c: Likewise.
* shadow/sgetspent.c: Likewise.
* shadow/sgetspent_r.c: Likewise.
* grp/fgetgrent.c: Adapt for change in interface of fgetgrent_r.
* pwd/fgetpwent.c: Likewise, for fgetpwent_r.c.
* shadow/fgetspent.c: Likewise, for fgetpwent_r.c.
* resolv/netdb.h: Adapt prototypes for reentrant functions to
follow POSIX.1c.
* sunrpc/rpc/netdb.h: Likewise,
* shadow/shadow.h: Likewise.
* inet/getnetgrent_r.c: Follow change in pwd/grp function interface.
* sysdeps/unix/getlogin_r.c: Return ERANGE when buffer is too small.
* inet/herrno.c: Don't define __h_errno. Only h_errno otherwise the
ELF aliasing creates strange situations.
* sysdeps/unix/sysv/linux/errnos.H: Define __set_errno as inline
function.
* sysdeps/unix/sysv/linux/i386/sysdep.S: Don't define __errno.
* sysdeps/unix/sysv/linux/m68k/sysdep.S: Likewise.
* libio/libio.h: Don't declare _IO_flockfile and _IO_funlockfile
weak.
* locale/programs/charmap.c: Add casts to prevent warnings.
* locale/programs/linereader.h: Likewise.
* locale/programs/ld-collate.c: Likewise.
* locale/programs/stringtrans.c: Likewise.
Change types for various variables to prevent warnings.
* locale/programs/ld-ctype.c: Likewise.
* locale/programs/linereader.h (lr_ungetc): Likewise.
* locale/programs/charset.h (struct charset): Use `unsigned int'
as type for width_default.
* posix/regex.c: Change type of `this_reg' variables.
* stdio-common/Makefile: Use -Wno-format for tstdiomisc.c.
* stdio-common/bug5.c: De-ANSI-fy. Use correct types for
variables.
* stdio-common/printf_fp.c: Initialize to_shift.
* stdio-common/test_rdwr.c: Add cast.
* stdio-common/vfprintf.c: Add casts and use correct types to
prevent warnings.
* stdio-common/vfscanf.c: Initialize str and strptr.
* sysdeps/libm-ieee754/e_jnf.c: Use correct types to prevent warnings.
* sysdeps/libm-ieee754/e_pow.c: Likewise.
* sysdeps/libm-ieee754/e_powf.c: Likewise.
* sysdeps/libm-ieee754/e_rem_pio2f.c: Likewise.
* time/test-tz.c: Likewise.
* manual/creature.texi: Document _REENTRANT and _THREAD_SAFE.
* manual/libc.texinfo: Prevent makeinfo failure by avoiding
libc.cp index. This must be fixed.
* manual/nss.texi: Adapt for correct POSIX.1c interface of
reentrant functions.
* manual/users.texi: Document netgroup functions.
* po/es.po: Updated.
* po/fr.po: Updated.
* posix/fnmatch.c: Change to match libit version.
* posix/unistd.h: Change prototype for ttyname_r to match POSIX.1c.
* sysdep/posix/ttyname_r.c: Likewise.
* stdlib/atexit.h (__new_exitfn): Add internal locking.
* stdlib/exit.c: De-ANSI-fy. Handle new ef_us value for flavor.
* stdlib/exit.h: De-ANSI-fy. Define new ef_us value for flavor.
* stdlib/random.c (__srandom): Add internal locking.
(__initstate): Likewise.
(__setstate): Likewise.
(__random): Likewise.
Mon Oct 28 22:28:37 1996 NIIBE Yutaka <gniibe@mri.co.jp>
* sysdeps/generic/crypt-entry.c (crypt_r): Use __set_errno.
(crypt): Likewise.
* resolv/gethnamaddr.c (gethostbyname2): Likewise.
* sysdeps/generic/uname.c: Likewise.
* sysdeps/posix/rename.c: Likewise.
* sysdeps/stub/setrlimit.c: Likewise.
* nss/nss_db/db-netgrp.c (_nss_db_setnetgrent): Fix typo.
Sun Oct 27 11:12:50 1996 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* locale/programs/ld-collate.c (collate_order_elem): Fix format
string.
(collate_element_to): Cast field width argument to `int' for
format string.
(collate_symbol): Likewise.
(collate_order_elem): Likewise.
(collate_weight_bsymbol): Likewise.
(collate_simple_weight): Likewise.
* locale/programs/ld-time.c (STRARR_ELEM): Fix format string.
* locale/programs/ld-ctype.c (ctype_class_newP): Add missing
argument for format string.
(ctype_map_newP): Likewise.
(set_class_defaults): Fix format string.
* locale/programs/localedef.c (construct_output_path): Putting an
explicit \0 into the format string does not work, use %c.
Sat Oct 26 20:38:36 1996 Richard Henderson <rth@tamu.edu>
* Makerules: Install all shared libraries in $(slibdir).
* login/Makefile: Build libutil.so in others pass after
libc.so is created.
* misc/mntent.h: Include <paths.h> for _PATH_MNTTAB & _PATH_MOUNTED.
* string/stratcliff.c: Allocate 3 pages instead of one, then use
mprotect so that we know that the adjacent pages are inaccessible.
* resource/sys/resource.h: Move all structures and enums to ...
* sysdeps/generic/resourcebits.h: ... here ...
* sysdeps/unix/bsd/sun/sunos4/resourcebits.h: ... and here.
* sysdeps/unix/sysv/linux/alpha/resourcebits.h: Remove.
* sysdeps/unix/sysv/linux/i386/resourcebits.h: Remove.
* sysdeps/unix/sysv/linux/m68k/resourcebits.h: Remove.
* sysdeps/unix/sysv/linux/mips/resourcebits.h: Remove.
* sysdeps/unix/sysv/linux/resourcebits.h: New file. Use kernel
header for RLIMIT_* definitions. The members of struct rlimit
are longs.
Thu Oct 24 17:43:34 1996 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* MakeTAGS (sysdep-dirs): Fix typo.
Wed Oct 23 03:45:22 1996 Ulrich Drepper <drepper@cygnus.com>
* Makefile (headers): Don't mention libc-version.h.
(install-others): ...but here.
* time/strptime.c: Recognize %s, %u, %g, and %G format.
nothing is found. This guarantees all subsequent calls behave
* sysdeps/unix/sysv/linux/syscalls.list: Change function name for
* io/getwd.c (getwd) [! PATH_MAX]: Don't assume that the user's
buffer is any longer than the amount necessary to hold the
filename; the Hurd getcwd uses the *entire* contents of the
buffer, however long it is specified to be.
* posix/getconf.c: De-ANSI-fy. Recognize POSIX.2 constant names.
since these do not depend on the platform.
1996-10-31 03:57:12 +01:00
|
|
|
|
2001-03-12 01:04:52 +01:00
|
|
|
u.x = x;
|
|
|
|
m = u.i[HIGH_HALF];
|
|
|
|
*error = 0;
|
|
|
|
*delta = 0;
|
|
|
|
if (m < 0x00100000) /* 1<x<2^-1007 */
|
|
|
|
{ x = x*t52.x; add = -52.0; u.x = x; m = u.i[HIGH_HALF];}
|
1996-03-05 22:41:30 +01:00
|
|
|
|
2001-03-12 01:04:52 +01:00
|
|
|
if ((m&0x000fffff) < 0x0006a09e)
|
|
|
|
{u.i[HIGH_HALF] = (m&0x000fffff)|0x3ff00000; two52.i[LOW_HALF]=(m>>20); }
|
|
|
|
else
|
|
|
|
{u.i[HIGH_HALF] = (m&0x000fffff)|0x3fe00000; two52.i[LOW_HALF]=(m>>20)+1; }
|
1996-03-05 22:41:30 +01:00
|
|
|
|
2001-03-12 01:04:52 +01:00
|
|
|
v.x = u.x + bigu.x;
|
|
|
|
uu = v.x - bigu.x;
|
|
|
|
i = (v.i[LOW_HALF]&0x000003ff)<<2;
|
|
|
|
if (two52.i[LOW_HALF] == 1023) /* nx = 0 */
|
|
|
|
{
|
|
|
|
if (i > 1192 && i < 1208) /* |x-1| < 1.5*2**-10 */
|
|
|
|
{
|
|
|
|
t = x - 1.0;
|
|
|
|
t1 = (t+5.0e6)-5.0e6;
|
|
|
|
t2 = t-t1;
|
|
|
|
e1 = t - 0.5*t1*t1;
|
|
|
|
e2 = t*t*t*(r3+t*(r4+t*(r5+t*(r6+t*(r7+t*r8)))))-0.5*t2*(t+t1);
|
|
|
|
res = e1+e2;
|
|
|
|
*error = 1.0e-21*ABS(t);
|
|
|
|
*delta = (e1-res)+e2;
|
|
|
|
return res;
|
|
|
|
} /* |x-1| < 1.5*2**-10 */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
v.x = u.x*(ui.x[i]+ui.x[i+1])+bigv.x;
|
|
|
|
vv = v.x-bigv.x;
|
|
|
|
j = v.i[LOW_HALF]&0x0007ffff;
|
|
|
|
j = j+j+j;
|
|
|
|
eps = u.x - uu*vv;
|
|
|
|
e1 = eps*ui.x[i];
|
|
|
|
e2 = eps*(ui.x[i+1]+vj.x[j]*(ui.x[i]+ui.x[i+1]));
|
|
|
|
e = e1+e2;
|
|
|
|
e2 = ((e1-e)+e2);
|
|
|
|
t=ui.x[i+2]+vj.x[j+1];
|
|
|
|
t1 = t+e;
|
|
|
|
t2 = (((t-t1)+e)+(ui.x[i+3]+vj.x[j+2]))+e2+e*e*(p2+e*(p3+e*p4));
|
|
|
|
res=t1+t2;
|
|
|
|
*error = 1.0e-24;
|
|
|
|
*delta = (t1-res)+t2;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
} /* nx = 0 */
|
|
|
|
else /* nx != 0 */
|
|
|
|
{
|
|
|
|
eps = u.x - uu;
|
|
|
|
nx = (two52.x - two52e.x)+add;
|
|
|
|
e1 = eps*ui.x[i];
|
|
|
|
e2 = eps*ui.x[i+1];
|
|
|
|
e=e1+e2;
|
|
|
|
e2 = (e1-e)+e2;
|
|
|
|
t=nx*ln2a.x+ui.x[i+2];
|
|
|
|
t1=t+e;
|
|
|
|
t2=(((t-t1)+e)+nx*ln2b.x+ui.x[i+3]+e2)+e*e*(q2+e*(q3+e*(q4+e*(q5+e*q6))));
|
|
|
|
res = t1+t2;
|
|
|
|
*error = 1.0e-21;
|
|
|
|
*delta = (t1-res)+t2;
|
|
|
|
return res;
|
|
|
|
} /* nx != 0 */
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
/* More slow but more accurate routine of log */
|
|
|
|
/* Computing log(x)(x is left argument).The result is return double + delta.*/
|
|
|
|
/* The result is bounded by error (right argument) */
|
|
|
|
/****************************************************************************/
|
2004-01-23 14:17:52 +01:00
|
|
|
static double my_log2(double x, double *delta, double *error) {
|
2001-03-12 08:57:09 +01:00
|
|
|
int i,j,m;
|
|
|
|
#if 0
|
|
|
|
int n;
|
|
|
|
#endif
|
|
|
|
double uu,vv,eps,nx,e,e1,e2,t,t1,t2,res,add=0;
|
|
|
|
#if 0
|
|
|
|
double cor;
|
|
|
|
#endif
|
2001-03-12 01:04:52 +01:00
|
|
|
double ou1,ou2,lu1,lu2,ov,lv1,lv2,a,a1,a2;
|
|
|
|
double y,yy,z,zz,j1,j2,j3,j4,j5,j6,j7,j8;
|
|
|
|
mynumber u,v;
|
2002-08-24 03:36:09 +02:00
|
|
|
#ifdef BIG_ENDI
|
|
|
|
mynumber
|
|
|
|
/**/ two52 = {{0x43300000, 0x00000000}}; /* 2**52 */
|
|
|
|
#else
|
|
|
|
#ifdef LITTLE_ENDI
|
|
|
|
mynumber
|
|
|
|
/**/ two52 = {{0x00000000, 0x43300000}}; /* 2**52 */
|
|
|
|
#endif
|
|
|
|
#endif
|
2001-03-12 01:04:52 +01:00
|
|
|
|
|
|
|
u.x = x;
|
|
|
|
m = u.i[HIGH_HALF];
|
|
|
|
*error = 0;
|
|
|
|
*delta = 0;
|
|
|
|
add=0;
|
|
|
|
if (m<0x00100000) { /* x < 2^-1022 */
|
|
|
|
x = x*t52.x; add = -52.0; u.x = x; m = u.i[HIGH_HALF]; }
|
1996-03-05 22:41:30 +01:00
|
|
|
|
2001-03-12 01:04:52 +01:00
|
|
|
if ((m&0x000fffff) < 0x0006a09e)
|
|
|
|
{u.i[HIGH_HALF] = (m&0x000fffff)|0x3ff00000; two52.i[LOW_HALF]=(m>>20); }
|
|
|
|
else
|
|
|
|
{u.i[HIGH_HALF] = (m&0x000fffff)|0x3fe00000; two52.i[LOW_HALF]=(m>>20)+1; }
|
|
|
|
|
|
|
|
v.x = u.x + bigu.x;
|
|
|
|
uu = v.x - bigu.x;
|
|
|
|
i = (v.i[LOW_HALF]&0x000003ff)<<2;
|
|
|
|
/*------------------------------------- |x-1| < 2**-11------------------------------- */
|
|
|
|
if ((two52.i[LOW_HALF] == 1023) && (i == 1200))
|
|
|
|
{
|
|
|
|
t = x - 1.0;
|
|
|
|
EMULV(t,s3,y,yy,j1,j2,j3,j4,j5);
|
|
|
|
ADD2(-0.5,0,y,yy,z,zz,j1,j2);
|
|
|
|
MUL2(t,0,z,zz,y,yy,j1,j2,j3,j4,j5,j6,j7,j8);
|
|
|
|
MUL2(t,0,y,yy,z,zz,j1,j2,j3,j4,j5,j6,j7,j8);
|
|
|
|
|
|
|
|
e1 = t+z;
|
|
|
|
e2 = (((t-e1)+z)+zz)+t*t*t*(ss3+t*(s4+t*(s5+t*(s6+t*(s7+t*s8)))));
|
|
|
|
res = e1+e2;
|
|
|
|
*error = 1.0e-25*ABS(t);
|
|
|
|
*delta = (e1-res)+e2;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
/*----------------------------- |x-1| > 2**-11 -------------------------- */
|
|
|
|
else
|
|
|
|
{ /*Computing log(x) according to log table */
|
|
|
|
nx = (two52.x - two52e.x)+add;
|
|
|
|
ou1 = ui.x[i];
|
|
|
|
ou2 = ui.x[i+1];
|
|
|
|
lu1 = ui.x[i+2];
|
|
|
|
lu2 = ui.x[i+3];
|
|
|
|
v.x = u.x*(ou1+ou2)+bigv.x;
|
|
|
|
vv = v.x-bigv.x;
|
|
|
|
j = v.i[LOW_HALF]&0x0007ffff;
|
|
|
|
j = j+j+j;
|
|
|
|
eps = u.x - uu*vv;
|
|
|
|
ov = vj.x[j];
|
|
|
|
lv1 = vj.x[j+1];
|
|
|
|
lv2 = vj.x[j+2];
|
|
|
|
a = (ou1+ou2)*(1.0+ov);
|
|
|
|
a1 = (a+1.0e10)-1.0e10;
|
|
|
|
a2 = a*(1.0-a1*uu*vv);
|
|
|
|
e1 = eps*a1;
|
|
|
|
e2 = eps*a2;
|
|
|
|
e = e1+e2;
|
|
|
|
e2 = (e1-e)+e2;
|
|
|
|
t=nx*ln2a.x+lu1+lv1;
|
|
|
|
t1 = t+e;
|
|
|
|
t2 = (((t-t1)+e)+(lu2+lv2+nx*ln2b.x+e2))+e*e*(p2+e*(p3+e*p4));
|
|
|
|
res=t1+t2;
|
|
|
|
*error = 1.0e-27;
|
|
|
|
*delta = (t1-res)+t2;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
1996-03-05 22:41:30 +01:00
|
|
|
|
2001-03-12 01:04:52 +01:00
|
|
|
/**********************************************************************/
|
|
|
|
/* Routine receives a double x and checks if it is an integer. If not */
|
|
|
|
/* it returns 0, else it returns 1 if even or -1 if odd. */
|
|
|
|
/**********************************************************************/
|
|
|
|
static int checkint(double x) {
|
|
|
|
union {int4 i[2]; double x;} u;
|
2001-03-12 08:57:09 +01:00
|
|
|
int k,m,n;
|
|
|
|
#if 0
|
|
|
|
int l;
|
|
|
|
#endif
|
2001-03-12 01:04:52 +01:00
|
|
|
u.x = x;
|
|
|
|
m = u.i[HIGH_HALF]&0x7fffffff; /* no sign */
|
|
|
|
if (m >= 0x7ff00000) return 0; /* x is +/-inf or NaN */
|
|
|
|
if (m >= 0x43400000) return 1; /* |x| >= 2**53 */
|
|
|
|
if (m < 0x40000000) return 0; /* |x| < 2, can not be 0 or 1 */
|
|
|
|
n = u.i[LOW_HALF];
|
|
|
|
k = (m>>20)-1023; /* 1 <= k <= 52 */
|
|
|
|
if (k == 52) return (n&1)? -1:1; /* odd or even*/
|
|
|
|
if (k>20) {
|
|
|
|
if (n<<(k-20)) return 0; /* if not integer */
|
|
|
|
return (n<<(k-21))?-1:1;
|
|
|
|
}
|
|
|
|
if (n) return 0; /*if not integer*/
|
|
|
|
if (k == 20) return (m&1)? -1:1;
|
|
|
|
if (m<<(k+12)) return 0;
|
|
|
|
return (m<<(k+11))?-1:1;
|
1996-03-05 22:41:30 +01:00
|
|
|
}
|