blob: 172f29f58f2572b87a7d2bd4895e80e50cd42600 [file] [log] [blame]
Edward O'Callaghandabf71f2009-08-05 19:06:50 +00001/* ===-- powitf2.cpp - Implement __powitf2 ---------------------------------===
2 *
3 * The LLVM Compiler Infrastructure
4 *
Howard Hinnant5b791f62010-11-16 22:13:33 +00005 * This file is dual licensed under the MIT and the University of Illinois Open
6 * Source Licenses. See LICENSE.TXT for details.
Edward O'Callaghandabf71f2009-08-05 19:06:50 +00007 *
8 * ===----------------------------------------------------------------------===
9 *
10 * This file implements __powitf2 for the compiler_rt library.
11 *
12 * ===----------------------------------------------------------------------===
13 */
Daniel Dunbarfd089992009-06-26 16:47:03 +000014
Daniel Dunbarfd089992009-06-26 16:47:03 +000015#include "int_lib.h"
16
Chandler Carruth6e2bf8f2012-06-22 21:09:22 +000017#if _ARCH_PPC
18
Edward O'Callaghandabf71f2009-08-05 19:06:50 +000019/* Returns: a ^ b */
Daniel Dunbarfd089992009-06-26 16:47:03 +000020
Joerg Sonnenberger6e99daa2014-03-01 15:30:50 +000021COMPILER_RT_ABI long double
Daniel Dunbarfd089992009-06-26 16:47:03 +000022__powitf2(long double a, si_int b)
23{
24 const int recip = b < 0;
25 long double r = 1;
26 while (1)
27 {
28 if (b & 1)
29 r *= a;
30 b /= 2;
31 if (b == 0)
32 break;
33 a *= a;
34 }
35 return recip ? 1/r : r;
36}
37
38#endif