blob: 740ac680e857070c950d4e0d52d019ad4c225ab6 [file] [log] [blame]
Rich Felkerb69f6952012-03-13 01:17:53 -04001#include "libm.h"
2
nszdf8b3e52012-03-13 16:38:22 +01003/* k is such that k*ln2 has minimal relative error and x - kln2 > log(DBL_MIN) */
4static const int k = 2043;
5static const double kln2 = 0x1.62066151add8bp+10;
Rich Felkerb69f6952012-03-13 01:17:53 -04006
nszdf8b3e52012-03-13 16:38:22 +01007/* exp(x)/2 for x >= log(DBL_MAX), slightly better than 0.5*exp(x/2)*exp(x/2) */
Rich Felkerb69f6952012-03-13 01:17:53 -04008double __expo2(double x)
9{
10 double scale;
Rich Felkerb69f6952012-03-13 01:17:53 -040011
nszdf8b3e52012-03-13 16:38:22 +010012 /* note that k is odd and scale*scale overflows */
13 INSERT_WORDS(scale, (uint32_t)(0x3ff + k/2) << 20, 0);
14 /* exp(x - k ln2) * 2**(k-1) */
Rich Felkerb69f6952012-03-13 01:17:53 -040015 return exp(x - kln2) * scale * scale;
16}