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

« back to all changes in this revision

Viewing changes to pgadmin/pgscript/utilities/m_apm/mapmipwr.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  -  mapmipwr.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 Integer Power function.
 
24
 */
 
25
 
 
26
#include "pgAdmin3.h"
 
27
#include "pgscript/utilities/mapm-lib/m_apm_lc.h"
 
28
 
 
29
/****************************************************************************/
 
30
void    m_apm_integer_pow(M_APM rr, int places, M_APM aa, int mexp)
 
31
{
 
32
M_APM   tmp0, tmpy, tmpz;
 
33
int     nexp, ii, signflag, local_precision;
 
34
 
 
35
if (mexp == 0)
 
36
  {
 
37
   m_apm_copy(rr, MM_One);
 
38
   return;
 
39
  }
 
40
else
 
41
  {
 
42
   if (mexp > 0)
 
43
     {
 
44
      signflag = 0;
 
45
      nexp     = mexp;
 
46
     }
 
47
   else
 
48
     {
 
49
      signflag = 1;
 
50
      nexp     = -mexp;
 
51
     }
 
52
  }
 
53
 
 
54
if (aa->m_apm_sign == 0)
 
55
  {
 
56
   M_set_to_zero(rr);
 
57
   return;
 
58
  }
 
59
 
 
60
tmp0 = M_get_stack_var();
 
61
tmpy = M_get_stack_var();
 
62
tmpz = M_get_stack_var();
 
63
 
 
64
local_precision = places + 8;
 
65
 
 
66
m_apm_copy(tmpy, MM_One);
 
67
m_apm_copy(tmpz, aa);
 
68
 
 
69
while (TRUE)
 
70
  {
 
71
   ii   = nexp & 1;
 
72
   nexp = nexp >> 1;
 
73
 
 
74
   if (ii != 0)                       /* exponent -was- odd */
 
75
     {
 
76
      m_apm_multiply(tmp0, tmpy, tmpz);
 
77
      m_apm_round(tmpy, local_precision, tmp0);
 
78
 
 
79
      if (nexp == 0)
 
80
        break;
 
81
     }
 
82
 
 
83
   m_apm_multiply(tmp0, tmpz, tmpz);
 
84
   m_apm_round(tmpz, local_precision, tmp0);
 
85
  }
 
86
 
 
87
if (signflag)
 
88
  {
 
89
   m_apm_reciprocal(rr, places, tmpy);
 
90
  }
 
91
else
 
92
  {
 
93
   m_apm_round(rr, places, tmpy);
 
94
  }
 
95
 
 
96
M_restore_stack(3);
 
97
}
 
98
/****************************************************************************/