BTRFS: Reimplement TreeIterator, add some error checks and remove redundancies.
[haiku.git] / src / libs / mapm / mapmhasn.c
blob99aae88c336284133ef696a1a68a144b7aaeaca6
2 /*
3 * M_APM - mapmhasn.c
5 * Copyright (C) 2000 - 2007 Michael C. Ring
7 * Permission to use, copy, and distribute this software and its
8 * documentation for any purpose with or without fee is hereby granted,
9 * provided that the above copyright notice appear in all copies and
10 * that both that copyright notice and this permission notice appear
11 * in supporting documentation.
13 * Permission to modify the software is granted. Permission to distribute
14 * the modified code is granted. Modifications are to be distributed by
15 * using the file 'license.txt' as a template to modify the file header.
16 * 'license.txt' is available in the official MAPM distribution.
18 * This software is provided "as is" without express or implied warranty.
22 * $Id: mapmhasn.c,v 1.7 2007/12/03 01:53:33 mike Exp $
24 * This file contains the Inverse Hyperbolic SIN, COS, & TAN functions.
26 * $Log: mapmhasn.c,v $
27 * Revision 1.7 2007/12/03 01:53:33 mike
28 * Update license
30 * Revision 1.6 2003/07/24 16:28:50 mike
31 * update arcsinh
33 * Revision 1.5 2003/07/23 23:08:27 mike
34 * fix problem with arcsinh when input is a very large
35 * negative number.
37 * Revision 1.4 2003/07/21 20:36:33 mike
38 * Modify error messages to be in a consistent format.
40 * Revision 1.3 2003/03/31 21:53:21 mike
41 * call generic error handling function
43 * Revision 1.2 2002/11/03 21:25:03 mike
44 * Updated function parameters to use the modern style
46 * Revision 1.1 2000/04/03 18:16:29 mike
47 * Initial revision
50 #include "m_apm_lc.h"
52 /****************************************************************************/
54 * arcsinh(x) == log [ x + sqrt(x^2 + 1) ]
56 * also, use arcsinh(-x) == -arcsinh(x)
58 void m_apm_arcsinh(M_APM rr, int places, M_APM aa)
60 M_APM tmp0, tmp1, tmp2;
62 /* result is 0 if input is 0 */
64 if (aa->m_apm_sign == 0)
66 M_set_to_zero(rr);
67 return;
70 tmp0 = M_get_stack_var();
71 tmp1 = M_get_stack_var();
72 tmp2 = M_get_stack_var();
74 m_apm_absolute_value(tmp0, aa);
75 m_apm_multiply(tmp1, tmp0, tmp0);
76 m_apm_add(tmp2, tmp1, MM_One);
77 m_apm_sqrt(tmp1, (places + 6), tmp2);
78 m_apm_add(tmp2, tmp0, tmp1);
79 m_apm_log(rr, places, tmp2);
81 rr->m_apm_sign = aa->m_apm_sign; /* fix final sign */
83 M_restore_stack(3);
85 /****************************************************************************/
87 * arccosh(x) == log [ x + sqrt(x^2 - 1) ]
89 * x >= 1.0
91 void m_apm_arccosh(M_APM rr, int places, M_APM aa)
93 M_APM tmp1, tmp2;
94 int ii;
96 ii = m_apm_compare(aa, MM_One);
98 if (ii == -1) /* x < 1 */
100 M_apm_log_error_msg(M_APM_RETURN, "\'m_apm_arccosh\', Argument < 1");
101 M_set_to_zero(rr);
102 return;
105 tmp1 = M_get_stack_var();
106 tmp2 = M_get_stack_var();
108 m_apm_multiply(tmp1, aa, aa);
109 m_apm_subtract(tmp2, tmp1, MM_One);
110 m_apm_sqrt(tmp1, (places + 6), tmp2);
111 m_apm_add(tmp2, aa, tmp1);
112 m_apm_log(rr, places, tmp2);
114 M_restore_stack(2);
116 /****************************************************************************/
118 * arctanh(x) == 0.5 * log [ (1 + x) / (1 - x) ]
120 * |x| < 1.0
122 void m_apm_arctanh(M_APM rr, int places, M_APM aa)
124 M_APM tmp1, tmp2, tmp3;
125 int ii, local_precision;
127 tmp1 = M_get_stack_var();
129 m_apm_absolute_value(tmp1, aa);
131 ii = m_apm_compare(tmp1, MM_One);
133 if (ii >= 0) /* |x| >= 1.0 */
135 M_apm_log_error_msg(M_APM_RETURN, "\'m_apm_arctanh\', |Argument| >= 1");
136 M_set_to_zero(rr);
137 M_restore_stack(1);
138 return;
141 tmp2 = M_get_stack_var();
142 tmp3 = M_get_stack_var();
144 local_precision = places + 8;
146 m_apm_add(tmp1, MM_One, aa);
147 m_apm_subtract(tmp2, MM_One, aa);
148 m_apm_divide(tmp3, local_precision, tmp1, tmp2);
149 m_apm_log(tmp2, local_precision, tmp3);
150 m_apm_multiply(tmp1, tmp2, MM_0_5);
151 m_apm_round(rr, places, tmp1);
153 M_restore_stack(3);
155 /****************************************************************************/