cosh magic number?
Steve Kargl
sgk at troutmask.apl.washington.edu
Fri May 31 19:14:10 UTC 2013
In msun/src/e_cosh.c, one finds the comment
*
* exp(x) + 1/exp(x)
* ln2/2 <= x <= 22 : cosh(x) := -------------------
* 2
Where does the magic number 22 come from?
Using exp(-|2x|) = 2**(1-p) with p = 53 for double, I
arrive at 18.022, which is a little too small.
#include <stdio.h>
#include <math.h>
int
main(void)
{
double x, y, z;
x = 18.022;
/* x = 19; */
y = exp(x);
z = cosh(x);
printf("%a\n%a\n%a\n", z, 0.5*(y + 1/y), 0.5 * y);
return 0;
}
% cc -o z -O a.c -lm && ./z
0x1.000b5bd5b4beep+25
0x1.000b5bd5b4beep+25
0x1.000b5bd5b4bedp+25
Rounding up to 19 gives
% cc -o z -O a.c -lm && ./z
0x1.546d8f9ed26e1p+26
0x1.546d8f9ed26e1p+26
0x1.546d8f9ed26e1p+26
So, why 22?
--
Steve
More information about the freebsd-numerics
mailing list