muldc3.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* ===-- muldc3.c - Implement __muldc3 -------------------------------------===
  2. *
  3. * The LLVM Compiler Infrastructure
  4. *
  5. * This file is dual licensed under the MIT and the University of Illinois Open
  6. * Source Licenses. See LICENSE.TXT for details.
  7. *
  8. * ===----------------------------------------------------------------------===
  9. *
  10. * This file implements __muldc3 for the compiler_rt library.
  11. *
  12. * ===----------------------------------------------------------------------===
  13. */
  14. #include "int_lib.h"
  15. #include "int_math.h"
  16. /* Returns: the product of a + ib and c + id */
  17. COMPILER_RT_ABI Dcomplex
  18. __muldc3(double __a, double __b, double __c, double __d)
  19. {
  20. double __ac = __a * __c;
  21. double __bd = __b * __d;
  22. double __ad = __a * __d;
  23. double __bc = __b * __c;
  24. Dcomplex z;
  25. COMPLEX_REAL(z) = __ac - __bd;
  26. COMPLEX_IMAGINARY(z) = __ad + __bc;
  27. if (crt_isnan(COMPLEX_REAL(z)) && crt_isnan(COMPLEX_IMAGINARY(z)))
  28. {
  29. int __recalc = 0;
  30. if (crt_isinf(__a) || crt_isinf(__b))
  31. {
  32. __a = crt_copysign(crt_isinf(__a) ? 1 : 0, __a);
  33. __b = crt_copysign(crt_isinf(__b) ? 1 : 0, __b);
  34. if (crt_isnan(__c))
  35. __c = crt_copysign(0, __c);
  36. if (crt_isnan(__d))
  37. __d = crt_copysign(0, __d);
  38. __recalc = 1;
  39. }
  40. if (crt_isinf(__c) || crt_isinf(__d))
  41. {
  42. __c = crt_copysign(crt_isinf(__c) ? 1 : 0, __c);
  43. __d = crt_copysign(crt_isinf(__d) ? 1 : 0, __d);
  44. if (crt_isnan(__a))
  45. __a = crt_copysign(0, __a);
  46. if (crt_isnan(__b))
  47. __b = crt_copysign(0, __b);
  48. __recalc = 1;
  49. }
  50. if (!__recalc && (crt_isinf(__ac) || crt_isinf(__bd) ||
  51. crt_isinf(__ad) || crt_isinf(__bc)))
  52. {
  53. if (crt_isnan(__a))
  54. __a = crt_copysign(0, __a);
  55. if (crt_isnan(__b))
  56. __b = crt_copysign(0, __b);
  57. if (crt_isnan(__c))
  58. __c = crt_copysign(0, __c);
  59. if (crt_isnan(__d))
  60. __d = crt_copysign(0, __d);
  61. __recalc = 1;
  62. }
  63. if (__recalc)
  64. {
  65. COMPLEX_REAL(z) = CRT_INFINITY * (__a * __c - __b * __d);
  66. COMPLEX_IMAGINARY(z) = CRT_INFINITY * (__a * __d + __b * __c);
  67. }
  68. }
  69. return z;
  70. }