116748Sjmallett#include "libm.h"
216748Sjmallett
31590Srgrimes#if FLT_EVAL_METHOD==2
41590Srgrimes#undef sqrtf
51590Srgrimes#define sqrtf sqrtl
61590Srgrimes#elif FLT_EVAL_METHOD==1
71590Srgrimes#undef sqrtf
81590Srgrimes#define sqrtf sqrt
91590Srgrimes#endif
101590Srgrimes
111590Srgrimes/* acosh(x) = log(x + sqrt(x*x-1)) */
121590Srgrimesfloat acoshf(float x)
131590Srgrimes{
141590Srgrimes	union {float f; uint32_t i;} u = {x};
151590Srgrimes	uint32_t a = u.i & 0x7fffffff;
161590Srgrimes
171590Srgrimes	if (a < 0x3f800000+(1<<23))
181590Srgrimes		/* |x| < 2, invalid if x < 1 or nan */
191590Srgrimes		/* up to 2ulp error in [1,1.125] */
201590Srgrimes		return log1pf(x-1 + sqrtf((x-1)*(x-1)+2*(x-1)));
211590Srgrimes	if (a < 0x3f800000+(12<<23))
221590Srgrimes		/* |x| < 0x1p12 */
231590Srgrimes		return logf(2*x - 1/(x+sqrtf(x*x-1)));
241590Srgrimes	/* x >= 0x1p12 */
251590Srgrimes	return logf(x) + 0.693147180559945309417232121458176568f;
261590Srgrimes}
271590Srgrimes