/lib/msun/src/s_ccoshf.c

https://bitbucket.org/iorivur/freebsd-bhyve-with-suspend-resume · C · 104 lines · 54 code · 18 blank · 32 comment · 23 complexity · b1960359dd6c4c4d6ee9f1fdaf2318d8 MD5 · raw file

  1. /*-
  2. * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice unmodified, this list of conditions, and the following
  10. * disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  16. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  17. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  18. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  19. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  20. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  21. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  22. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  24. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. /*
  27. * Hyperbolic cosine of a complex argument. See s_ccosh.c for details.
  28. */
  29. #include <sys/cdefs.h>
  30. __FBSDID("$FreeBSD: head/lib/msun/src/s_ccoshf.c 226599 2011-10-21 06:29:32Z das $");
  31. #include <complex.h>
  32. #include <math.h>
  33. #include "math_private.h"
  34. static const float huge = 0x1p127;
  35. float complex
  36. ccoshf(float complex z)
  37. {
  38. float x, y, h;
  39. int32_t hx, hy, ix, iy;
  40. x = crealf(z);
  41. y = cimagf(z);
  42. GET_FLOAT_WORD(hx, x);
  43. GET_FLOAT_WORD(hy, y);
  44. ix = 0x7fffffff & hx;
  45. iy = 0x7fffffff & hy;
  46. if (ix < 0x7f800000 && iy < 0x7f800000) {
  47. if (iy == 0)
  48. return (cpackf(coshf(x), x * y));
  49. if (ix < 0x41100000) /* small x: normal case */
  50. return (cpackf(coshf(x) * cosf(y), sinhf(x) * sinf(y)));
  51. /* |x| >= 9, so cosh(x) ~= exp(|x|) */
  52. if (ix < 0x42b17218) {
  53. /* x < 88.7: expf(|x|) won't overflow */
  54. h = expf(fabsf(x)) * 0.5f;
  55. return (cpackf(h * cosf(y), copysignf(h, x) * sinf(y)));
  56. } else if (ix < 0x4340b1e7) {
  57. /* x < 192.7: scale to avoid overflow */
  58. z = __ldexp_cexpf(cpackf(fabsf(x), y), -1);
  59. return (cpackf(crealf(z), cimagf(z) * copysignf(1, x)));
  60. } else {
  61. /* x >= 192.7: the result always overflows */
  62. h = huge * x;
  63. return (cpackf(h * h * cosf(y), h * sinf(y)));
  64. }
  65. }
  66. if (ix == 0 && iy >= 0x7f800000)
  67. return (cpackf(y - y, copysignf(0, x * (y - y))));
  68. if (iy == 0 && ix >= 0x7f800000) {
  69. if ((hx & 0x7fffff) == 0)
  70. return (cpackf(x * x, copysignf(0, x) * y));
  71. return (cpackf(x * x, copysignf(0, (x + x) * y)));
  72. }
  73. if (ix < 0x7f800000 && iy >= 0x7f800000)
  74. return (cpackf(y - y, x * (y - y)));
  75. if (ix >= 0x7f800000 && (hx & 0x7fffff) == 0) {
  76. if (iy >= 0x7f800000)
  77. return (cpackf(x * x, x * (y - y)));
  78. return (cpackf((x * x) * cosf(y), x * sinf(y)));
  79. }
  80. return (cpackf((x * x) * (y - y), (x + x) * (y - y)));
  81. }
  82. float complex
  83. ccosf(float complex z)
  84. {
  85. return (ccoshf(cpackf(-cimagf(z), crealf(z))));
  86. }