/newlib/libm/complex/cprojf.c

https://bitbucket.org/pizzafactory/binutils · C · 68 lines · 18 code · 8 blank · 42 comment · 2 complexity · 0bf052f3d000f9a1e672f1f4a3a84082 MD5 · raw file

  1. /* $NetBSD: cprojf.c,v 1.3 2010/09/20 17:51:38 christos Exp $ */
  2. /*-
  3. * Copyright (c) 2010 The NetBSD Foundation, Inc.
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  16. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  17. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  18. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  19. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  20. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  21. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  22. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  23. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  24. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  25. * POSSIBILITY OF SUCH DAMAGE.
  26. *
  27. * imported and modified include for newlib 2010/10/03
  28. * Marco Atzeri <marco_atzeri@yahoo.it>
  29. */
  30. #include <sys/cdefs.h>
  31. /*__RCSID("$NetBSD: cprojf.c,v 1.3 2010/09/20 17:51:38 christos Exp $"); */
  32. #include <complex.h>
  33. #include <math.h>
  34. #include "../common/fdlibm.h"
  35. /*
  36. * cprojf(float complex z)
  37. *
  38. * These functions return the value of the projection (not stereographic!)
  39. * onto the Riemann sphere.
  40. *
  41. * z projects to z, except that all complex infinities (even those with one
  42. * infinite part and one NaN part) project to positive infinity on the real axis.
  43. * If z has an infinite part, then cproj(z) shall be equivalent to:
  44. *
  45. * INFINITY + I * copysign(0.0, cimag(z))
  46. */
  47. float complex
  48. cprojf(float complex z)
  49. {
  50. float_complex w = { .z = z };
  51. if (isinf(crealf(z)) || isinf(cimagf(z))) {
  52. #ifdef __INFINITY
  53. REAL_PART(w) = __INFINITY;
  54. #else
  55. REAL_PART(w) = INFINITY;
  56. #endif
  57. IMAG_PART(w) = copysignf(0.0, cimagf(z));
  58. }
  59. return (w.z);
  60. }