30 lines · c
1//===-- powidf2.cpp - Implement __powidf2 ---------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8//9// This file implements __powidf2 for the compiler_rt library.10//11//===----------------------------------------------------------------------===//12 13#include "int_lib.h"14 15// Returns: a ^ b16 17COMPILER_RT_ABI double __powidf2(double a, int b) {18 const int recip = b < 0;19 double r = 1;20 while (1) {21 if (b & 1)22 r *= a;23 b /= 2;24 if (b == 0)25 break;26 a *= a;27 }28 return recip ? 1 / r : r;29}30