exp2.c
Go to the documentation of this file.
1 /* exp2.c
2  *
3  * Base 2 exponential function
4  *
5  *
6  *
7  * SYNOPSIS:
8  *
9  * double x, y, exp2();
10  *
11  * y = exp2( x );
12  *
13  *
14  *
15  * DESCRIPTION:
16  *
17  * Returns 2 raised to the x power.
18  *
19  * Range reduction is accomplished by separating the argument
20  * into an integer k and fraction f such that
21  * x k f
22  * 2 = 2 2.
23  *
24  * A Pade' form
25  *
26  * 1 + 2x P(x**2) / (Q(x**2) - x P(x**2) )
27  *
28  * approximates 2**x in the basic range [-0.5, 0.5].
29  *
30  *
31  * ACCURACY:
32  *
33  * Relative error:
34  * arithmetic domain # trials peak rms
35  * IEEE -1022,+1024 30000 1.8e-16 5.4e-17
36  *
37  *
38  * See exp.c for comments on error amplification.
39  *
40  *
41  * ERROR MESSAGES:
42  *
43  * message condition value returned
44  * exp underflow x < -MAXL2 0.0
45  * exp overflow x > MAXL2 INFINITY
46  *
47  * For IEEE arithmetic, MAXL2 = 1024.
48  */
49 
50 
51 /*
52  * Cephes Math Library Release 2.3: March, 1995
53  * Copyright 1984, 1995 by Stephen L. Moshier
54  */
55 
56 
57 
58 #include "mconf.h"
59 
60 static double P[] = {
61  2.30933477057345225087E-2,
62  2.02020656693165307700E1,
63  1.51390680115615096133E3,
64 };
65 
66 static double Q[] = {
67  /* 1.00000000000000000000E0, */
68  2.33184211722314911771E2,
69  4.36821166879210612817E3,
70 };
71 
72 #define MAXL2 1024.0
73 #define MINL2 -1024.0
74 
75 double exp2(double x)
76 {
77  double px, xx;
78  short n;
79 
80  if (cephes_isnan(x))
81  return (x);
82  if (x > MAXL2) {
83  return (INFINITY);
84  }
85 
86  if (x < MINL2) {
87  return (0.0);
88  }
89 
90  xx = x; /* save x */
91  /* separate into integer and fractional parts */
92  px = floor(x + 0.5);
93  n = px;
94  x = x - px;
95 
96  /* rational approximation
97  * exp2(x) = 1 + 2xP(xx)/(Q(xx) - P(xx))
98  * where xx = x**2
99  */
100  xx = x * x;
101  px = x * polevl(xx, P, 2);
102  x = px / (p1evl(xx, Q, 2) - px);
103  x = 1.0 + ldexp(x, 1);
104 
105  /* scale by power of 2 */
106  x = ldexp(x, n);
107  return (x);
108 }
cephes_isnan
#define cephes_isnan(x)
Definition: mconf.h:99
x
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Definition: gnuplot_common_settings.hh:12
exp2
double exp2(double x)
Definition: exp2.c:75
MINL2
#define MINL2
Definition: exp2.c:73
p1evl
static double p1evl(double x, const double coef[], int N)
Definition: polevl.h:97
n
int n
Definition: BiCGSTAB_simple.cpp:1
polevl
static double polevl(double x, const double coef[], int N)
Definition: polevl.h:65
P
static double P[]
Definition: exp2.c:60
MAXL2
#define MAXL2
Definition: exp2.c:72
Eigen::Quaternion
The quaternion class used to represent 3D orientations and rotations.
Definition: ForwardDeclarations.h:293
mconf.h
floor
const EIGEN_DEVICE_FUNC FloorReturnType floor() const
Definition: ArrayCwiseUnaryOps.h:481
px
RealScalar RealScalar * px
Definition: level1_cplx_impl.h:28


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:11:31