1996-03-05 21:41:30 +00:00
|
|
|
/*
|
2001-03-12 00:04:52 +00:00
|
|
|
* IBM Accurate Mathematical Library
|
2002-07-06 06:36:39 +00:00
|
|
|
* written by International Business Machines Corp.
|
2018-01-01 00:32:25 +00:00
|
|
|
* Copyright (C) 2001-2018 Free Software Foundation, Inc.
|
1996-03-05 21:41:30 +00:00
|
|
|
*
|
2001-03-12 00:04:52 +00: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-26 22:40:48 +00:00
|
|
|
* the Free Software Foundation; either version 2.1 of the License, or
|
2001-03-12 00:04:52 +00:00
|
|
|
* (at your option) any later version.
|
1996-12-20 01:39:50 +00:00
|
|
|
*
|
2001-03-12 00:04:52 +00: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 21:51:55 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
1996-03-05 21:41:30 +00:00
|
|
|
*
|
2001-03-12 00:04:52 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2012-02-09 23:18:22 +00:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
1996-03-05 21:41:30 +00:00
|
|
|
*/
|
2001-03-12 00:04:52 +00:00
|
|
|
/*********************************************************************/
|
|
|
|
/* */
|
2002-07-06 06:36:39 +00:00
|
|
|
/* MODULE_NAME:ulog.c */
|
2001-03-12 00:04:52 +00:00
|
|
|
/* */
|
|
|
|
/* FUNCTION:ulog */
|
|
|
|
/* */
|
|
|
|
/* FILES NEEDED: dla.h endian.h mpa.h mydefs.h ulog.h */
|
|
|
|
/* ulog.tbl */
|
|
|
|
/* */
|
|
|
|
/* An ultimate log routine. Given an IEEE double machine number x */
|
2018-02-07 12:24:43 +00:00
|
|
|
/* it computes the rounded (to nearest) value of log(x). */
|
2001-03-12 00:04:52 +00:00
|
|
|
/* Assumption: Machine arithmetic operations are performed in */
|
|
|
|
/* round to nearest mode of IEEE 754 standard. */
|
|
|
|
/* */
|
|
|
|
/*********************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#include "endian.h"
|
2011-10-23 16:50:28 +00:00
|
|
|
#include <dla.h>
|
2001-03-12 00:04:52 +00:00
|
|
|
#include "mpa.h"
|
|
|
|
#include "MathLib.h"
|
2015-05-15 10:53:55 +00:00
|
|
|
#include <math.h>
|
2012-03-09 19:29:16 +00:00
|
|
|
#include <math_private.h>
|
2001-05-12 14:32:12 +00:00
|
|
|
|
2011-10-25 04:56:33 +00:00
|
|
|
#ifndef SECTION
|
|
|
|
# define SECTION
|
|
|
|
#endif
|
|
|
|
|
2001-03-12 00:04:52 +00:00
|
|
|
/*********************************************************************/
|
2018-02-07 12:24:43 +00:00
|
|
|
/* An ultimate log routine. Given an IEEE double machine number x */
|
|
|
|
/* it computes the rounded (to nearest) value of log(x). */
|
2001-03-12 00:04:52 +00:00
|
|
|
/*********************************************************************/
|
2011-10-25 04:56:33 +00:00
|
|
|
double
|
|
|
|
SECTION
|
2013-03-29 11:01:52 +00:00
|
|
|
__ieee754_log (double x)
|
|
|
|
{
|
2018-02-07 12:24:43 +00:00
|
|
|
int i, j, n, ux, dx;
|
2013-03-29 11:01:52 +00:00
|
|
|
double dbl_n, u, p0, q, r0, w, nln2a, luai, lubi, lvaj, lvbj,
|
2018-02-07 12:24:43 +00:00
|
|
|
sij, ssij, ttij, A, B, B0, polI, polII, t8, a, aa, b, bb, c;
|
2011-10-24 18:21:18 +00:00
|
|
|
#ifndef DLA_FMS
|
2018-02-07 12:24:43 +00:00
|
|
|
double t1, t2, t3, t4, t5;
|
2011-10-22 23:02:20 +00:00
|
|
|
#endif
|
2001-03-12 00:04:52 +00:00
|
|
|
number num;
|
|
|
|
|
|
|
|
#include "ulog.tbl"
|
|
|
|
#include "ulog.h"
|
|
|
|
|
|
|
|
/* Treating special values of x ( x<=0, x=INF, x=NaN etc.). */
|
|
|
|
|
2013-03-29 11:01:52 +00:00
|
|
|
num.d = x;
|
|
|
|
ux = num.i[HIGH_HALF];
|
|
|
|
dx = num.i[LOW_HALF];
|
|
|
|
n = 0;
|
2014-02-10 13:45:42 +00:00
|
|
|
if (__glibc_unlikely (ux < 0x00100000))
|
2013-03-29 11:01:52 +00:00
|
|
|
{
|
2014-02-10 13:45:42 +00:00
|
|
|
if (__glibc_unlikely (((ux & 0x7fffffff) | dx) == 0))
|
2013-10-17 14:03:24 +00:00
|
|
|
return MHALF / 0.0; /* return -INF */
|
2014-02-10 13:45:42 +00:00
|
|
|
if (__glibc_unlikely (ux < 0))
|
2013-10-17 14:03:24 +00:00
|
|
|
return (x - x) / 0.0; /* return NaN */
|
2013-03-29 11:01:52 +00:00
|
|
|
n -= 54;
|
2013-10-17 14:03:24 +00:00
|
|
|
x *= two54.d; /* scale x */
|
2013-03-29 11:01:52 +00:00
|
|
|
num.d = x;
|
|
|
|
}
|
2014-02-10 13:45:42 +00:00
|
|
|
if (__glibc_unlikely (ux >= 0x7ff00000))
|
2013-10-17 14:03:24 +00:00
|
|
|
return x + x; /* INF or NaN */
|
2001-03-12 00:04:52 +00:00
|
|
|
|
|
|
|
/* Regular values of x */
|
|
|
|
|
2013-03-29 11:10:36 +00:00
|
|
|
w = x - 1;
|
2015-05-15 10:53:55 +00:00
|
|
|
if (__glibc_likely (fabs (w) > U03))
|
2013-03-29 11:01:52 +00:00
|
|
|
goto case_03;
|
2001-03-12 00:04:52 +00:00
|
|
|
|
2014-03-21 18:13:58 +00:00
|
|
|
/* log (1) is +0 in all rounding modes. */
|
|
|
|
if (w == 0.0)
|
|
|
|
return 0.0;
|
|
|
|
|
2018-02-07 12:24:43 +00:00
|
|
|
/*--- The case abs(x-1) < 0.03 */
|
2001-03-12 00:04:52 +00:00
|
|
|
|
2013-03-29 11:01:52 +00:00
|
|
|
t8 = MHALF * w;
|
|
|
|
EMULV (t8, w, a, aa, t1, t2, t3, t4, t5);
|
|
|
|
EADD (w, a, b, bb);
|
2001-03-12 00:04:52 +00:00
|
|
|
/* Evaluate polynomial II */
|
2013-03-29 11:01:52 +00:00
|
|
|
polII = b7.d + w * b8.d;
|
|
|
|
polII = b6.d + w * polII;
|
|
|
|
polII = b5.d + w * polII;
|
|
|
|
polII = b4.d + w * polII;
|
|
|
|
polII = b3.d + w * polII;
|
|
|
|
polII = b2.d + w * polII;
|
|
|
|
polII = b1.d + w * polII;
|
|
|
|
polII = b0.d + w * polII;
|
|
|
|
polII *= w * w * w;
|
|
|
|
c = (aa + bb) + polII;
|
2001-03-12 00:04:52 +00:00
|
|
|
|
2018-02-07 12:24:43 +00:00
|
|
|
/* Here b contains the high part of the result, and c the low part.
|
|
|
|
Maximum error is b * 2.334e-19, so accuracy is >61 bits.
|
|
|
|
Therefore max ULP error of b + c is ~0.502. */
|
|
|
|
return b + c;
|
2001-03-12 00:04:52 +00:00
|
|
|
|
2018-02-07 12:24:43 +00:00
|
|
|
/*--- The case abs(x-1) > 0.03 */
|
2013-03-29 11:01:52 +00:00
|
|
|
case_03:
|
2001-03-12 00:04:52 +00:00
|
|
|
|
|
|
|
/* Find n,u such that x = u*2**n, 1/sqrt(2) < u < sqrt(2) */
|
|
|
|
n += (num.i[HIGH_HALF] >> 20) - 1023;
|
|
|
|
num.i[HIGH_HALF] = (num.i[HIGH_HALF] & 0x000fffff) | 0x3ff00000;
|
2013-03-29 11:01:52 +00:00
|
|
|
if (num.d > SQRT_2)
|
|
|
|
{
|
|
|
|
num.d *= HALF;
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
u = num.d;
|
|
|
|
dbl_n = (double) n;
|
2001-03-12 00:04:52 +00:00
|
|
|
|
|
|
|
/* Find i such that ui=1+(i-75)/2**8 is closest to u (i= 0,1,2,...,181) */
|
|
|
|
num.d += h1.d;
|
|
|
|
i = (num.i[HIGH_HALF] & 0x000fffff) >> 12;
|
|
|
|
|
|
|
|
/* Find j such that vj=1+(j-180)/2**16 is closest to v=u/ui (j= 0,...,361) */
|
2013-03-29 11:01:52 +00:00
|
|
|
num.d = u * Iu[i].d + h2.d;
|
2001-03-12 00:04:52 +00:00
|
|
|
j = (num.i[HIGH_HALF] & 0x000fffff) >> 4;
|
|
|
|
|
|
|
|
/* Compute w=(u-ui*vj)/(ui*vj) */
|
2013-03-29 11:10:36 +00:00
|
|
|
p0 = (1 + (i - 75) * DEL_U) * (1 + (j - 180) * DEL_V);
|
2013-03-29 11:01:52 +00:00
|
|
|
q = u - p0;
|
|
|
|
r0 = Iu[i].d * Iv[j].d;
|
|
|
|
w = q * r0;
|
2001-03-12 00:04:52 +00:00
|
|
|
|
|
|
|
/* Evaluate polynomial I */
|
2013-03-29 11:01:52 +00:00
|
|
|
polI = w + (a2.d + a3.d * w) * w * w;
|
2001-03-12 00:04:52 +00:00
|
|
|
|
|
|
|
/* Add up everything */
|
2013-03-29 11:01:52 +00:00
|
|
|
nln2a = dbl_n * LN2A;
|
|
|
|
luai = Lu[i][0].d;
|
|
|
|
lubi = Lu[i][1].d;
|
|
|
|
lvaj = Lv[j][0].d;
|
|
|
|
lvbj = Lv[j][1].d;
|
|
|
|
EADD (luai, lvaj, sij, ssij);
|
|
|
|
EADD (nln2a, sij, A, ttij);
|
|
|
|
B0 = (((lubi + lvbj) + ssij) + ttij) + dbl_n * LN2B;
|
|
|
|
B = polI + B0;
|
2001-03-12 00:04:52 +00:00
|
|
|
|
2018-02-07 12:24:43 +00:00
|
|
|
/* Here A contains the high part of the result, and B the low part.
|
|
|
|
Maximum abs error is 6.095e-21 and min log (x) is 0.0295 since x > 1.03.
|
|
|
|
Therefore max ULP error of A + B is ~0.502. */
|
|
|
|
return A + B;
|
1996-03-05 21:41:30 +00:00
|
|
|
}
|
2013-03-29 11:01:52 +00:00
|
|
|
|
2011-10-25 00:19:17 +00:00
|
|
|
#ifndef __ieee754_log
|
2011-10-12 15:27:51 +00:00
|
|
|
strong_alias (__ieee754_log, __log_finite)
|
2011-10-25 00:19:17 +00:00
|
|
|
#endif
|