powidf2.c revision 355940
1132718Skan//===-- powidf2.cpp - Implement __powidf2 ---------------------------------===//
290075Sobrien//
3169689Skan// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
490075Sobrien// See https://llvm.org/LICENSE.txt for license information.
590075Sobrien// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6132718Skan//
790075Sobrien//===----------------------------------------------------------------------===//
8132718Skan//
990075Sobrien// This file implements __powidf2 for the compiler_rt library.
1090075Sobrien//
1190075Sobrien//===----------------------------------------------------------------------===//
1290075Sobrien
13132718Skan#include "int_lib.h"
1490075Sobrien
1590075Sobrien// Returns: a ^ b
1690075Sobrien
1790075SobrienCOMPILER_RT_ABI double __powidf2(double a, si_int b) {
1890075Sobrien  const int recip = b < 0;
19132718Skan  double r = 1;
20169689Skan  while (1) {
21169689Skan    if (b & 1)
2290075Sobrien      r *= a;
23117395Skan    b /= 2;
24117395Skan    if (b == 0)
25117395Skan      break;
26117395Skan    a *= a;
27117395Skan  }
28117395Skan  return recip ? 1 / r : r;
2990075Sobrien}
30117395Skan