Date: Fri, 31 May 2013 12:14:10 -0700 From: Steve Kargl <sgk@troutmask.apl.washington.edu> To: freebsd-numerics@freebsd.org Subject: cosh magic number? Message-ID: <20130531191410.GA74343@troutmask.apl.washington.edu>
index | next in thread | raw e-mail
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
home |
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20130531191410.GA74343>
