powidf2.c revision 276789
1276789Sdim/* ===-- powidf2.cpp - Implement __powidf2 ---------------------------------=== 2276789Sdim * 3276789Sdim * The LLVM Compiler Infrastructure 4276789Sdim * 5276789Sdim * This file is dual licensed under the MIT and the University of Illinois Open 6276789Sdim * Source Licenses. See LICENSE.TXT for details. 7276789Sdim * 8276789Sdim * ===----------------------------------------------------------------------=== 9276789Sdim * 10276789Sdim * This file implements __powidf2 for the compiler_rt library. 11276789Sdim * 12276789Sdim * ===----------------------------------------------------------------------=== 13276789Sdim */ 14276789Sdim 15276789Sdim#include "int_lib.h" 16276789Sdim 17276789Sdim/* Returns: a ^ b */ 18276789Sdim 19276789SdimCOMPILER_RT_ABI double 20276789Sdim__powidf2(double a, si_int b) 21276789Sdim{ 22276789Sdim const int recip = b < 0; 23276789Sdim double r = 1; 24276789Sdim while (1) 25276789Sdim { 26276789Sdim if (b & 1) 27276789Sdim r *= a; 28276789Sdim b /= 2; 29276789Sdim if (b == 0) 30276789Sdim break; 31276789Sdim a *= a; 32276789Sdim } 33276789Sdim return recip ? 1/r : r; 34276789Sdim} 35