powidf2.c 786 B

1234567891011121314151617181920212223242526272829
  1. //===-- powidf2.cpp - Implement __powidf2 ---------------------------------===//
  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 __powidf2 for the compiler_rt library.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "int_lib.h"
  13. // Returns: a ^ b
  14. COMPILER_RT_ABI double __powidf2(double a, int b) {
  15. const int recip = b < 0;
  16. double r = 1;
  17. while (1) {
  18. if (b & 1)
  19. r *= a;
  20. b /= 2;
  21. if (b == 0)
  22. break;
  23. a *= a;
  24. }
  25. return recip ? 1 / r : r;
  26. }