ba237a9d91
Files correlati : Ricompilazione Demo : [ ] Commento : Aggiunti i sorgenti per Greenleaf Math Library (gfm.dll) git-svn-id: svn://10.65.10.50/trunk@10079 c028cbd2-c16b-5b4b-a496-9718f37d4682
83 lines
1.7 KiB
C
Executable File
83 lines
1.7 KiB
C
Executable File
/* DEC *PowerInteger(pDst,pSrc,i)
|
|
*
|
|
* ARGUMENT
|
|
* DEC *pDst,*pSrc;
|
|
* int i;
|
|
*
|
|
* DESCRIPTION
|
|
* Raises pSrc to the power 'i'. If i<0, raises pSrc to the |i|, then
|
|
* takes the reciprocal(ie, if i<0, then x**i = 1/x**|i|). If x=0, then
|
|
* if i=<0, then error (GM_NAN), else pDst is set to 1. If x<0, then if the
|
|
* power is odd, the result will be negative, otherwise positive. The
|
|
* absolute value cannot exceed 2**63 -1. Note we call dpoxi() because
|
|
* other high-level functions need returns of 2**79 -1, which is what
|
|
* this routine gets back and then sqeezes it back to 64-bits.
|
|
*
|
|
* SIDE EFFECTS
|
|
* *pDst is indeterminate on overflow, underflow. It is undisturbed
|
|
* on GM_NULLPOINTER.
|
|
*
|
|
* RETURNS
|
|
* Ptr to pDst if no errors, otherwise GM_NULL.
|
|
*
|
|
* POSSIBLE ERROR CODES
|
|
*
|
|
* GM_NULLPOINTER
|
|
* GM_OVERFLOW
|
|
* GM_UNDERFLOW
|
|
*
|
|
* AUTHOR
|
|
* Andy Anderson 08-05-87 1130
|
|
* Copyright (C) 1987-1990 Greenleaf Software Inc. All rights reserved.
|
|
*
|
|
* MODIFICATIONS
|
|
*
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include "gm.h"
|
|
#include "gmsystem.h"
|
|
|
|
DEC *PowerInteger(pDst,pSrc,i)
|
|
DEC *pDst,*pSrc;
|
|
int i;
|
|
{
|
|
int wRetVal;
|
|
|
|
_MacStart(GM_DPOWI);
|
|
_MacInVarD(pSrc);
|
|
_MacOutVarD(pDst);
|
|
|
|
if (_MacIsDecZ(pSrc) && (i<=0)) {
|
|
_MacErr(GM_PWR0);
|
|
_MacRet(GM_NULL);
|
|
}
|
|
|
|
if (_MacIsDecZ(pSrc)) {
|
|
_MacDZero(pDst);
|
|
_MacRet(pDst);
|
|
}
|
|
|
|
wRetVal=_IntPwrDec80Bit(pDst,pSrc,i);
|
|
|
|
/* then see if success */
|
|
if(wRetVal == GM_OVERFLOW) {
|
|
_MacErr(wRetVal);
|
|
_MacRet(GM_NULL);
|
|
}
|
|
|
|
/* then try to reduce to 64-bit */
|
|
wRetVal = _Sq5UnsTo4Uns(pDst); /* places or it's an error */
|
|
|
|
if(wRetVal != GM_SUCCESS) {
|
|
_MacErr(GM_OVERFLOW);
|
|
_MacRet(GM_NULL);
|
|
}
|
|
|
|
if (_MacIsDecZ(pDst)) {
|
|
_MacErr(GM_UNDERFLOW);
|
|
}
|
|
|
|
_MacRet(pDst);
|
|
}
|