/newlib/libm/complex/cacos.c

https://bitbucket.org/pizzafactory/binutils · C · 99 lines · 17 code · 6 blank · 76 comment · 0 complexity · 325d5824c512a84cc2750d3b7c57a3b2 MD5 · raw file

  1. /* $NetBSD: cacos.c,v 1.1 2007/08/20 16:01:30 drochner Exp $ */
  2. /*-
  3. * Copyright (c) 2007 The NetBSD Foundation, Inc.
  4. * All rights reserved.
  5. *
  6. * This code is derived from software written by Stephen L. Moshier.
  7. * It is redistributed by the NetBSD Foundation by permission of the author.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  19. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  20. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  21. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  22. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  23. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  24. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  25. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  26. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28. * POSSIBILITY OF SUCH DAMAGE.
  29. *
  30. * imported and modified include for newlib 2010/10/03
  31. * Marco Atzeri <marco_atzeri@yahoo.it>
  32. */
  33. /*
  34. FUNCTION
  35. <<cacos>>, <<cacosf>>---complex arc cosine
  36. INDEX
  37. cacos
  38. INDEX
  39. cacosf
  40. ANSI_SYNOPSIS
  41. #include <complex.h>
  42. double complex cacos(double complex <[z]>);
  43. float complex cacosf(float complex <[z]>);
  44. DESCRIPTION
  45. These functions compute the complex arc cosine of <[z]>,
  46. with branch cuts outside the interval [-1, +1] along the real axis.
  47. <<cacosf>> is identical to <<cacos>>, except that it performs
  48. its calculations on <<floats complex>>.
  49. RETURNS
  50. @ifnottex
  51. These functions return the complex arc cosine value, in the range
  52. of a strip mathematically unbounded along the imaginary axis
  53. and in the interval [0, pi] along the real axis.
  54. @end ifnottex
  55. @tex
  56. These functions return the complex arc cosine value, in the range
  57. of a strip mathematically unbounded along the imaginary axis
  58. and in the interval [<<0>>, $\pi$] along the real axis.
  59. @end tex
  60. PORTABILITY
  61. <<cacos>> and <<cacosf>> are ISO C99
  62. QUICKREF
  63. <<cacos>> and <<cacosf>> are ISO C99
  64. */
  65. #include <complex.h>
  66. #include <math.h>
  67. double complex
  68. cacos(double complex z)
  69. {
  70. double complex w;
  71. /* FIXME: The original NetBSD code results in an ICE when trying to
  72. build this function on ARM/Thumb using gcc 4.5.1. For now we use
  73. a hopefully temporary workaround. */
  74. #if 0
  75. w = casin(z);
  76. w = (M_PI_2 - creal(w)) - cimag(w) * I;
  77. #else
  78. double complex tmp0, tmp1;
  79. tmp0 = casin(z);
  80. tmp1 = M_PI_2 - creal(tmp0);
  81. w = tmp1 - (cimag(tmp0) * I);
  82. #endif
  83. return w;
  84. }