5
* Copyright (C) 1999 - 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 Integer Power function.
27
#include "pgscript/utilities/mapm-lib/m_apm_lc.h"
29
/****************************************************************************/
30
void m_apm_integer_pow(M_APM rr, int places, M_APM aa, int mexp)
32
M_APM tmp0, tmpy, tmpz;
33
int nexp, ii, signflag, local_precision;
37
m_apm_copy(rr, MM_One);
54
if (aa->m_apm_sign == 0)
60
tmp0 = M_get_stack_var();
61
tmpy = M_get_stack_var();
62
tmpz = M_get_stack_var();
64
local_precision = places + 8;
66
m_apm_copy(tmpy, MM_One);
74
if (ii != 0) /* exponent -was- odd */
76
m_apm_multiply(tmp0, tmpy, tmpz);
77
m_apm_round(tmpy, local_precision, tmp0);
83
m_apm_multiply(tmp0, tmpz, tmpz);
84
m_apm_round(tmpz, local_precision, tmp0);
89
m_apm_reciprocal(rr, places, tmpy);
93
m_apm_round(rr, places, tmpy);
98
/****************************************************************************/