~ubuntu-branches/debian/sid/pgadmin3/sid

« back to all changes in this revision

Viewing changes to pgadmin/pgscript/utilities/m_apm/mapmrsin.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Gerfried Fuchs
  • Date: 2009-07-30 12:27:16 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20090730122716-fddbh42on721bbs2
Tags: 1.10.0-1
* New upstream release.
* Adjusted watch file to match release candidates.
* Updated to Standards-Version 3.8.2:
  - Moved to Section: database.
  - Add DEB_BUILD_OPTIONS support for parallel building.
  - Move from findstring to filter suggestion for DEB_BUILD_OPTIONS parsing.
* pgagent got split into its own separate source package by upstream.
* Exclude Docs.vcproj from installation.
* Move doc-base.enus from pgadmin3 to pgadmin3-data package, the files are
  in there too.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/* 
 
3
 *  M_APM  -  mapmrsin.c
 
4
 *
 
5
 *  Copyright (C) 1999 - 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
 *
 
23
 *      This file contains the basic series expansion functions for 
 
24
 *      the SIN / COS functions.
 
25
 */
 
26
 
 
27
#include "pgAdmin3.h"
 
28
#include "pgscript/utilities/mapm-lib/m_apm_lc.h"
 
29
 
 
30
/****************************************************************************/
 
31
/*
 
32
                                  x^3     x^5     x^7     x^9
 
33
                 sin(x)  =  x  -  ---  +  ---  -  ---  +  ---  ...
 
34
                                   3!      5!      7!      9!
 
35
*/
 
36
void    M_raw_sin(M_APM rr, int places, M_APM xx)
 
37
{
 
38
M_APM   sum, term, tmp2, tmp7, tmp8;
 
39
int     tolerance, flag, local_precision, dplaces;
 
40
long    m1, m2;
 
41
 
 
42
sum  = M_get_stack_var();
 
43
term = M_get_stack_var();
 
44
tmp2 = M_get_stack_var();
 
45
tmp7 = M_get_stack_var();
 
46
tmp8 = M_get_stack_var();
 
47
 
 
48
m_apm_copy(sum, xx);
 
49
m_apm_copy(term, xx);
 
50
m_apm_multiply(tmp8, xx, xx);
 
51
m_apm_round(tmp2, (places + 6), tmp8);
 
52
 
 
53
dplaces   = (places + 8) - xx->m_apm_exponent;
 
54
tolerance = xx->m_apm_exponent - (places + 4);
 
55
 
 
56
m1   = 2L;
 
57
flag = 0;
 
58
 
 
59
while (TRUE)
 
60
  {
 
61
   m_apm_multiply(tmp8, term, tmp2);
 
62
 
 
63
   if ((tmp8->m_apm_exponent < tolerance) || (tmp8->m_apm_sign == 0))
 
64
     break;
 
65
 
 
66
   local_precision = dplaces + term->m_apm_exponent;
 
67
 
 
68
   if (local_precision < 20)
 
69
     local_precision = 20;
 
70
 
 
71
   m2 = m1 * (m1 + 1);
 
72
   m_apm_set_long(tmp7, m2);
 
73
 
 
74
   m_apm_divide(term, local_precision, tmp8, tmp7);
 
75
 
 
76
   if (flag == 0)
 
77
     {
 
78
      m_apm_subtract(tmp7, sum, term);
 
79
      m_apm_copy(sum, tmp7);
 
80
     }
 
81
   else
 
82
     {
 
83
      m_apm_add(tmp7, sum, term);
 
84
      m_apm_copy(sum, tmp7);
 
85
     }
 
86
 
 
87
   m1 += 2;
 
88
   flag = 1 - flag;
 
89
  }
 
90
 
 
91
m_apm_round(rr, places, sum);
 
92
M_restore_stack(5);
 
93
}
 
94
/****************************************************************************/
 
95
/*
 
96
                                  x^2     x^4     x^6     x^8
 
97
                 cos(x)  =  1  -  ---  +  ---  -  ---  +  ---  ...
 
98
                                   2!      4!      6!      8!
 
99
*/
 
100
void    M_raw_cos(M_APM rr, int places, M_APM xx)
 
101
{
 
102
M_APM   sum, term, tmp7, tmp8, tmp9;
 
103
int     tolerance, flag, local_precision, prev_exp;
 
104
long    m1, m2;
 
105
 
 
106
sum  = M_get_stack_var();
 
107
term = M_get_stack_var();
 
108
tmp7 = M_get_stack_var();
 
109
tmp8 = M_get_stack_var();
 
110
tmp9 = M_get_stack_var();
 
111
 
 
112
m_apm_copy(sum, MM_One);
 
113
m_apm_copy(term, MM_One);
 
114
 
 
115
m_apm_multiply(tmp8, xx, xx);
 
116
m_apm_round(tmp9, (places + 6), tmp8);
 
117
 
 
118
local_precision = places + 8;
 
119
tolerance       = -(places + 4);
 
120
prev_exp        = 0;
 
121
 
 
122
m1   = 1L;
 
123
flag = 0;
 
124
 
 
125
while (TRUE)
 
126
  {
 
127
   m2 = m1 * (m1 + 1);
 
128
   m_apm_set_long(tmp7, m2);
 
129
 
 
130
   m_apm_multiply(tmp8, term, tmp9);
 
131
   m_apm_divide(term, local_precision, tmp8, tmp7);
 
132
 
 
133
   if (flag == 0)
 
134
     {
 
135
      m_apm_subtract(tmp7, sum, term);
 
136
      m_apm_copy(sum, tmp7);
 
137
     }
 
138
   else
 
139
     {
 
140
      m_apm_add(tmp7, sum, term);
 
141
      m_apm_copy(sum, tmp7);
 
142
     }
 
143
 
 
144
   if ((term->m_apm_exponent < tolerance) || (term->m_apm_sign == 0))
 
145
     break;
 
146
 
 
147
   if (m1 != 1L)
 
148
     {
 
149
      local_precision = local_precision + term->m_apm_exponent - prev_exp;
 
150
 
 
151
      if (local_precision < 20)
 
152
        local_precision = 20;
 
153
     }
 
154
 
 
155
   prev_exp = term->m_apm_exponent;
 
156
 
 
157
   m1 += 2;
 
158
   flag = 1 - flag;
 
159
  }
 
160
 
 
161
m_apm_round(rr, places, sum);
 
162
M_restore_stack(5);
 
163
}
 
164
/****************************************************************************/