~ubuntu-branches/ubuntu/breezy/uclibc/breezy

« back to all changes in this revision

Viewing changes to test/math/eexp.c

  • Committer: Bazaar Package Importer
  • Author(s): David Schleef
  • Date: 2005-04-18 13:29:53 UTC
  • mfrom: (1.1.1 upstream) (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050418132953-hzuzafmpkxuj0gvj
Tags: 0.9.27-1
* New upstream release.
* Acknowledge NMU (Closes: #268989) and fix the bug it caused
  (Closes: #284326)
* Add gross versioned dependency for gcc-3.3, and make sure we use
  gcc-3.3 in the gcc wrapper. (Closes: #304806)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*                                                      xexp.c          */
2
 
/* exponential function check routine */
3
 
/* by Stephen L. Moshier. */
4
 
 
5
 
 
6
 
#include "ehead.h"
7
 
 
8
 
/*
9
 
extern int powinited;
10
 
extern short maxposint[], maxnegint[];
11
 
*/
12
 
 
13
 
void eexp( x, y )
14
 
unsigned short *x, *y;
15
 
{
16
 
unsigned short num[NE], den[NE], x2[NE];
17
 
long i;
18
 
unsigned short sign, expchk;
19
 
 
20
 
/* range reduction theory: x = i + f, 0<=f<1;
21
 
 * e**x = e**i * e**f 
22
 
 * e**i = 2**(i/log 2).
23
 
 * Let i/log2 = i1 + f1, 0<=f1<1.
24
 
 * Then e**i = 2**i1 * 2**f1, so
25
 
 * e**x = 2**i1 * e**(log 2 * f1) * e**f.
26
 
 */
27
 
/*
28
 
if( powinited == 0 )
29
 
        initpow();
30
 
*/
31
 
if( ecmp(x, ezero) == 0 )
32
 
        {
33
 
        emov( eone, y );
34
 
        return;
35
 
        }
36
 
emov(x, x2);
37
 
expchk = x2[NE-1];
38
 
sign = expchk & 0x8000;
39
 
x2[NE-1] &= 0x7fff;
40
 
 
41
 
/* Test for excessively large argument */
42
 
expchk &= 0x7fff;
43
 
if( expchk > (EXONE + 15) )
44
 
        {
45
 
        eclear( y );
46
 
        if( sign == 0 )
47
 
                einfin( y );
48
 
        return;
49
 
        }
50
 
 
51
 
eifrac( x2, &i, num );          /* x = i + f            */
52
 
 
53
 
if( i != 0 )
54
 
 {
55
 
 ltoe( &i, den );               /* floating point i     */
56
 
 ediv( elog2, den, den );       /* i/log 2              */
57
 
 eifrac( den, &i, den );        /* i/log 2  =  i1 + f1  */
58
 
 emul( elog2, den, den );       /* log 2 * f1           */
59
 
 eadd( den, num, x2 );          /* log 2 * f1  + f      */
60
 
 }
61
 
 
62
 
/*x2[NE-1] -= 1;*/
63
 
eldexp( x2, -1L, x2 ); /* divide by 2 */
64
 
etanh( x2, x2 );        /* tanh( x/2 )                  */
65
 
eadd( x2, eone, num );  /* 1 + tanh                     */
66
 
eneg( x2 );
67
 
eadd( x2, eone, den );  /* 1 - tanh                     */
68
 
ediv( den, num, y );    /* (1 + tanh)/(1 - tanh)        */
69
 
 
70
 
/*y[NE-1] += i;*/
71
 
if( sign )
72
 
        {
73
 
        ediv( y, eone, y );
74
 
        i = -i;
75
 
        }
76
 
eldexp( y, i, y );      /* multiply by 2**i */
77
 
}