[444] | 1 | |
---|
| 2 | /* @(#)e_acosh.c 5.1 93/09/24 */ |
---|
| 3 | |
---|
| 4 | /* |
---|
| 5 | FUNCTION |
---|
| 6 | <<acosh>>, <<acoshf>>---inverse hyperbolic cosine |
---|
| 7 | |
---|
| 8 | INDEX |
---|
| 9 | acosh |
---|
| 10 | INDEX |
---|
| 11 | acoshf |
---|
| 12 | |
---|
| 13 | SYNOPSIS |
---|
| 14 | #include <math.h> |
---|
| 15 | double acosh(double <[x]>); |
---|
| 16 | float acoshf(float <[x]>); |
---|
| 17 | |
---|
| 18 | DESCRIPTION |
---|
| 19 | <<acosh>> calculates the inverse hyperbolic cosine of <[x]>. |
---|
| 20 | <<acosh>> is defined as |
---|
| 21 | @ifnottex |
---|
| 22 | . log(<[x]> + sqrt(<[x]>*<[x]>-1)) |
---|
| 23 | @end ifnottex |
---|
| 24 | @tex |
---|
| 25 | $$ln\Bigl(x + \sqrt{x^2-1}\Bigr)$$ |
---|
| 26 | @end tex |
---|
| 27 | |
---|
| 28 | <[x]> must be a number greater than or equal to 1. |
---|
| 29 | |
---|
| 30 | <<acoshf>> is identical, other than taking and returning floats. |
---|
| 31 | |
---|
| 32 | RETURNS |
---|
| 33 | <<acosh>> and <<acoshf>> return the calculated value. If <[x]> |
---|
| 34 | less than 1, the return value is NaN and <<errno>> is set to <<EDOM>>. |
---|
| 35 | |
---|
| 36 | You can change the error-handling behavior with the non-ANSI |
---|
| 37 | <<matherr>> function. |
---|
| 38 | |
---|
| 39 | PORTABILITY |
---|
| 40 | Neither <<acosh>> nor <<acoshf>> are ANSI C. They are not recommended |
---|
| 41 | for portable programs. |
---|
| 42 | |
---|
| 43 | |
---|
| 44 | QUICKREF |
---|
| 45 | ansi svid posix rentrant |
---|
| 46 | acos n,n,n,m |
---|
| 47 | acosf n,n,n,m |
---|
| 48 | |
---|
| 49 | MATHREF |
---|
| 50 | acosh, NAN, arg,DOMAIN,EDOM |
---|
| 51 | acosh, < 1.0, NAN,DOMAIN,EDOM |
---|
| 52 | acosh, >=1.0, acosh(arg),,, |
---|
| 53 | |
---|
| 54 | MATHREF |
---|
| 55 | acoshf, NAN, arg,DOMAIN,EDOM |
---|
| 56 | acoshf, < 1.0, NAN,DOMAIN,EDOM |
---|
| 57 | acoshf, >=1.0, acosh(arg),,, |
---|
| 58 | |
---|
| 59 | */ |
---|
| 60 | |
---|
| 61 | /* |
---|
| 62 | * ==================================================== |
---|
| 63 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. |
---|
| 64 | * |
---|
| 65 | * Developed at SunPro, a Sun Microsystems, Inc. business. |
---|
| 66 | * Permission to use, copy, modify, and distribute this |
---|
| 67 | * software is freely granted, provided that this notice |
---|
| 68 | * is preserved. |
---|
| 69 | * ==================================================== |
---|
| 70 | * |
---|
| 71 | */ |
---|
| 72 | |
---|
| 73 | /* acosh(x) |
---|
| 74 | * Method : |
---|
| 75 | * Based on |
---|
| 76 | * acosh(x) = log [ x + sqrt(x*x-1) ] |
---|
| 77 | * we have |
---|
| 78 | * acosh(x) := log(x)+ln2, if x is large; else |
---|
| 79 | * acosh(x) := log(2x-1/(sqrt(x*x-1)+x)) if x>2; else |
---|
| 80 | * acosh(x) := log1p(t+sqrt(2.0*t+t*t)); where t=x-1. |
---|
| 81 | * |
---|
| 82 | * Special cases: |
---|
| 83 | * acosh(x) is NaN with signal if x<1. |
---|
| 84 | * acosh(NaN) is NaN without signal. |
---|
| 85 | */ |
---|
| 86 | |
---|
| 87 | #include "fdlibm.h" |
---|
| 88 | |
---|
| 89 | #ifndef _DOUBLE_IS_32BITS |
---|
| 90 | |
---|
| 91 | #ifdef __STDC__ |
---|
| 92 | static const double |
---|
| 93 | #else |
---|
| 94 | static double |
---|
| 95 | #endif |
---|
| 96 | one = 1.0, |
---|
| 97 | ln2 = 6.93147180559945286227e-01; /* 0x3FE62E42, 0xFEFA39EF */ |
---|
| 98 | |
---|
| 99 | #ifdef __STDC__ |
---|
| 100 | double acosh(double x) |
---|
| 101 | #else |
---|
| 102 | double acosh(x) |
---|
| 103 | double x; |
---|
| 104 | #endif |
---|
| 105 | { |
---|
| 106 | double t; |
---|
| 107 | __int32_t hx; |
---|
| 108 | __uint32_t lx; |
---|
| 109 | EXTRACT_WORDS(hx,lx,x); |
---|
| 110 | if(hx<0x3ff00000) { /* x < 1 */ |
---|
| 111 | return (x-x)/(x-x); |
---|
| 112 | } else if(hx >=0x41b00000) { /* x > 2**28 */ |
---|
| 113 | if(hx >=0x7ff00000) { /* x is inf of NaN */ |
---|
| 114 | return x+x; |
---|
| 115 | } else |
---|
| 116 | return log(x)+ln2; /* acosh(huge)=log(2x) */ |
---|
| 117 | } else if(((hx-0x3ff00000)|lx)==0) { |
---|
| 118 | return 0.0; /* acosh(1) = 0 */ |
---|
| 119 | } else if (hx > 0x40000000) { /* 2**28 > x > 2 */ |
---|
| 120 | t=x*x; |
---|
| 121 | return log(2.0*x-one/(x+sqrt(t-one))); |
---|
| 122 | } else { /* 1<x<2 */ |
---|
| 123 | t = x-one; |
---|
| 124 | return log1p(t+sqrt(2.0*t+t*t)); |
---|
| 125 | } |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | #endif /* defined(_DOUBLE_IS_32BITS) */ |
---|