xref: /freebsd-src/contrib/llvm-project/compiler-rt/lib/builtins/powidf2.c (revision e25152834cdf3b353892835a4f3b157e066a8ed4)
10b57cec5SDimitry Andric //===-- powidf2.cpp - Implement __powidf2 ---------------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file implements __powidf2 for the compiler_rt library.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric #include "int_lib.h"
140b57cec5SDimitry Andric 
150b57cec5SDimitry Andric // Returns: a ^ b
160b57cec5SDimitry Andric 
__powidf2(double a,int b)17*5ffd83dbSDimitry Andric COMPILER_RT_ABI double __powidf2(double a, int b) {
180b57cec5SDimitry Andric   const int recip = b < 0;
190b57cec5SDimitry Andric   double r = 1;
200b57cec5SDimitry Andric   while (1) {
210b57cec5SDimitry Andric     if (b & 1)
220b57cec5SDimitry Andric       r *= a;
230b57cec5SDimitry Andric     b /= 2;
240b57cec5SDimitry Andric     if (b == 0)
250b57cec5SDimitry Andric       break;
260b57cec5SDimitry Andric     a *= a;
270b57cec5SDimitry Andric   }
280b57cec5SDimitry Andric   return recip ? 1 / r : r;
290b57cec5SDimitry Andric }
30