2009-08-07 20:30:09 +00:00
|
|
|
/*===-- powisf2.cpp - Implement __powisf2 ---------------------------------===
|
|
|
|
*
|
|
|
|
* The LLVM Compiler Infrastructure
|
|
|
|
*
|
2010-11-16 22:13:33 +00:00
|
|
|
* This file is dual licensed under the MIT and the University of Illinois Open
|
|
|
|
* Source Licenses. See LICENSE.TXT for details.
|
2009-08-07 20:30:09 +00:00
|
|
|
*
|
|
|
|
* ===----------------------------------------------------------------------===
|
|
|
|
*
|
|
|
|
* This file implements __powisf2 for the compiler_rt library.
|
|
|
|
*
|
|
|
|
* ===----------------------------------------------------------------------===
|
|
|
|
*/
|
2009-06-26 16:47:03 +00:00
|
|
|
|
|
|
|
#include "int_lib.h"
|
|
|
|
|
2009-08-07 20:30:09 +00:00
|
|
|
/* Returns: a ^ b */
|
2009-06-26 16:47:03 +00:00
|
|
|
|
2011-04-19 17:52:09 +00:00
|
|
|
COMPILER_RT_ABI float
|
2009-06-26 16:47:03 +00:00
|
|
|
__powisf2(float a, si_int b)
|
|
|
|
{
|
|
|
|
const int recip = b < 0;
|
|
|
|
float r = 1;
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
if (b & 1)
|
|
|
|
r *= a;
|
|
|
|
b /= 2;
|
|
|
|
if (b == 0)
|
|
|
|
break;
|
|
|
|
a *= a;
|
|
|
|
}
|
|
|
|
return recip ? 1/r : r;
|
|
|
|
}
|