1
2 /*
3 * M_APM - mapmhsin.c
4 *
5 * Copyright (C) 2000 - 2007 Michael C. Ring
6 *
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.
12 *
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.
17 *
18 * This software is provided "as is" without express or implied warranty.
19 */
20
21 /*
22 * $Id: mapmhsin.c,v 1.4 2007/12/03 01:54:06 mike Exp $
23 *
24 * This file contains the Hyperbolic SIN, COS, & TAN functions.
25 *
26 * $Log: mapmhsin.c,v $
27 * Revision 1.4 2007/12/03 01:54:06 mike
28 * Update license
29 *
30 * Revision 1.3 2002/11/03 21:29:20 mike
31 * Updated function parameters to use the modern style
32 *
33 * Revision 1.2 2000/09/23 19:52:56 mike
34 * change divide call to reciprocal
35 *
36 * Revision 1.1 2000/04/03 18:16:26 mike
37 * Initial revision
38 */
39
40 #include "m_apm_lc.h"
41
42 /****************************************************************************/
43 /*
44 * sinh(x) == 0.5 * [ exp(x) - exp(-x) ]
45 */
m_apm_sinh(M_APM rr,int places,M_APM aa)46 void m_apm_sinh(M_APM rr, int places, M_APM aa)
47 {
48 M_APM tmp1, tmp2, tmp3;
49 int local_precision;
50
51 tmp1 = M_get_stack_var();
52 tmp2 = M_get_stack_var();
53 tmp3 = M_get_stack_var();
54
55 local_precision = places + 4;
56
57 m_apm_exp(tmp1, local_precision, aa);
58 m_apm_reciprocal(tmp2, local_precision, tmp1);
59 m_apm_subtract(tmp3, tmp1, tmp2);
60 m_apm_multiply(tmp1, tmp3, MM_0_5);
61 m_apm_round(rr, places, tmp1);
62
63 M_restore_stack(3);
64 }
65 /****************************************************************************/
66 /*
67 * cosh(x) == 0.5 * [ exp(x) + exp(-x) ]
68 */
m_apm_cosh(M_APM rr,int places,M_APM aa)69 void m_apm_cosh(M_APM rr, int places, M_APM aa)
70 {
71 M_APM tmp1, tmp2, tmp3;
72 int local_precision;
73
74 tmp1 = M_get_stack_var();
75 tmp2 = M_get_stack_var();
76 tmp3 = M_get_stack_var();
77
78 local_precision = places + 4;
79
80 m_apm_exp(tmp1, local_precision, aa);
81 m_apm_reciprocal(tmp2, local_precision, tmp1);
82 m_apm_add(tmp3, tmp1, tmp2);
83 m_apm_multiply(tmp1, tmp3, MM_0_5);
84 m_apm_round(rr, places, tmp1);
85
86 M_restore_stack(3);
87 }
88 /****************************************************************************/
89 /*
90 * tanh(x) == [ exp(x) - exp(-x) ] / [ exp(x) + exp(-x) ]
91 */
m_apm_tanh(M_APM rr,int places,M_APM aa)92 void m_apm_tanh(M_APM rr, int places, M_APM aa)
93 {
94 M_APM tmp1, tmp2, tmp3, tmp4;
95 int local_precision;
96
97 tmp1 = M_get_stack_var();
98 tmp2 = M_get_stack_var();
99 tmp3 = M_get_stack_var();
100 tmp4 = M_get_stack_var();
101
102 local_precision = places + 4;
103
104 m_apm_exp(tmp1, local_precision, aa);
105 m_apm_reciprocal(tmp2, local_precision, tmp1);
106 m_apm_subtract(tmp3, tmp1, tmp2);
107 m_apm_add(tmp4, tmp1, tmp2);
108 m_apm_divide(tmp1, local_precision, tmp3, tmp4);
109 m_apm_round(rr, places, tmp1);
110
111 M_restore_stack(4);
112 }
113 /****************************************************************************/
114