X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fsin.c;h=9b90c0f76c6769be4b2ef5ff6503af60e1af247a;hb=f34506723f150a03d5e6e389820bd369b89e30b0;hp=27df7618df8361c704a100c1adfa97be87c05f6f;hpb=c9266275a7240e07da227b662cc6afcb0000d7a6;p=platform%2Fupstream%2Fmpc.git diff --git a/src/sin.c b/src/sin.c index 27df761..9b90c0f 100644 --- a/src/sin.c +++ b/src/sin.c @@ -1,27 +1,169 @@ /* mpc_sin -- sine of a complex number. -Copyright (C) 2010, 2011 INRIA +Copyright (C) 2007, 2009 Paul Zimmermann, Philippe Th\'eveny -This file is part of GNU MPC. +This file is part of the MPC Library. -GNU MPC is free software; you can redistribute it and/or modify it under -the terms of the GNU Lesser General Public License as published by the -Free Software Foundation; either version 3 of the License, or (at your +The MPC Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. -GNU MPC is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for -more details. +The MPC Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. You should have received a copy of the GNU Lesser General Public License -along with this program. If not, see http://www.gnu.org/licenses/ . -*/ +along with the MPC Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, +MA 02111-1307, USA. */ #include "mpc-impl.h" int mpc_sin (mpc_ptr rop, mpc_srcptr op, mpc_rnd_t rnd) { - return MPC_INEX1 (mpc_sin_cos (rop, NULL, op, rnd, 0)); + mpfr_t x, y, z; + mp_prec_t prec; + int ok = 0; + int inex_re, inex_im; + + /* special values */ + if (!mpfr_number_p (MPC_RE (op)) || !mpfr_number_p (MPC_IM (op))) + { + if (mpfr_nan_p (MPC_RE (op)) || mpfr_nan_p (MPC_IM (op))) + { + mpc_set (rop, op, rnd); + + if (mpfr_nan_p (MPC_IM (op))) + { + /* sin(x +i*NaN) = NaN +i*NaN, except for x=0 */ + /* sin(-0 +i*NaN) = -0 +i*NaN */ + /* sin(+0 +i*NaN) = +0 +i*NaN */ + if (!mpfr_zero_p (MPC_RE (op))) + mpfr_set_nan (MPC_RE (rop)); + else if (!mpfr_inf_p (MPC_IM (op)) + && !mpfr_zero_p (MPC_IM (op))) + /* sin(NaN -i*Inf) = NaN -i*Inf */ + /* sin(NaN -i*0) = NaN -i*0 */ + /* sin(NaN +i*0) = NaN +i*0 */ + /* sin(NaN +i*Inf) = NaN +i*Inf */ + /* sin(NaN +i*y) = NaN +i*NaN, when 0<|y|= 2, r = sin(a)*cosh(b)*(1+4*t) with |t| <= 2^(-w), + thus the relative error is bounded by 4*2^(-w) <= 4*ulp(r). + */ + + prec = MPC_MAX_PREC(rop); + + mpfr_init2 (x, 2); + mpfr_init2 (y, 2); + mpfr_init2 (z, 2); + + do + { + prec += mpc_ceil_log2 (prec) + 5; + + mpfr_set_prec (x, prec); + mpfr_set_prec (y, prec); + mpfr_set_prec (z, prec); + + mpfr_sin_cos (x, y, MPC_RE(op), GMP_RNDN); + mpfr_cosh (z, MPC_IM(op), GMP_RNDN); + mpfr_mul (x, x, z, GMP_RNDN); + ok = mpfr_can_round (x, prec - 2, GMP_RNDN, GMP_RNDZ, + MPFR_PREC(MPC_RE(rop)) + (MPC_RND_RE(rnd) == GMP_RNDN)); + if (ok) /* compute imaginary part */ + { + mpfr_sinh (z, MPC_IM(op), GMP_RNDN); + mpfr_mul (y, y, z, GMP_RNDN); + ok = mpfr_can_round (y, prec - 2, GMP_RNDN, GMP_RNDZ, + MPFR_PREC(MPC_IM(rop)) + (MPC_RND_IM(rnd) == GMP_RNDN)); + } + } + while (ok == 0); + + inex_re = mpfr_set (MPC_RE(rop), x, MPC_RND_RE(rnd)); + inex_im = mpfr_set (MPC_IM(rop), y, MPC_RND_IM(rnd)); + + mpfr_clear (x); + mpfr_clear (y); + mpfr_clear (z); + + return MPC_INEX (inex_re, inex_im); }