 /*
  * Khoros: $Id: dpow.c,v 1.2 1992/03/20 23:42:30 dkhoros Exp $
  */

#if !defined(lint) && !defined(SABER)
static char rcsid[] = "Khoros: $Id: dpow.c,v 1.2 1992/03/20 23:42:30 dkhoros Exp $";
#endif

 /*
  * $Log: dpow.c,v $
 * Revision 1.2  1992/03/20  23:42:30  dkhoros
 * VirtualPatch5
 *
  */ 

/*
 *----------------------------------------------------------------------
 *
 * Copyright 1990, University of New Mexico.  All rights reserved.
 * 
 * Permission to copy and modify this software and its documen-
 * tation only for internal use in your organization is hereby
 * granted, provided that this notice is retained thereon and
 * on all copies.  UNM makes no representations as too the sui-
 * tability and operability of this software for any purpose.
 * It is provided "as is" without express or implied warranty.
 * 
 * UNM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
 * NESS.  IN NO EVENT SHALL UNM BE LIABLE FOR ANY SPECIAL,
 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY OTHER DAMAGES WHAT-
 * SOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PER-
 * FORMANCE OF THIS SOFTWARE.
 * 
 * No other rights, including for example, the right to redis-
 * tribute this software and its documentation or the right to
 * prepare derivative works, are granted unless specifically
 * provided in a separate license agreement.
 *----------------------------------------------------------------------
 */

#include "unmcopyright.h"	 /* Copyright 1990 by UNM */
#include "vinclude.h"

/***********************************************************************
*
*  Routine Name: powtwo()
*
*          Date:
*        
*       Purpose: check if sequence length is a power of two (2) 
*
*         Input: 
*
*        Output: 
*
*    Written By:  
*
* Modifications:
*
***********************************************************************/

int
powtwo( length )

int length;

{
	float size;

	size = (float) length;
	
	while ( size > 1.0 )
	{
	      size /= 2.0;
	      if ( size == 1.0 )
	      {
		 return(1);
	      } 
	      else if ( size < 1.0 )
	      { 
                 return(0);
	      }
	}
	return(0);

} /* end of powtwo */


/***********************************************************************
*
*  Routine Name: dpower()
*
*          Date:
*        
*       Purpose: power of a number 
*
*         Input: 
*
*        Output: 
*
*    Written By:  
*
* Modifications:
*
***********************************************************************/

double dpower (base, exp)
int exp;
double base;
{
        double answer;

        if ( exp > 0)
        {
           for (answer = 1.0; exp > 0; exp--) 
           {
                answer *= base;
           }
           return (answer);
        }
        else if (base != 0)
        {
           for (answer = 1.0; exp < 0; exp++)
           {
                answer /= base;
           }
           return (answer);
        }
        else
        {
           (void)fprintf(stderr,"0 to the %d power is not allowed!!!\n\n",exp);
           return (0);
        }

} /* end of dpower */

