From owner-freebsd-numerics@FreeBSD.ORG Fri May 31 19:14:10 2013 Return-Path: Delivered-To: freebsd-numerics@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 7CADEB72 for ; Fri, 31 May 2013 19:14:10 +0000 (UTC) (envelope-from sgk@troutmask.apl.washington.edu) Received: from troutmask.apl.washington.edu (troutmask.apl.washington.edu [128.95.76.21]) by mx1.freebsd.org (Postfix) with ESMTP id 62755868 for ; Fri, 31 May 2013 19:14:10 +0000 (UTC) Received: from troutmask.apl.washington.edu (localhost.apl.washington.edu [127.0.0.1]) by troutmask.apl.washington.edu (8.14.6/8.14.6) with ESMTP id r4VJEA0D074365 for ; Fri, 31 May 2013 12:14:10 -0700 (PDT) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.14.6/8.14.6/Submit) id r4VJEA9d074364 for freebsd-numerics@freebsd.org; Fri, 31 May 2013 12:14:10 -0700 (PDT) (envelope-from sgk) Date: Fri, 31 May 2013 12:14:10 -0700 From: Steve Kargl To: freebsd-numerics@freebsd.org Subject: cosh magic number? Message-ID: <20130531191410.GA74343@troutmask.apl.washington.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-BeenThere: freebsd-numerics@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Discussions of high quality implementation of libm functions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 31 May 2013 19:14:10 -0000 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 #include 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