13cab2bb3Spatrick //===-- powitf2.cpp - Implement __powitf2 ---------------------------------===// 23cab2bb3Spatrick // 33cab2bb3Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 43cab2bb3Spatrick // See https://llvm.org/LICENSE.txt for license information. 53cab2bb3Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 63cab2bb3Spatrick // 73cab2bb3Spatrick //===----------------------------------------------------------------------===// 83cab2bb3Spatrick // 93cab2bb3Spatrick // This file implements __powitf2 for the compiler_rt library. 103cab2bb3Spatrick // 113cab2bb3Spatrick //===----------------------------------------------------------------------===// 123cab2bb3Spatrick 13*1f9cb04fSpatrick #define QUAD_PRECISION 14*1f9cb04fSpatrick #include "fp_lib.h" 153cab2bb3Spatrick 16*1f9cb04fSpatrick #if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) 173cab2bb3Spatrick 183cab2bb3Spatrick // Returns: a ^ b 193cab2bb3Spatrick __powitf2(long double a,int b)20*1f9cb04fSpatrickCOMPILER_RT_ABI long double __powitf2(long double a, int b) { 213cab2bb3Spatrick const int recip = b < 0; 223cab2bb3Spatrick long double r = 1; 233cab2bb3Spatrick while (1) { 243cab2bb3Spatrick if (b & 1) 253cab2bb3Spatrick r *= a; 263cab2bb3Spatrick b /= 2; 273cab2bb3Spatrick if (b == 0) 283cab2bb3Spatrick break; 293cab2bb3Spatrick a *= a; 303cab2bb3Spatrick } 313cab2bb3Spatrick return recip ? 1 / r : r; 323cab2bb3Spatrick } 333cab2bb3Spatrick 343cab2bb3Spatrick #endif 35