1353358Sdim//===-- powidf2.cpp - Implement __powidf2 ---------------------------------===// 2353358Sdim// 3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4353358Sdim// See https://llvm.org/LICENSE.txt for license information. 5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6353358Sdim// 7353358Sdim//===----------------------------------------------------------------------===// 8353358Sdim// 9353358Sdim// This file implements __powidf2 for the compiler_rt library. 10353358Sdim// 11353358Sdim//===----------------------------------------------------------------------===// 12276789Sdim 13276789Sdim#include "int_lib.h" 14276789Sdim 15353358Sdim// Returns: a ^ b 16276789Sdim 17353358SdimCOMPILER_RT_ABI double __powidf2(double a, si_int b) { 18353358Sdim const int recip = b < 0; 19353358Sdim double r = 1; 20353358Sdim while (1) { 21353358Sdim if (b & 1) 22353358Sdim r *= a; 23353358Sdim b /= 2; 24353358Sdim if (b == 0) 25353358Sdim break; 26353358Sdim a *= a; 27353358Sdim } 28353358Sdim return recip ? 1 / r : r; 29276789Sdim} 30