/math/s_cexpf.c

https://github.com/nitinkamble/x32-glibc · C · 125 lines · 84 code · 14 blank · 27 comment · 18 complexity · 1d1395d25abd1c280ba7c672981b0b78 MD5 · raw file

  1. /* Return value of complex exponential function for float complex value.
  2. Copyright (C) 1997 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, write to the Free
  15. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  16. 02111-1307 USA. */
  17. #include <complex.h>
  18. #include <fenv.h>
  19. #include <math.h>
  20. #include "math_private.h"
  21. __complex__ float
  22. __cexpf (__complex__ float x)
  23. {
  24. __complex__ float retval;
  25. int rcls = fpclassify (__real__ x);
  26. int icls = fpclassify (__imag__ x);
  27. if (rcls >= FP_ZERO)
  28. {
  29. /* Real part is finite. */
  30. if (icls >= FP_ZERO)
  31. {
  32. /* Imaginary part is finite. */
  33. float exp_val = __ieee754_expf (__real__ x);
  34. float sinix, cosix;
  35. __sincosf (__imag__ x, &sinix, &cosix);
  36. if (isfinite (exp_val))
  37. {
  38. __real__ retval = exp_val * cosix;
  39. __imag__ retval = exp_val * sinix;
  40. }
  41. else
  42. {
  43. __real__ retval = __copysignf (exp_val, cosix);
  44. __imag__ retval = __copysignf (exp_val, sinix);
  45. }
  46. }
  47. else
  48. {
  49. /* If the imaginary part is +-inf or NaN and the real part
  50. is not +-inf the result is NaN + iNaN. */
  51. __real__ retval = __nanf ("");
  52. __imag__ retval = __nanf ("");
  53. #ifdef FE_INVALID
  54. feraiseexcept (FE_INVALID);
  55. #endif
  56. }
  57. }
  58. else if (rcls == FP_INFINITE)
  59. {
  60. /* Real part is infinite. */
  61. if (icls >= FP_ZERO)
  62. {
  63. /* Imaginary part is finite. */
  64. float value = signbit (__real__ x) ? 0.0 : HUGE_VALF;
  65. if (icls == FP_ZERO)
  66. {
  67. /* Imaginary part is 0.0. */
  68. __real__ retval = value;
  69. __imag__ retval = __imag__ x;
  70. }
  71. else
  72. {
  73. float sinix, cosix;
  74. __sincosf (__imag__ x, &sinix, &cosix);
  75. __real__ retval = __copysignf (value, cosix);
  76. __imag__ retval = __copysignf (value, sinix);
  77. }
  78. }
  79. else if (signbit (__real__ x) == 0)
  80. {
  81. __real__ retval = HUGE_VALF;
  82. __imag__ retval = __nanf ("");
  83. #ifdef FE_INVALID
  84. if (icls == FP_INFINITE)
  85. feraiseexcept (FE_INVALID);
  86. #endif
  87. }
  88. else
  89. {
  90. __real__ retval = 0.0;
  91. __imag__ retval = __copysignf (0.0, __imag__ x);
  92. }
  93. }
  94. else
  95. {
  96. /* If the real part is NaN the result is NaN + iNaN. */
  97. __real__ retval = __nanf ("");
  98. __imag__ retval = __nanf ("");
  99. #ifdef FE_INVALID
  100. if (rcls != FP_NAN || icls != FP_NAN)
  101. feraiseexcept (FE_INVALID);
  102. #endif
  103. }
  104. return retval;
  105. }
  106. #ifndef __cexpf
  107. weak_alias (__cexpf, cexpf)
  108. #endif