/contrib/compiler-rt/lib/mulsc3.c

https://github.com/blacklion/GEOM-Events · C · 74 lines · 57 code · 3 blank · 14 comment · 19 complexity · c9a2e03445623799265e44ebcbcc06f8 MD5 · raw file

  1. /* ===-- mulsc3.c - Implement __mulsc3 -------------------------------------===
  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 __mulsc3 for the compiler_rt library.
  11. *
  12. * ===----------------------------------------------------------------------===
  13. */
  14. #include "int_lib.h"
  15. #include <math.h>
  16. #include <complex.h>
  17. /* Returns: the product of a + ib and c + id */
  18. float _Complex
  19. __mulsc3(float __a, float __b, float __c, float __d)
  20. {
  21. float __ac = __a * __c;
  22. float __bd = __b * __d;
  23. float __ad = __a * __d;
  24. float __bc = __b * __c;
  25. float _Complex z;
  26. __real__ z = __ac - __bd;
  27. __imag__ z = __ad + __bc;
  28. if (isnan(__real__ z) && isnan(__imag__ z))
  29. {
  30. int __recalc = 0;
  31. if (isinf(__a) || isinf(__b))
  32. {
  33. __a = copysignf(isinf(__a) ? 1 : 0, __a);
  34. __b = copysignf(isinf(__b) ? 1 : 0, __b);
  35. if (isnan(__c))
  36. __c = copysignf(0, __c);
  37. if (isnan(__d))
  38. __d = copysignf(0, __d);
  39. __recalc = 1;
  40. }
  41. if (isinf(__c) || isinf(__d))
  42. {
  43. __c = copysignf(isinf(__c) ? 1 : 0, __c);
  44. __d = copysignf(isinf(__d) ? 1 : 0, __d);
  45. if (isnan(__a))
  46. __a = copysignf(0, __a);
  47. if (isnan(__b))
  48. __b = copysignf(0, __b);
  49. __recalc = 1;
  50. }
  51. if (!__recalc && (isinf(__ac) || isinf(__bd) ||
  52. isinf(__ad) || isinf(__bc)))
  53. {
  54. if (isnan(__a))
  55. __a = copysignf(0, __a);
  56. if (isnan(__b))
  57. __b = copysignf(0, __b);
  58. if (isnan(__c))
  59. __c = copysignf(0, __c);
  60. if (isnan(__d))
  61. __d = copysignf(0, __d);
  62. __recalc = 1;
  63. }
  64. if (__recalc)
  65. {
  66. __real__ z = INFINITY * (__a * __c - __b * __d);
  67. __imag__ z = INFINITY * (__a * __d + __b * __c);
  68. }
  69. }
  70. return z;
  71. }