powixf2.c 816 B

123456789101112131415161718192021222324252627282930313233
  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. #if !_ARCH_PPC
  13. #include "int_lib.h"
  14. // Returns: a ^ b
  15. COMPILER_RT_ABI xf_float __powixf2(xf_float a, int b) {
  16. const int recip = b < 0;
  17. xf_float r = 1;
  18. while (1) {
  19. if (b & 1)
  20. r *= a;
  21. b /= 2;
  22. if (b == 0)
  23. break;
  24. a *= a;
  25. }
  26. return recip ? 1 / r : r;
  27. }
  28. #endif