/*
 *  powf.c
 *
 *  AMENDMENT HISTORY
 *  ~~~~~~~~~~~~~~~~~
 *  30 Dec 93   DJW   - No logic change - but now uses 'float' type variables
 *                      and functions wherever possible for extra speed.
 */

#define __LIBRARY__

#include <math.h>
#include <limits.h>
#include <errno.h>

float  powf _LIB_F2_(float,  x, \
                      float,  y)
{
    int sign = 0;
    float power, result;

    if(x == 0)
    {
        if(y <= 0)
        {
            errno = EDOM;
            return HUGE_VAL;
        }
        else
            return 0;
    }
    else if(x < 0)
    {
        if(floorf(y) != y || y < (float) INT_MIN || y > (float) INT_MAX)
        {
            errno = EDOM;
            return HUGE_VAL;
        }
        if(((int) y) & 1)			/* odd power */
            sign = 1;
        x = -x;
    }

    /* we could save two multiplications (or so) by 'inlining' the code for
     * exp() and log() at this point. It's not worth it. */

    if((power = _mult(y, log(x))) == HUGE_VAL)
    {
        return HUGE_VAL;			/* with errno = ERANGE */
    }

    result = expf(power);

    return sign ? -result : result;
}

