/lib/libm/noieee_src/n_csin.c

https://bitbucket.org/kmv/aeriebsd-src · C · 89 lines · 30 code · 8 blank · 51 comment · 3 complexity · 4355116e8b35fad382f12e1ab7466201 MD5 · raw file

  1. /*
  2. * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net>
  3. *
  4. * Permission to use, copy, modify, and distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #if defined(LIBM_SCCS) && !defined(lint)
  17. static const char rcsid[] = "$ABSD$";
  18. #endif
  19. /* csin()
  20. *
  21. * Complex circular sine
  22. *
  23. *
  24. *
  25. * SYNOPSIS:
  26. *
  27. * double complex csin();
  28. * double complex z, w;
  29. *
  30. * w = csin (z);
  31. *
  32. *
  33. *
  34. * DESCRIPTION:
  35. *
  36. * If
  37. * z = x + iy,
  38. *
  39. * then
  40. *
  41. * w = sin x cosh y + i cos x sinh y.
  42. *
  43. * csin(z) = -i csinh(iz).
  44. *
  45. * ACCURACY:
  46. *
  47. * Relative error:
  48. * arithmetic domain # trials peak rms
  49. * DEC -10,+10 8400 5.3e-17 1.3e-17
  50. * IEEE -10,+10 30000 3.8e-16 1.0e-16
  51. * Also tested by csin(casin(z)) = z.
  52. *
  53. */
  54. #include <complex.h>
  55. #include <math.h>
  56. /* calculate cosh and sinh */
  57. static void
  58. cchsh(double x, double *c, double *s)
  59. {
  60. double e, ei;
  61. if (fabs(x) <= 0.5) {
  62. *c = cosh(x);
  63. *s = sinh(x);
  64. }
  65. else {
  66. e = exp(x);
  67. ei = 0.5/e;
  68. e = 0.5 * e;
  69. *s = e - ei;
  70. *c = e + ei;
  71. }
  72. }
  73. double complex
  74. csin(double complex z)
  75. {
  76. double complex w;
  77. double ch, sh;
  78. cchsh( cimag (z), &ch, &sh );
  79. w = sin (creal(z)) * ch + (cos (creal(z)) * sh) * I;
  80. return (w);
  81. }