muldc3.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //===-- muldc3.c - Implement __muldc3 -------------------------------------===//
  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 __muldc3 for the compiler_rt library.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "int_lib.h"
  13. #include "int_math.h"
  14. // Returns: the product of a + ib and c + id
  15. COMPILER_RT_ABI Dcomplex __muldc3(double __a, double __b, double __c,
  16. double __d) {
  17. double __ac = __a * __c;
  18. double __bd = __b * __d;
  19. double __ad = __a * __d;
  20. double __bc = __b * __c;
  21. Dcomplex z;
  22. COMPLEX_REAL(z) = __ac - __bd;
  23. COMPLEX_IMAGINARY(z) = __ad + __bc;
  24. if (crt_isnan(COMPLEX_REAL(z)) && crt_isnan(COMPLEX_IMAGINARY(z))) {
  25. int __recalc = 0;
  26. if (crt_isinf(__a) || crt_isinf(__b)) {
  27. __a = crt_copysign(crt_isinf(__a) ? 1 : 0, __a);
  28. __b = crt_copysign(crt_isinf(__b) ? 1 : 0, __b);
  29. if (crt_isnan(__c))
  30. __c = crt_copysign(0, __c);
  31. if (crt_isnan(__d))
  32. __d = crt_copysign(0, __d);
  33. __recalc = 1;
  34. }
  35. if (crt_isinf(__c) || crt_isinf(__d)) {
  36. __c = crt_copysign(crt_isinf(__c) ? 1 : 0, __c);
  37. __d = crt_copysign(crt_isinf(__d) ? 1 : 0, __d);
  38. if (crt_isnan(__a))
  39. __a = crt_copysign(0, __a);
  40. if (crt_isnan(__b))
  41. __b = crt_copysign(0, __b);
  42. __recalc = 1;
  43. }
  44. if (!__recalc && (crt_isinf(__ac) || crt_isinf(__bd) || crt_isinf(__ad) ||
  45. crt_isinf(__bc))) {
  46. if (crt_isnan(__a))
  47. __a = crt_copysign(0, __a);
  48. if (crt_isnan(__b))
  49. __b = crt_copysign(0, __b);
  50. if (crt_isnan(__c))
  51. __c = crt_copysign(0, __c);
  52. if (crt_isnan(__d))
  53. __d = crt_copysign(0, __d);
  54. __recalc = 1;
  55. }
  56. if (__recalc) {
  57. COMPLEX_REAL(z) = CRT_INFINITY * (__a * __c - __b * __d);
  58. COMPLEX_IMAGINARY(z) = CRT_INFINITY * (__a * __d + __b * __c);
  59. }
  60. }
  61. return z;
  62. }