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

« back to all changes in this revision

Viewing changes to pgadmin/pgscript/utilities/m_apm/mapmasn0.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  -  mapmasn0.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
 *
 
23
 *      This file contains the 'ARC' family of functions; ARC-SIN, 
 
24
 *      ARC-COS, ARC-TAN when the input arg is very close to 0 (zero).
 
25
 *
 
26
 */
 
27
 
 
28
#include "pgAdmin3.h"
 
29
#include "pgscript/utilities/mapm-lib/m_apm_lc.h"
 
30
 
 
31
/****************************************************************************/
 
32
/*
 
33
        Calculate arcsin using the identity :
 
34
 
 
35
                                      x
 
36
        arcsin (x) == arctan [ --------------- ]
 
37
                                sqrt(1 - x^2)
 
38
 
 
39
*/
 
40
void    M_arcsin_near_0(M_APM rr, int places, M_APM aa)
 
41
{
 
42
M_APM   tmp5, tmp6;
 
43
 
 
44
tmp5 = M_get_stack_var();
 
45
tmp6 = M_get_stack_var();
 
46
 
 
47
M_cos_to_sin(tmp5, (places + 8), aa);
 
48
m_apm_divide(tmp6, (places + 8), aa, tmp5);
 
49
M_arctan_near_0(rr, places, tmp6);
 
50
 
 
51
M_restore_stack(2);
 
52
}
 
53
/****************************************************************************/
 
54
/*
 
55
        Calculate arccos using the identity :
 
56
 
 
57
        arccos (x) == PI / 2 - arcsin (x)
 
58
 
 
59
*/
 
60
void    M_arccos_near_0(M_APM rr, int places, M_APM aa)
 
61
{
 
62
M_APM   tmp1, tmp2;
 
63
 
 
64
tmp1 = M_get_stack_var();
 
65
tmp2 = M_get_stack_var();
 
66
 
 
67
M_check_PI_places(places);
 
68
M_arcsin_near_0(tmp1, (places + 4), aa);
 
69
m_apm_subtract(tmp2, MM_lc_HALF_PI, tmp1);
 
70
m_apm_round(rr, places, tmp2);
 
71
 
 
72
M_restore_stack(2);
 
73
}
 
74
/****************************************************************************/
 
75
/*
 
76
        calculate arctan (x) with the following series:
 
77
 
 
78
                              x^3     x^5     x^7     x^9
 
79
        arctan (x)  =   x  -  ---  +  ---  -  ---  +  ---  ...
 
80
                               3       5       7       9
 
81
 
 
82
*/
 
83
void    M_arctan_near_0(M_APM rr, int places, M_APM aa)
 
84
{
 
85
M_APM   tmp0, tmp2, tmpR, tmpS, digit, term;
 
86
int     tolerance, dplaces, local_precision;
 
87
long    m1;
 
88
 
 
89
tmp0  = M_get_stack_var();
 
90
tmp2  = M_get_stack_var();
 
91
tmpR  = M_get_stack_var();
 
92
tmpS  = M_get_stack_var();
 
93
term  = M_get_stack_var();
 
94
digit = M_get_stack_var();
 
95
 
 
96
tolerance = aa->m_apm_exponent - (places + 4);
 
97
dplaces   = (places + 8) - aa->m_apm_exponent;
 
98
 
 
99
m_apm_copy(term, aa);
 
100
m_apm_copy(tmpS, aa);
 
101
m_apm_multiply(tmp0, aa, aa);
 
102
m_apm_round(tmp2, (dplaces + 8), tmp0);
 
103
 
 
104
m1 = 1L;
 
105
 
 
106
while (TRUE)
 
107
  {
 
108
   /*
 
109
    *   do the subtraction term
 
110
    */
 
111
 
 
112
   m_apm_multiply(tmp0, term, tmp2);
 
113
 
 
114
   if ((tmp0->m_apm_exponent < tolerance) || (tmp0->m_apm_sign == 0))
 
115
     {
 
116
      m_apm_round(rr, places, tmpS);
 
117
      break;
 
118
     }
 
119
 
 
120
   local_precision = dplaces + tmp0->m_apm_exponent;
 
121
 
 
122
   if (local_precision < 20)
 
123
     local_precision = 20;
 
124
 
 
125
   m1 += 2;
 
126
   m_apm_set_long(digit, m1);
 
127
   m_apm_round(term, local_precision, tmp0);
 
128
   m_apm_divide(tmp0, local_precision, term, digit);
 
129
   m_apm_subtract(tmpR, tmpS, tmp0);
 
130
 
 
131
   /*
 
132
    *   do the addition term
 
133
    */
 
134
 
 
135
   m_apm_multiply(tmp0, term, tmp2);
 
136
 
 
137
   if ((tmp0->m_apm_exponent < tolerance) || (tmp0->m_apm_sign == 0))
 
138
     {
 
139
      m_apm_round(rr, places, tmpR);
 
140
      break;
 
141
     }
 
142
 
 
143
   local_precision = dplaces + tmp0->m_apm_exponent;
 
144
 
 
145
   if (local_precision < 20)
 
146
     local_precision = 20;
 
147
 
 
148
   m1 += 2;
 
149
   m_apm_set_long(digit, m1);
 
150
   m_apm_round(term, local_precision, tmp0);
 
151
   m_apm_divide(tmp0, local_precision, term, digit);
 
152
   m_apm_add(tmpS, tmpR, tmp0);
 
153
  }
 
154
 
 
155
M_restore_stack(6);                    /* restore the 6 locals we used here */
 
156
}
 
157
/****************************************************************************/