/*-
 * Function: powdi
 * Abstract:
 *
 *    Optimized version of pow when exponent is an integer number.
 *
 * Initial coding by A S Bozin
 * Copyright (c) 1997-2000 The MathWorks, Inc. All Rights Reserved.
 * $Revision: 1.1 $ $Date: 2000/06/14 16:07:36 $
 */
#include "tmwtypes.h"
#include <math.h>

real_T
powdi(real_T x, int_T n)
{
    real_T          pow;
    uint_T          u;

    /*
     * First executable statement
     */
    pow = 1;
    if (n != 0) {
	if (n < 0) {
	    n = -n;
	    x = 1 / x;
	}
	for (u = n;;) {
	    if (u & 01)
		pow *= x;
	    if (u >>= 1)
		x *= x;
	    else
		break;
	}
    }
    return (pow);					   /* Last card of powdi */
}
