xref: /freebsd/contrib/llvm-project/compiler-rt/lib/builtins/powitf2.c (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
1 //===-- powitf2.cpp - Implement __powitf2 ---------------------------------===//
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 __powitf2 for the compiler_rt library.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #define QUAD_PRECISION
14 #include "fp_lib.h"
15 
16 #if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
17 
18 // Returns: a ^ b
19 
20 COMPILER_RT_ABI long double __powitf2(long double a, int b) {
21   const int recip = b < 0;
22   long double r = 1;
23   while (1) {
24     if (b & 1)
25       r *= a;
26     b /= 2;
27     if (b == 0)
28       break;
29     a *= a;
30   }
31   return recip ? 1 / r : r;
32 }
33 
34 #endif
35