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.
23
* This file contains the Hyperbolic SIN, COS, & TAN functions.
27
#include "pgscript/utilities/mapm-lib/m_apm_lc.h"
29
/****************************************************************************/
31
* sinh(x) == 0.5 * [ exp(x) - exp(-x) ]
33
void m_apm_sinh(M_APM rr, int places, M_APM aa)
35
M_APM tmp1, tmp2, tmp3;
38
tmp1 = M_get_stack_var();
39
tmp2 = M_get_stack_var();
40
tmp3 = M_get_stack_var();
42
local_precision = places + 4;
44
m_apm_exp(tmp1, local_precision, aa);
45
m_apm_reciprocal(tmp2, local_precision, tmp1);
46
m_apm_subtract(tmp3, tmp1, tmp2);
47
m_apm_multiply(tmp1, tmp3, MM_0_5);
48
m_apm_round(rr, places, tmp1);
52
/****************************************************************************/
54
* cosh(x) == 0.5 * [ exp(x) + exp(-x) ]
56
void m_apm_cosh(M_APM rr, int places, M_APM aa)
58
M_APM tmp1, tmp2, tmp3;
61
tmp1 = M_get_stack_var();
62
tmp2 = M_get_stack_var();
63
tmp3 = M_get_stack_var();
65
local_precision = places + 4;
67
m_apm_exp(tmp1, local_precision, aa);
68
m_apm_reciprocal(tmp2, local_precision, tmp1);
69
m_apm_add(tmp3, tmp1, tmp2);
70
m_apm_multiply(tmp1, tmp3, MM_0_5);
71
m_apm_round(rr, places, tmp1);
75
/****************************************************************************/
77
* tanh(x) == [ exp(x) - exp(-x) ] / [ exp(x) + exp(-x) ]
79
void m_apm_tanh(M_APM rr, int places, M_APM aa)
81
M_APM tmp1, tmp2, tmp3, tmp4;
84
tmp1 = M_get_stack_var();
85
tmp2 = M_get_stack_var();
86
tmp3 = M_get_stack_var();
87
tmp4 = M_get_stack_var();
89
local_precision = places + 4;
91
m_apm_exp(tmp1, local_precision, aa);
92
m_apm_reciprocal(tmp2, local_precision, tmp1);
93
m_apm_subtract(tmp3, tmp1, tmp2);
94
m_apm_add(tmp4, tmp1, tmp2);
95
m_apm_divide(tmp1, local_precision, tmp3, tmp4);
96
m_apm_round(rr, places, tmp1);
100
/****************************************************************************/