powitf2.c 840 B

12345678910111213141516171819202122232425262728293031323334
  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. #define QUAD_PRECISION
  13. #include "fp_lib.h"
  14. #if defined(CRT_HAS_TF_MODE)
  15. // Returns: a ^ b
  16. COMPILER_RT_ABI fp_t __powitf2(fp_t a, int b) {
  17. const int recip = b < 0;
  18. fp_t r = 1;
  19. while (1) {
  20. if (b & 1)
  21. r *= a;
  22. b /= 2;
  23. if (b == 0)
  24. break;
  25. a *= a;
  26. }
  27. return recip ? 1 / r : r;
  28. }
  29. #endif