diff options
Diffstat (limited to 'libc/math')
-rw-r--r-- | libc/math/Makefile | 4 | ||||
-rw-r--r-- | libc/math/libm-test.inc | 136 | ||||
-rw-r--r-- | libc/math/s_ctan.c | 44 | ||||
-rw-r--r-- | libc/math/s_ctanf.c | 44 | ||||
-rw-r--r-- | libc/math/s_ctanh.c | 43 | ||||
-rw-r--r-- | libc/math/s_ctanhf.c | 43 | ||||
-rw-r--r-- | libc/math/s_ctanhl.c | 43 | ||||
-rw-r--r-- | libc/math/s_ctanl.c | 45 | ||||
-rw-r--r-- | libc/math/w_ilogb.c | 42 | ||||
-rw-r--r-- | libc/math/w_ilogbf.c | 38 | ||||
-rw-r--r-- | libc/math/w_ilogbl.c | 37 |
11 files changed, 423 insertions, 96 deletions
diff --git a/libc/math/Makefile b/libc/math/Makefile index 826acb7a3..25a62e5f2 100644 --- a/libc/math/Makefile +++ b/libc/math/Makefile @@ -44,14 +44,16 @@ libm-support = k_standard s_lib_version s_matherr s_signgam \ libm-calls = e_acos e_acosh e_asin e_atan2 e_atanh e_cosh e_exp e_fmod \ e_hypot e_j0 e_j1 e_jn e_lgamma_r e_log e_log10 e_pow \ e_rem_pio2 e_remainder e_scalb e_sinh e_sqrt e_gamma_r \ + e_ilogb \ k_cos k_rem_pio2 k_sin k_tan s_asinh s_atan s_cbrt \ s_ceil s_cos s_erf s_expm1 s_fabs \ - s_floor s_ilogb s_log1p s_logb \ + s_floor s_log1p s_logb \ s_nextafter s_nexttoward s_rint s_scalbln \ s_significand s_sin s_tan s_tanh w_acos w_acosh w_asin \ w_atan2 w_atanh w_cosh w_drem w_exp w_exp2 w_exp10 w_fmod \ w_tgamma w_hypot w_j0 w_j1 w_jn w_lgamma w_lgamma_r \ w_log w_log10 w_pow w_remainder w_scalb w_sinh w_sqrt \ + w_ilogb \ s_fpclassify s_fmax s_fmin s_fdim s_nan s_trunc \ s_remquo e_log2 e_exp2 s_round s_nearbyint s_sincos \ conj cimag creal cabs carg s_cexp s_csinh s_ccosh s_clog \ diff --git a/libc/math/libm-test.inc b/libc/math/libm-test.inc index 5401031ee..258f8b874 100644 --- a/libc/math/libm-test.inc +++ b/libc/math/libm-test.inc @@ -2848,6 +2848,36 @@ ctan_test (void) TEST_c_c (ctan, 0.75L, 1.25L, 0.160807785916206426725166058173438663L, 0.975363285031235646193581759755216379L); TEST_c_c (ctan, -2, -3, 0.376402564150424829275122113032269084e-2L, -1.00323862735360980144635859782192726L); + TEST_c_c (ctan, 1, 45, 1.490158918874345552942703234806348520895e-39L, 1.000000000000000000000000000000000000001L); + TEST_c_c (ctan, 1, 47, 2.729321264492904590777293425576722354636e-41L, 1.0); + +#ifndef TEST_FLOAT + TEST_c_c (ctan, 1, 355, 8.140551093483276762350406321792653551513e-309L, 1.0); + TEST_c_c (ctan, 1, 365, 1.677892637497921890115075995898773550884e-317L, 1.0); +#endif + +#if defined TEST_LDOUBLE && LDBL_MAX_EXP >= 16384 + TEST_c_c (ctan, 1, 5680, 4.725214596136812019616700920476949798307e-4934L, 1.0); + TEST_c_c (ctan, 1, 5690, 9.739393181626937151720816611272607059057e-4943L, 1.0); +#endif + + TEST_c_c (ctan, 0x3.243f6cp-1, 0, -2.287733242885645987394874673945769518150e7L, 0.0); + + TEST_c_c (ctan, 0x1p127, 1, 0.2446359391192790896381501310437708987204L, 0.9101334047676183761532873794426475906201L); + +#ifndef TEST_FLOAT + TEST_c_c (ctan, 0x1p1023, 1, -0.2254627924997545057926782581695274244229L, 0.8786063118883068695462540226219865087189L); +#endif + +#if defined TEST_LDOUBLE && LDBL_MAX_EXP >= 16384 + TEST_c_c (ctan, 0x1p16383L, 1, 0.1608598776370396607204448234354670036772L, 0.8133818522051542536316746743877629761488L); +#endif + + TEST_c_c (ctan, 50000, 50000, plus_zero, 1.0); + TEST_c_c (ctan, 50000, -50000, plus_zero, -1.0); + TEST_c_c (ctan, -50000, 50000, minus_zero, 1.0); + TEST_c_c (ctan, -50000, -50000, minus_zero, -1.0); + END (ctan, complex); } @@ -2907,6 +2937,36 @@ ctanh_test (void) TEST_c_c (ctanh, 0.75L, 1.25L, 1.37260757053378320258048606571226857L, 0.385795952609750664177596760720790220L); TEST_c_c (ctanh, -2, -3, -0.965385879022133124278480269394560686L, 0.988437503832249372031403430350121098e-2L); + TEST_c_c (ctanh, 45, 1, 1.000000000000000000000000000000000000001L, 1.490158918874345552942703234806348520895e-39L); + TEST_c_c (ctanh, 47, 1, 1.0, 2.729321264492904590777293425576722354636e-41L); + +#ifndef TEST_FLOAT + TEST_c_c (ctanh, 355, 1, 1.0, 8.140551093483276762350406321792653551513e-309L); + TEST_c_c (ctanh, 365, 1, 1.0, 1.677892637497921890115075995898773550884e-317L); +#endif + +#if defined TEST_LDOUBLE && LDBL_MAX_EXP >= 16384 + TEST_c_c (ctanh, 5680, 1, 1.0, 4.725214596136812019616700920476949798307e-4934L); + TEST_c_c (ctanh, 5690, 1, 1.0, 9.739393181626937151720816611272607059057e-4943L); +#endif + + TEST_c_c (ctanh, 0, 0x3.243f6cp-1, 0.0, -2.287733242885645987394874673945769518150e7L); + + TEST_c_c (ctanh, 1, 0x1p127, 0.9101334047676183761532873794426475906201L, 0.2446359391192790896381501310437708987204L); + +#ifndef TEST_FLOAT + TEST_c_c (ctanh, 1, 0x1p1023, 0.8786063118883068695462540226219865087189L, -0.2254627924997545057926782581695274244229L); +#endif + +#if defined TEST_LDOUBLE && LDBL_MAX_EXP >= 16384 + TEST_c_c (ctanh, 1, 0x1p16383L, 0.8133818522051542536316746743877629761488L, 0.1608598776370396607204448234354670036772L); +#endif + + TEST_c_c (ctanh, 50000, 50000, 1.0, plus_zero); + TEST_c_c (ctanh, 50000, -50000, 1.0, minus_zero); + TEST_c_c (ctanh, -50000, 50000, -1.0, plus_zero); + TEST_c_c (ctanh, -50000, -50000, -1.0, minus_zero); + END (ctanh, complex); } @@ -3016,8 +3076,7 @@ exp_test (void) /* Bug 13922: OVERFLOW exception may be missing. */ TEST_f_f (exp, max_value, plus_infty, OVERFLOW_EXCEPTION_OK); - /* Bug 13705: spurious OVERFLOW exception may be present. */ - TEST_f_f (exp, -max_value, 0, OVERFLOW_EXCEPTION_OK); + TEST_f_f (exp, -max_value, 0); END (exp); } @@ -3756,13 +3815,22 @@ ilogb_test (void) TEST_f_i (ilogb, 1024, 10); TEST_f_i (ilogb, -2000, 10); - /* XXX We have a problem here: the standard does not tell us whether - exceptions are allowed/required. ignore them for now. */ - - TEST_f_i (ilogb, 0.0, FP_ILOGB0, EXCEPTIONS_OK); - TEST_f_i (ilogb, nan_value, FP_ILOGBNAN, EXCEPTIONS_OK); - TEST_f_i (ilogb, plus_infty, INT_MAX, EXCEPTIONS_OK); - TEST_f_i (ilogb, minus_infty, INT_MAX, EXCEPTIONS_OK); + /* ilogb (0.0) == FP_ILOGB0 plus invalid exception */ + errno = 0; + TEST_f_i (ilogb, 0.0, FP_ILOGB0, INVALID_EXCEPTION); + check_int ("errno for ilogb(0.0) unchanged", errno, EDOM, 0, 0, 0); + /* ilogb (NaN) == FP_ILOGBNAN plus invalid exception */ + errno = 0; + TEST_f_i (ilogb, nan_value, FP_ILOGBNAN, INVALID_EXCEPTION); + check_int ("errno for ilogb(NaN) unchanged", errno, EDOM, 0, 0, 0); + /* ilogb (inf) == INT_MAX plus invalid exception */ + errno = 0; + TEST_f_i (ilogb, plus_infty, INT_MAX, INVALID_EXCEPTION); + check_int ("errno for ilogb(Inf) unchanged", errno, EDOM, 0, 0, 0); + /* ilogb (-inf) == INT_MAX plus invalid exception */ + errno = 0; + TEST_f_i (ilogb, minus_infty, INT_MAX, INVALID_EXCEPTION); + check_int ("errno for ilogb(-Inf) unchanged", errno, EDOM, 0, 0, 0); END (ilogb); } @@ -5635,10 +5703,8 @@ pow_test (void) TEST_ff_f (pow, 0x1p72L, 0x1p72L, plus_infty, OVERFLOW_EXCEPTION); TEST_ff_f (pow, 10, -0x1p72L, 0); - /* Bug 13873: OVERFLOW exception may be missing. */ - TEST_ff_f (pow, max_value, max_value, plus_infty, OVERFLOW_EXCEPTION_OK); - /* Bug 13872: spurious OVERFLOW exception may be present. */ - TEST_ff_f (pow, 10, -max_value, 0, OVERFLOW_EXCEPTION_OK); + TEST_ff_f (pow, max_value, max_value, plus_infty, OVERFLOW_EXCEPTION); + TEST_ff_f (pow, 10, -max_value, 0); TEST_ff_f (pow, 0, 1, 0); TEST_ff_f (pow, 0, 11, 0); @@ -5922,8 +5988,7 @@ pow_test (void) TEST_ff_f (pow, -2.0, 0x1.ffffffffffffffffffffffffffffp+113L, plus_infty, OVERFLOW_EXCEPTION); # endif #endif - /* Bug 13873: OVERFLOW exception may be missing. */ - TEST_ff_f (pow, -2.0, max_value, plus_infty, OVERFLOW_EXCEPTION_OK); + TEST_ff_f (pow, -2.0, max_value, plus_infty, OVERFLOW_EXCEPTION); TEST_ff_f (pow, -max_value, 0.5, nan_value, INVALID_EXCEPTION); TEST_ff_f (pow, -max_value, 1.5, nan_value, INVALID_EXCEPTION); @@ -5953,8 +6018,7 @@ pow_test (void) TEST_ff_f (pow, -max_value, -0x1.ffffffffffffffffffffffffffffp+113L, plus_zero); # endif #endif - /* Bug 13872: spurious OVERFLOW exception may be present. */ - TEST_ff_f (pow, -max_value, -max_value, plus_zero, OVERFLOW_EXCEPTION_OK); + TEST_ff_f (pow, -max_value, -max_value, plus_zero); TEST_ff_f (pow, -max_value, 0xffffff, minus_infty, OVERFLOW_EXCEPTION); TEST_ff_f (pow, -max_value, 0x1fffffe, plus_infty, OVERFLOW_EXCEPTION); @@ -5976,8 +6040,7 @@ pow_test (void) TEST_ff_f (pow, -max_value, 0x1.ffffffffffffffffffffffffffffp+113L, plus_infty, OVERFLOW_EXCEPTION); # endif #endif - /* Bug 13873: OVERFLOW exception may be missing. */ - TEST_ff_f (pow, -max_value, max_value, plus_infty, OVERFLOW_EXCEPTION_OK); + TEST_ff_f (pow, -max_value, max_value, plus_infty, OVERFLOW_EXCEPTION); TEST_ff_f (pow, -0.5, 126, 0x1p-126); TEST_ff_f (pow, -0.5, 127, -0x1p-127); @@ -6004,8 +6067,7 @@ pow_test (void) TEST_ff_f (pow, -0.5, -0x1.ffffffffffffffffffffffffffffp+113L, plus_infty, OVERFLOW_EXCEPTION); # endif #endif - /* Bug 13873: OVERFLOW exception may be missing. */ - TEST_ff_f (pow, -0.5, -max_value, plus_infty, OVERFLOW_EXCEPTION_OK); + TEST_ff_f (pow, -0.5, -max_value, plus_infty, OVERFLOW_EXCEPTION); TEST_ff_f (pow, -0.5, 0xffffff, minus_zero); TEST_ff_f (pow, -0.5, 0x1fffffe, plus_zero); @@ -6058,8 +6120,7 @@ pow_test (void) TEST_ff_f (pow, -min_value, -0x1.ffffffffffffffffffffffffffffp+113L, plus_infty, OVERFLOW_EXCEPTION); # endif #endif - /* Bug 13873: OVERFLOW exception may be missing. */ - TEST_ff_f (pow, -min_value, -max_value, plus_infty, OVERFLOW_EXCEPTION_OK); + TEST_ff_f (pow, -min_value, -max_value, plus_infty, OVERFLOW_EXCEPTION); TEST_ff_f (pow, -min_value, 0xffffff, minus_zero); TEST_ff_f (pow, -min_value, 0x1fffffe, plus_zero); @@ -6081,8 +6142,33 @@ pow_test (void) TEST_ff_f (pow, -min_value, 0x1.ffffffffffffffffffffffffffffp+113L, plus_zero); # endif #endif - /* Bug 13872: spurious OVERFLOW exception may be present. */ - TEST_ff_f (pow, -min_value, max_value, plus_zero, OVERFLOW_EXCEPTION_OK); + TEST_ff_f (pow, -min_value, max_value, plus_zero); + +#ifndef TEST_LDOUBLE /* Bug 13881. */ + TEST_ff_f (pow, 0x0.ffffffp0, 10, 0.999999403953712118183885036774764444747L); + TEST_ff_f (pow, 0x0.ffffffp0, 100, 0.999994039553108359406305079606228341585L); + TEST_ff_f (pow, 0x0.ffffffp0, 1000, 0.9999403971297699052276650144650733772182L); + TEST_ff_f (pow, 0x0.ffffffp0, 0x1p24, 0.3678794302077803437135155590023422899744L); + TEST_ff_f (pow, 0x0.ffffffp0, 0x1p30, 1.603807831524924233828134753069728224044e-28L); + TEST_ff_f (pow, 0x0.ffffffp0, 0x1.234566p30, 2.374884712135295099971443365381007297732e-32L); + TEST_ff_f (pow, 0x0.ffffffp0, -10, 1.000000596046643153205170848674671339688L); + TEST_ff_f (pow, 0x0.ffffffp0, -100, 1.000005960482418779499387594989252621451L); + TEST_ff_f (pow, 0x0.ffffffp0, -1000, 1.000059606422943986382898964231519867906L); + TEST_ff_f (pow, 0x0.ffffffp0, -0x1p24, 2.7182819094701610539628664526874952929416L); + TEST_ff_f (pow, 0x0.ffffffp0, -0x1p30, 6.2351609734265057988914412331288163636075e+27L); + TEST_ff_f (pow, 0x0.ffffffp0, -0x1.234566p30, 4.2107307141696353498921307077142537353515e+31L); + TEST_ff_f (pow, 0x1.000002p0, 0x1p24, 7.3890552180866447284268641248075832310141L); + TEST_ff_f (pow, 0x1.000002p0, 0x1.234566p29, 4.2107033006507495188536371520637025716256e+31L); + TEST_ff_f (pow, 0x1.000002p0, -0x1.234566p29, 2.3749001736727769098946062325205705312166e-32L); +#endif + + /* Bug 13881: powl inaccurate so these tests disabled for long double. */ +#if !defined TEST_FLOAT && !defined TEST_LDOUBLE + TEST_ff_f (pow, 0x0.fffffffffffff8p0L, 0x1.23456789abcdfp62L, 1.0118762747827252817436395051178295138220e-253L); + TEST_ff_f (pow, 0x0.fffffffffffff8p0L, -0x1.23456789abcdfp62L, 9.8826311568054561811190162420900667121992e+252L); + TEST_ff_f (pow, 0x1.0000000000001p0L, 0x1.23456789abcdfp61L, 9.8826311568044974397135026217687399395481e+252L); + TEST_ff_f (pow, 0x1.0000000000001p0L, -0x1.23456789abcdfp61L, 1.0118762747828234466621210689458255908670e-253L); +#endif END (pow); } diff --git a/libc/math/s_ctan.c b/libc/math/s_ctan.c index c838fadeb..78117b310 100644 --- a/libc/math/s_ctan.c +++ b/libc/math/s_ctan.c @@ -1,5 +1,5 @@ /* Complex tangent function for double. - Copyright (C) 1997, 2005, 2011 Free Software Foundation, Inc. + Copyright (C) 1997-2012 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. @@ -20,9 +20,8 @@ #include <complex.h> #include <fenv.h> #include <math.h> - #include <math_private.h> - +#include <float.h> __complex__ double __ctan (__complex__ double x) @@ -51,24 +50,45 @@ __ctan (__complex__ double x) } else { - double sin2rx, cos2rx; + double sinrx, cosrx; double den; + const int t = (int) ((DBL_MAX_EXP - 1) * M_LN2 / 2); - __sincos (2.0 * __real__ x, &sin2rx, &cos2rx); + /* tan(x+iy) = (sin(2x) + i*sinh(2y))/(cos(2x) + cosh(2y)) + = (sin(x)*cos(x) + i*sinh(y)*cosh(y)/(cos(x)^2 + sinh(y)^2). */ - den = cos2rx + __ieee754_cosh (2.0 * __imag__ x); + __sincos (__real__ x, &sinrx, &cosrx); - if (den == 0.0) + if (fabs (__imag__ x) > t) { - __complex__ double ez = __cexp (1.0i * x); - __complex__ double emz = __cexp (-1.0i * x); + /* Avoid intermediate overflow when the real part of the + result may be subnormal. Ignoring negligible terms, the + imaginary part is +/- 1, the real part is + sin(x)*cos(x)/sinh(y)^2 = 4*sin(x)*cos(x)/exp(2y). */ + double exp_2t = __ieee754_exp (2 * t); - res = (ez - emz) / (ez + emz) * -1.0i; + __imag__ res = __copysign (1.0, __imag__ x); + __real__ res = 4 * sinrx * cosrx; + __imag__ x = fabs (__imag__ x); + __imag__ x -= t; + __real__ res /= exp_2t; + if (__imag__ x > t) + { + /* Underflow (original imaginary part of x has absolute + value > 2t). */ + __real__ res /= exp_2t; + } + else + __real__ res /= __ieee754_exp (2 * __imag__ x); } else { - __real__ res = sin2rx / den; - __imag__ res = __ieee754_sinh (2.0 * __imag__ x) / den; + double sinhix = __ieee754_sinh (__imag__ x); + double coshix = __ieee754_cosh (__imag__ x); + + den = cosrx * cosrx + sinhix * sinhix; + __real__ res = sinrx * cosrx / den; + __imag__ res = sinhix * coshix / den; } } diff --git a/libc/math/s_ctanf.c b/libc/math/s_ctanf.c index 5f7f28ad0..4cba559a4 100644 --- a/libc/math/s_ctanf.c +++ b/libc/math/s_ctanf.c @@ -1,5 +1,5 @@ /* Complex tangent function for float. - Copyright (C) 1997, 2005, 2011 Free Software Foundation, Inc. + Copyright (C) 1997-2012 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. @@ -21,7 +21,7 @@ #include <fenv.h> #include <math.h> #include <math_private.h> - +#include <float.h> __complex__ float __ctanf (__complex__ float x) @@ -50,25 +50,45 @@ __ctanf (__complex__ float x) } else { - float sin2rx, cos2rx; + float sinrx, cosrx; float den; + const int t = (int) ((FLT_MAX_EXP - 1) * M_LN2 / 2); - __sincosf (2.0 * __real__ x, &sin2rx, &cos2rx); - - den = cos2rx + __ieee754_coshf (2.0 * __imag__ x); + /* tan(x+iy) = (sin(2x) + i*sinh(2y))/(cos(2x) + cosh(2y)) + = (sin(x)*cos(x) + i*sinh(y)*cosh(y)/(cos(x)^2 + sinh(y)^2). */ + __sincosf (__real__ x, &sinrx, &cosrx); - if (den == 0.0) + if (fabsf (__imag__ x) > t) { - __complex__ float ez = __cexpf (1.0i * x); - __complex__ float emz = __cexpf (-1.0i * x); + /* Avoid intermediate overflow when the real part of the + result may be subnormal. Ignoring negligible terms, the + imaginary part is +/- 1, the real part is + sin(x)*cos(x)/sinh(y)^2 = 4*sin(x)*cos(x)/exp(2y). */ + float exp_2t = __ieee754_expf (2 * t); - res = (ez - emz) / (ez + emz) * -1.0i; + __imag__ res = __copysignf (1.0, __imag__ x); + __real__ res = 4 * sinrx * cosrx; + __imag__ x = fabsf (__imag__ x); + __imag__ x -= t; + __real__ res /= exp_2t; + if (__imag__ x > t) + { + /* Underflow (original imaginary part of x has absolute + value > 2t). */ + __real__ res /= exp_2t; + } + else + __real__ res /= __ieee754_expf (2 * __imag__ x); } else { - __real__ res = sin2rx / den; - __imag__ res = __ieee754_sinhf (2.0 * __imag__ x) / den; + float sinhix = __ieee754_sinhf (__imag__ x); + float coshix = __ieee754_coshf (__imag__ x); + + den = cosrx * cosrx + sinhix * sinhix; + __real__ res = sinrx * cosrx / den; + __imag__ res = sinhix * coshix / den; } } diff --git a/libc/math/s_ctanh.c b/libc/math/s_ctanh.c index 9cecb8bdb..201871e7e 100644 --- a/libc/math/s_ctanh.c +++ b/libc/math/s_ctanh.c @@ -1,5 +1,5 @@ /* Complex hyperbole tangent for double. - Copyright (C) 1997, 2005, 2011 Free Software Foundation, Inc. + Copyright (C) 1997-2012 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. @@ -21,7 +21,7 @@ #include <fenv.h> #include <math.h> #include <math_private.h> - +#include <float.h> __complex__ double __ctanh (__complex__ double x) @@ -50,24 +50,45 @@ __ctanh (__complex__ double x) } else { - double sin2ix, cos2ix; + double sinix, cosix; double den; + const int t = (int) ((DBL_MAX_EXP - 1) * M_LN2 / 2); - __sincos (2.0 * __imag__ x, &sin2ix, &cos2ix); + /* tanh(x+iy) = (sinh(2x) + i*sin(2y))/(cosh(2x) + cos(2y)) + = (sinh(x)*cosh(x) + i*sin(y)*cos(y))/(sinh(x)^2 + cos(y)^2). */ - den = (__ieee754_cosh (2.0 * __real__ x) + cos2ix); + __sincos (__imag__ x, &sinix, &cosix); - if (den == 0.0) + if (fabs (__real__ x) > t) { - __complex__ double ez = __cexp (x); - __complex__ double emz = __cexp (-x); + /* Avoid intermediate overflow when the imaginary part of + the result may be subnormal. Ignoring negligible terms, + the real part is +/- 1, the imaginary part is + sin(y)*cos(y)/sinh(x)^2 = 4*sin(y)*cos(y)/exp(2x). */ + double exp_2t = __ieee754_exp (2 * t); - res = (ez - emz) / (ez + emz); + __real__ res = __copysign (1.0, __real__ x); + __imag__ res = 4 * sinix * cosix; + __real__ x = fabs (__real__ x); + __real__ x -= t; + __imag__ res /= exp_2t; + if (__real__ x > t) + { + /* Underflow (original real part of x has absolute value + > 2t). */ + __imag__ res /= exp_2t; + } + else + __imag__ res /= __ieee754_exp (2 * __real__ x); } else { - __real__ res = __ieee754_sinh (2.0 * __real__ x) / den; - __imag__ res = sin2ix / den; + double sinhrx = __ieee754_sinh (__real__ x); + double coshrx = __ieee754_cosh (__real__ x); + + den = sinhrx * sinhrx + cosix * cosix; + __real__ res = sinhrx * coshrx / den; + __imag__ res = sinix * cosix / den; } } diff --git a/libc/math/s_ctanhf.c b/libc/math/s_ctanhf.c index fce5aaf29..e50515577 100644 --- a/libc/math/s_ctanhf.c +++ b/libc/math/s_ctanhf.c @@ -1,5 +1,5 @@ /* Complex hyperbole tangent for float. - Copyright (C) 1997, 2005, 2011 Free Software Foundation, Inc. + Copyright (C) 1997-2012 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. @@ -21,7 +21,7 @@ #include <fenv.h> #include <math.h> #include <math_private.h> - +#include <float.h> __complex__ float __ctanhf (__complex__ float x) @@ -50,24 +50,45 @@ __ctanhf (__complex__ float x) } else { - float sin2ix, cos2ix; + float sinix, cosix; float den; + const int t = (int) ((FLT_MAX_EXP - 1) * M_LN2 / 2); - __sincosf (2.0 * __imag__ x, &sin2ix, &cos2ix); + /* tanh(x+iy) = (sinh(2x) + i*sin(2y))/(cosh(2x) + cos(2y)) + = (sinh(x)*cosh(x) + i*sin(y)*cos(y))/(sinh(x)^2 + cos(y)^2). */ - den = (__ieee754_coshf (2.0 * __real__ x) + cos2ix); + __sincosf (__imag__ x, &sinix, &cosix); - if (den == 0.0f) + if (fabsf (__real__ x) > t) { - __complex__ float ez = __cexpf (x); - __complex__ float emz = __cexpf (-x); + /* Avoid intermediate overflow when the imaginary part of + the result may be subnormal. Ignoring negligible terms, + the real part is +/- 1, the imaginary part is + sin(y)*cos(y)/sinh(x)^2 = 4*sin(y)*cos(y)/exp(2x). */ + float exp_2t = __ieee754_expf (2 * t); - res = (ez - emz) / (ez + emz); + __real__ res = __copysignf (1.0, __real__ x); + __imag__ res = 4 * sinix * cosix; + __real__ x = fabsf (__real__ x); + __real__ x -= t; + __imag__ res /= exp_2t; + if (__real__ x > t) + { + /* Underflow (original real part of x has absolute value + > 2t). */ + __imag__ res /= exp_2t; + } + else + __imag__ res /= __ieee754_expf (2 * __real__ x); } else { - __real__ res = __ieee754_sinhf (2.0 * __real__ x) / den; - __imag__ res = sin2ix / den; + float sinhrx = __ieee754_sinhf (__real__ x); + float coshrx = __ieee754_coshf (__real__ x); + + den = sinhrx * sinhrx + cosix * cosix; + __real__ res = sinhrx * coshrx / den; + __imag__ res = sinix * cosix / den; } } diff --git a/libc/math/s_ctanhl.c b/libc/math/s_ctanhl.c index d22e13a97..e5d677903 100644 --- a/libc/math/s_ctanhl.c +++ b/libc/math/s_ctanhl.c @@ -1,5 +1,5 @@ /* Complex hyperbole tangent for long double. - Copyright (C) 1997, 2005, 2011 Free Software Foundation, Inc. + Copyright (C) 1997-2012 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. @@ -21,7 +21,7 @@ #include <fenv.h> #include <math.h> #include <math_private.h> - +#include <float.h> __complex__ long double __ctanhl (__complex__ long double x) @@ -50,24 +50,45 @@ __ctanhl (__complex__ long double x) } else { - long double sin2ix, cos2ix; + long double sinix, cosix; long double den; + const int t = (int) ((LDBL_MAX_EXP - 1) * M_LN2l / 2); - __sincosl (2.0 * __imag__ x, &sin2ix, &cos2ix); + /* tanh(x+iy) = (sinh(2x) + i*sin(2y))/(cosh(2x) + cos(2y)) + = (sinh(x)*cosh(x) + i*sin(y)*cos(y))/(sinh(x)^2 + cos(y)^2). */ - den = (__ieee754_coshl (2.0 * __real__ x) + cos2ix); + __sincosl (__imag__ x, &sinix, &cosix); - if (den == 0.0L) + if (fabsl (__real__ x) > t) { - __complex__ long double ez = __cexpl (x); - __complex__ long double emz = __cexpl (-x); + /* Avoid intermediate overflow when the imaginary part of + the result may be subnormal. Ignoring negligible terms, + the real part is +/- 1, the imaginary part is + sin(y)*cos(y)/sinh(x)^2 = 4*sin(y)*cos(y)/exp(2x). */ + long double exp_2t = __ieee754_expl (2 * t); - res = (ez - emz) / (ez + emz); + __real__ res = __copysignl (1.0, __real__ x); + __imag__ res = 4 * sinix * cosix; + __real__ x = fabsl (__real__ x); + __real__ x -= t; + __imag__ res /= exp_2t; + if (__real__ x > t) + { + /* Underflow (original real part of x has absolute value + > 2t). */ + __imag__ res /= exp_2t; + } + else + __imag__ res /= __ieee754_expl (2 * __real__ x); } else { - __real__ res = __ieee754_sinhl (2.0 * __real__ x) / den; - __imag__ res = sin2ix / den; + long double sinhrx = __ieee754_sinhl (__real__ x); + long double coshrx = __ieee754_coshl (__real__ x); + + den = sinhrx * sinhrx + cosix * cosix; + __real__ res = sinhrx * coshrx / den; + __imag__ res = sinix * cosix / den; } } diff --git a/libc/math/s_ctanl.c b/libc/math/s_ctanl.c index 112dd723d..12d700cad 100644 --- a/libc/math/s_ctanl.c +++ b/libc/math/s_ctanl.c @@ -1,5 +1,5 @@ /* Complex tangent function for long double. - Copyright (C) 1997, 2005, 2011 Free Software Foundation, Inc. + Copyright (C) 1997-2012 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. @@ -20,9 +20,8 @@ #include <complex.h> #include <fenv.h> #include <math.h> - #include <math_private.h> - +#include <float.h> __complex__ long double __ctanl (__complex__ long double x) @@ -51,25 +50,45 @@ __ctanl (__complex__ long double x) } else { - long double sin2rx, cos2rx; + long double sinrx, cosrx; long double den; + const int t = (int) ((LDBL_MAX_EXP - 1) * M_LN2l / 2); - __sincosl (2.0 * __real__ x, &sin2rx, &cos2rx); - - den = cos2rx + __ieee754_coshl (2.0 * __imag__ x); + /* tan(x+iy) = (sin(2x) + i*sinh(2y))/(cos(2x) + cosh(2y)) + = (sin(x)*cos(x) + i*sinh(y)*cosh(y)/(cos(x)^2 + sinh(y)^2). */ + __sincosl (__real__ x, &sinrx, &cosrx); - if (den == 0.0) + if (fabsl (__imag__ x) > t) { - __complex__ long double ez = __cexpl (1.0i * x); - __complex__ long double emz = __cexpl (-1.0i * x); + /* Avoid intermediate overflow when the real part of the + result may be subnormal. Ignoring negligible terms, the + imaginary part is +/- 1, the real part is + sin(x)*cos(x)/sinh(y)^2 = 4*sin(x)*cos(x)/exp(2y). */ + long double exp_2t = __ieee754_expl (2 * t); - res = (ez - emz) / (ez + emz) * -1.0i; + __imag__ res = __copysignl (1.0, __imag__ x); + __real__ res = 4 * sinrx * cosrx; + __imag__ x = fabsl (__imag__ x); + __imag__ x -= t; + __real__ res /= exp_2t; + if (__imag__ x > t) + { + /* Underflow (original imaginary part of x has absolute + value > 2t). */ + __real__ res /= exp_2t; + } + else + __real__ res /= __ieee754_expl (2 * __imag__ x); } else { - __real__ res = sin2rx / den; - __imag__ res = __ieee754_sinhl (2.0 * __imag__ x) / den; + long double sinhix = __ieee754_sinhl (__imag__ x); + long double coshix = __ieee754_coshl (__imag__ x); + + den = cosrx * cosrx + sinhix * sinhix; + __real__ res = sinrx * cosrx / den; + __imag__ res = sinhix * coshix / den; } } diff --git a/libc/math/w_ilogb.c b/libc/math/w_ilogb.c new file mode 100644 index 000000000..c87b517c5 --- /dev/null +++ b/libc/math/w_ilogb.c @@ -0,0 +1,42 @@ +/* Copyright (C) 2012 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Adhemerval Zanella <azanella@linux.vnet.ibm.com>, 2011. + + The GNU C 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. + + The GNU C 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 the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#include <math.h> +#include <errno.h> +#include <math_private.h> + +/* wrapper ilogb */ +int +__ilogb (double x) +{ + int r = __ieee754_ilogb (x); + if (__builtin_expect (r == FP_ILOGB0, 0) + || __builtin_expect (r == FP_ILOGBNAN, 0) + || __builtin_expect (r == INT_MAX, 0)) + { + __set_errno (EDOM); + feraiseexcept (FE_INVALID); + } + return r; +} + +weak_alias (__ilogb, ilogb) +#ifdef NO_LONG_DOUBLE +strong_alias (__ilogb, __ilogbl) +weak_alias (__ilogb, ilogbl) +#endif diff --git a/libc/math/w_ilogbf.c b/libc/math/w_ilogbf.c new file mode 100644 index 000000000..ae3574a75 --- /dev/null +++ b/libc/math/w_ilogbf.c @@ -0,0 +1,38 @@ +/* Copyright (C) 2012 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Adhemerval Zanella <azanella@linux.vnet.ibm.com>, 2011. + + The GNU C 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. + + The GNU C 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 the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#include <math.h> +#include <errno.h> +#include <math_private.h> + +/* wrapper ilogbf */ +int +__ilogbf (float x) +{ + int r = __ieee754_ilogbf (x); + if (__builtin_expect (r == FP_ILOGB0, 0) + || __builtin_expect (r == FP_ILOGBNAN, 0) + || __builtin_expect (r == INT_MAX, 0)) + { + __set_errno (EDOM); + feraiseexcept (FE_INVALID); + } + return r; +} + +weak_alias (__ilogbf, ilogbf) diff --git a/libc/math/w_ilogbl.c b/libc/math/w_ilogbl.c new file mode 100644 index 000000000..8c30caa48 --- /dev/null +++ b/libc/math/w_ilogbl.c @@ -0,0 +1,37 @@ +/* Copyright (C) 2012 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Adhemerval Zanella <azanella@linux.vnet.ibm.com>, 2011. + + The GNU C 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. + + The GNU C 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 the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#include <math.h> +#include <errno.h> +#include <math_private.h> + +/* wrapper ilogbl */ +int +__ilogbl (long double x) +{ + int r = __ieee754_ilogbl (x); + if (__builtin_expect (r == FP_ILOGB0, 0) + || __builtin_expect (r == FP_ILOGBNAN, 0) + || __builtin_expect (r == INT_MAX, 0)) + { + __set_errno (EDOM); + feraiseexcept (FE_INVALID); + } + return r; +} +weak_alias (__ilogbl, ilogbl) |