1 | /* e_acoshl.c -- long double version of e_acosh.c. |
2 | * Conversion to long double by Ulrich Drepper, |
3 | * Cygnus Support, drepper@cygnus.com. |
4 | */ |
5 | |
6 | /* |
7 | * ==================================================== |
8 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. |
9 | * |
10 | * Developed at SunPro, a Sun Microsystems, Inc. business. |
11 | * Permission to use, copy, modify, and distribute this |
12 | * software is freely granted, provided that this notice |
13 | * is preserved. |
14 | * ==================================================== |
15 | */ |
16 | |
17 | /* __ieee754_acoshl(x) |
18 | * Method : |
19 | * Based on |
20 | * acoshl(x) = logl [ x + sqrtl(x*x-1) ] |
21 | * we have |
22 | * acoshl(x) := logl(x)+ln2, if x is large; else |
23 | * acoshl(x) := logl(2x-1/(sqrtl(x*x-1)+x)) if x>2; else |
24 | * acoshl(x) := log1pl(t+sqrtl(2.0*t+t*t)); where t=x-1. |
25 | * |
26 | * Special cases: |
27 | * acoshl(x) is NaN with signal if x<1. |
28 | * acoshl(NaN) is NaN without signal. |
29 | */ |
30 | |
31 | #include <math.h> |
32 | #include <math_private.h> |
33 | #include <libm-alias-finite.h> |
34 | |
35 | static const long double |
36 | one = 1.0, |
37 | ln2 = 6.931471805599453094287e-01L; /* 0x3FFE, 0xB17217F7, 0xD1CF79AC */ |
38 | |
39 | long double |
40 | __ieee754_acoshl(long double x) |
41 | { |
42 | long double t; |
43 | uint32_t se,i0,i1; |
44 | GET_LDOUBLE_WORDS(se,i0,i1,x); |
45 | if(se<0x3fff || se & 0x8000) { /* x < 1 */ |
46 | return (x-x)/(x-x); |
47 | } else if(se >=0x401d) { /* x > 2**30 */ |
48 | if(se >=0x7fff) { /* x is inf of NaN */ |
49 | return x+x; |
50 | } else |
51 | return __ieee754_logl(x)+ln2; /* acoshl(huge)=logl(2x) */ |
52 | } else if(((se-0x3fff)|(i0^0x80000000)|i1)==0) { |
53 | return 0.0; /* acosh(1) = 0 */ |
54 | } else if (se > 0x4000) { /* 2**28 > x > 2 */ |
55 | t=x*x; |
56 | return __ieee754_logl(2.0*x-one/(x+sqrtl(t-one))); |
57 | } else { /* 1<x<2 */ |
58 | t = x-one; |
59 | return __log1pl(t+sqrtl(2.0*t+t*t)); |
60 | } |
61 | } |
62 | libm_alias_finite (__ieee754_acoshl, __acoshl) |
63 | |