powixf2.c revision 222656
167754Smsmith/* ===-- powixf2.cpp - Implement __powixf2 ---------------------------------=== 267754Smsmith * 367754Smsmith * The LLVM Compiler Infrastructure 467754Smsmith * 567754Smsmith * This file is dual licensed under the MIT and the University of Illinois Open 667754Smsmith * Source Licenses. See LICENSE.TXT for details. 7217365Sjkim * 8281075Sdim * ===----------------------------------------------------------------------=== 970243Smsmith * 1067754Smsmith * This file implements __powixf2 for the compiler_rt library. 11217365Sjkim * 12217365Sjkim * ===----------------------------------------------------------------------=== 13217365Sjkim */ 14217365Sjkim 15217365Sjkim#if !_ARCH_PPC 16217365Sjkim 17217365Sjkim#include "int_lib.h" 18217365Sjkim 19217365Sjkim/* Returns: a ^ b */ 20217365Sjkim 21217365Sjkimlong double 22217365Sjkim__powixf2(long double a, si_int b) 23217365Sjkim{ 24217365Sjkim const int recip = b < 0; 2567754Smsmith long double r = 1; 26217365Sjkim while (1) 27217365Sjkim { 28217365Sjkim if (b & 1) 2967754Smsmith r *= a; 30217365Sjkim b /= 2; 31217365Sjkim if (b == 0) 32217365Sjkim break; 33217365Sjkim a *= a; 34217365Sjkim } 35217365Sjkim return recip ? 1/r : r; 36217365Sjkim} 37217365Sjkim 38217365Sjkim#endif 39217365Sjkim