From 8da2ce0e5abd48f6b116e5ef9a8350751279b6a6 Mon Sep 17 00:00:00 2001 From: Aditya Upadhyay Date: Sat, 24 Jun 2017 21:02:01 +0530 Subject: [PATCH] Importing cprojl.c from NetBSD. --- newlib/libm/complex/Makefile.am | 2 +- newlib/libm/complex/Makefile.in | 12 ++++++-- newlib/libm/complex/cprojl.c | 64 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 newlib/libm/complex/cprojl.c diff --git a/newlib/libm/complex/Makefile.am b/newlib/libm/complex/Makefile.am index e4460c9..f42f35e 100644 --- a/newlib/libm/complex/Makefile.am +++ b/newlib/libm/complex/Makefile.am @@ -10,7 +10,7 @@ src = cabs.c cacos.c cacosh.c carg.c casin.c casinh.c \ cpow.c cproj.c creal.c \ csin.c csinh.c csqrt.c ctan.c ctanh.c -lsrc = cabsl.c creall.c cimagl.c ccoshl.c cacoshl.c csqrtl.c clogl.c cephes_subrl.c cargl.c +lsrc = cabsl.c creall.c cimagl.c ccoshl.c cacoshl.c csqrtl.c clogl.c cephes_subrl.c cargl.c cprojl.c fsrc = cabsf.c casinf.c ccosf.c cimagf.c cprojf.c \ csqrtf.c cacosf.c casinhf.c ccoshf.c clogf.c clog10f.c \ diff --git a/newlib/libm/complex/Makefile.in b/newlib/libm/complex/Makefile.in index 006e142..ceadf0f 100644 --- a/newlib/libm/complex/Makefile.in +++ b/newlib/libm/complex/Makefile.in @@ -99,7 +99,7 @@ am__objects_2 = lib_a-cabsf.$(OBJEXT) lib_a-casinf.$(OBJEXT) \ am__objects_3 = lib_a-cabsl.$(OBJEXT) lib_a-creall.$(OBJEXT) \ lib_a-cimagl.$(OBJEXT) lib_a-ccoshl.$(OBJEXT) lib_a-cacoshl.$(OBJEXT) \ lib_a-clogl.$(OBJEXT) lib_a-csqrtl.$(OBJEXT) lib_a-cephes_subrl.$(OBJEXT) \ - lib_a-cargl.$(OBJEXT) + lib_a-cargl.$(OBJEXT) lib_a-cprojl.$(OBJEXT) @USE_LIBTOOL_FALSE@am_lib_a_OBJECTS = $(am__objects_1) \ @USE_LIBTOOL_FALSE@ $(am__objects_2) $(am__objects_3) lib_a_OBJECTS = $(am_lib_a_OBJECTS) @@ -115,7 +115,7 @@ am__objects_5 = cabsf.lo casinf.lo ccosf.lo cimagf.lo cprojf.lo \ conjf.lo csinf.lo ctanhf.lo cargf.lo catanhf.lo cexpf.lo \ cpowf.lo csinhf.lo am__objects_6 = cabsl.lo creall.lo cimagl.lo ccoshl.lo cacoshl.lo \ - clogl.lo csqrtl.lo cephes_subrl.lo cargl.lo + clogl.lo csqrtl.lo cephes_subrl.lo cargl.lo cprojl.lo @USE_LIBTOOL_TRUE@am_libcomplex_la_OBJECTS = $(am__objects_4) \ @USE_LIBTOOL_TRUE@ $(am__objects_5) $(am__objects_6) libcomplex_la_OBJECTS = $(am_libcomplex_la_OBJECTS) @@ -279,7 +279,7 @@ src = cabs.c cacos.c cacosh.c carg.c casin.c casinh.c \ cpow.c cproj.c creal.c \ csin.c csinh.c csqrt.c ctan.c ctanh.c -lsrc = cabsl.c creall.c cimagl.c ccoshl.c cacoshl.c clogl.c csqrtl.c cephes_subrl.c cargl.c +lsrc = cabsl.c creall.c cimagl.c ccoshl.c cacoshl.c clogl.c csqrtl.c cephes_subrl.c cargl.c cprojl.c fsrc = cabsf.c casinf.c ccosf.c cimagf.c cprojf.c \ csqrtf.c cacosf.c casinhf.c ccoshf.c clogf.c clog10f.c \ crealf.c ctanf.c cacoshf.c catanf.c \ @@ -650,6 +650,12 @@ lib_a-cargl.o: cargl.c lib_a-cargl.obj: cargl.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-cargl.obj `if test -f 'cargl.c'; then $(CYGPATH_W) 'cargl.c'; else $(CYGPATH_W) '$(srcdir)/cargl.c'; fi` +lib_a-cprojl.o: cprojl.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-cprojl.o `test -f 'cprojl.c' || echo '$(srcdir)/'`cprojl.c + +lib_a-cprojl.obj: cprojl.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-cprojl.obj `if test -f 'cprojl.c'; then $(CYGPATH_W) 'cprojl.c'; else $(CYGPATH_W) '$(srcdir)/cprojl.c'; fi` + lib_a-catanhf.o: catanhf.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-catanhf.o `test -f 'catanhf.c' || echo '$(srcdir)/'`catanhf.c diff --git a/newlib/libm/complex/cprojl.c b/newlib/libm/complex/cprojl.c new file mode 100644 index 0000000..e71c773 --- /dev/null +++ b/newlib/libm/complex/cprojl.c @@ -0,0 +1,64 @@ +/* $NetBSD: cprojl.c,v 1.7 2014/10/10 00:48:18 christos Exp $ */ + +/*- + * Copyright (c) 2010 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include +__RCSID("$NetBSD: cprojl.c,v 1.7 2014/10/10 00:48:18 christos Exp $"); + +#include +#include + +#include "../common/fdlibm.h" + +/* + * cprojl(long double complex z) + * + * These functions return the value of the projection (not stereographic!) + * onto the Riemann sphere. + * + * z projects to z, except that all complex infinities (even those with one + * infinite part and one NaN part) project to positive infinity on the real axis. + * If z has an infinite part, then cproj(z) shall be equivalent to: + * + * INFINITY + I * copysign(0.0, cimag(z)) + */ +long double complex +cprojl(long double complex z) +{ + long_double_complex w = { .z = z }; + + /*CONSTCOND*/ + if (isinf(creall(z)) || isinf(cimagl(z))) { +#ifdef __INFINITY + REAL_PART(w) = HUGE_VAL; +#else + REAL_PART(w) = INFINITY; +#endif + IMAG_PART(w) = copysignl(0.0L, cimagl(z)); + } + + return (w.z); +} -- 2.7.4