s_csinl.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* $OpenBSD: s_csinl.c,v 1.2 2011/07/20 19:28:33 martynas 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. /* csinl()
  18. *
  19. * Complex circular sine
  20. *
  21. *
  22. *
  23. * SYNOPSIS:
  24. *
  25. * long double complex csinl();
  26. * long double complex z, w;
  27. *
  28. * w = csinl( z );
  29. *
  30. *
  31. *
  32. * DESCRIPTION:
  33. *
  34. * If
  35. * z = x + iy,
  36. *
  37. * then
  38. *
  39. * w = sin x cosh y + i cos x sinh y.
  40. *
  41. *
  42. *
  43. * ACCURACY:
  44. *
  45. * Relative error:
  46. * arithmetic domain # trials peak rms
  47. * DEC -10,+10 8400 5.3e-17 1.3e-17
  48. * IEEE -10,+10 30000 3.8e-16 1.0e-16
  49. * Also tested by csin(casin(z)) = z.
  50. *
  51. */
  52. #include <openlibm_complex.h>
  53. #include <openlibm_math.h>
  54. static void
  55. cchshl(long double x, long double *c, long double *s)
  56. {
  57. long double e, ei;
  58. if(fabsl(x) <= 0.5L) {
  59. *c = coshl(x);
  60. *s = sinhl(x);
  61. } else {
  62. e = expl(x);
  63. ei = 0.5L/e;
  64. e = 0.5L * e;
  65. *s = e - ei;
  66. *c = e + ei;
  67. }
  68. }
  69. long double complex
  70. csinl(long double complex z)
  71. {
  72. long double complex w;
  73. long double ch, sh;
  74. cchshl(cimagl(z), &ch, &sh);
  75. w = sinl(creall(z)) * ch + (cosl(creall(z)) * sh) * I;
  76. return (w);
  77. }