xref: /freebsd/contrib/llvm-project/compiler-rt/lib/builtins/powixf2.c (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1 //===-- powixf2.cpp - Implement __powixf2 ---------------------------------===//
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-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements __powixf2 for the compiler_rt library.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #if !_ARCH_PPC
14 
15 #include "int_lib.h"
16 
17 // Returns: a ^ b
18 
19 COMPILER_RT_ABI long double __powixf2(long double a, int b) {
20   const int recip = b < 0;
21   long double r = 1;
22   while (1) {
23     if (b & 1)
24       r *= a;
25     b /= 2;
26     if (b == 0)
27       break;
28     a *= a;
29   }
30   return recip ? 1 / r : r;
31 }
32 
33 #endif
34