s_ccosf.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* $OpenBSD: s_ccosf.c,v 1.2 2010/07/18 18:42:26 guenther Exp $ */
  2. /*
  3. * Copyright (c) 2008 Stephen L. Moshier <[email protected]>
  4. *
  5. * Permission to use, copy, modify, and distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. /* ccosf()
  18. *
  19. * Complex circular cosine
  20. *
  21. *
  22. *
  23. * SYNOPSIS:
  24. *
  25. * void ccosf();
  26. * cmplxf z, w;
  27. *
  28. * ccosf( &z, &w );
  29. *
  30. *
  31. *
  32. * DESCRIPTION:
  33. *
  34. * If
  35. * z = x + iy,
  36. *
  37. * then
  38. *
  39. * w = cos x cosh y - i sin x sinh y.
  40. *
  41. *
  42. *
  43. * ACCURACY:
  44. *
  45. * Relative error:
  46. * arithmetic domain # trials peak rms
  47. * IEEE -10,+10 30000 1.8e-7 5.5e-8
  48. */
  49. #include <openlibm_complex.h>
  50. #include <openlibm_math.h>
  51. /* calculate cosh and sinh */
  52. static void
  53. _cchshf(float xx, float *c, float *s)
  54. {
  55. float x, e, ei;
  56. x = xx;
  57. if(fabsf(x) <= 0.5f) {
  58. *c = coshf(x);
  59. *s = sinhf(x);
  60. }
  61. else {
  62. e = expf(x);
  63. ei = 0.5f/e;
  64. e = 0.5f * e;
  65. *s = e - ei;
  66. *c = e + ei;
  67. }
  68. }
  69. float complex
  70. ccosf(float complex z)
  71. {
  72. float complex w;
  73. float ch, sh;
  74. _cchshf( cimagf(z), &ch, &sh );
  75. w = cosf( crealf(z) ) * ch + ( -sinf( crealf(z) ) * sh) * I;
  76. return (w);
  77. }