Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
9e7be8c
BUG: Overflow in tan and tanh for large complex values
ewmoore Feb 22, 2013
f442ead
STY: npymath: tabs -> spaces, long lines
ewmoore Mar 1, 2013
d62c590
ENH: Check for, and use all C99 complex functions if available
ewmoore Mar 6, 2013
af5ff55
ENH: npymath: Use a better complex division algorithm.
ewmoore Mar 8, 2013
e6b99c9
MAINT: umath: generate the ldexp and frexp ufuncs like all the others.
ewmoore Mar 9, 2013
0fdaa54
MAINT: umath/npymath: Add ldexp and frexp to npymath
ewmoore Mar 9, 2013
2d33f7c
ENH: npymath: handle clog edge cases more carefully.
ewmoore Mar 10, 2013
50d6720
ENH: evaluate c99 complex funcs at build time
ewmoore Oct 1, 2013
d504ea1
BUG: NPY_LOGE2 is log(2)
ewmoore Oct 2, 2013
5362b35
BUG: Test aginst +/-TANH_HUGE
ewmoore Oct 2, 2013
e61e74f
TST: check for tanh(1000+0j) == 1 + 0j etc.
ewmoore Oct 2, 2013
852cd10
BUG: Fix up some corner cases in npy_cexp
ewmoore Oct 2, 2013
0f57b42
MAINT: remove debug print statement
ewmoore Oct 2, 2013
eb06557
MAINT: fix two typos in test_c99complex.c
ewmoore Oct 4, 2013
77705ab
ENH: Be more careful with large real parts in npy_cexp
ewmoore Oct 4, 2013
e574e29
ENH: Import the ccosh/ccos implementation from FreeBSD
ewmoore Oct 4, 2013
3710481
ENH: Import the csinh/csin implementation from FreeBSD
ewmoore Oct 4, 2013
a837853
ENH: Import the catanh/catan implemenation from FreeBSD
ewmoore Oct 9, 2013
36e0d8b
BUG: printf requires a literal for the first argument.
ewmoore Oct 9, 2013
330b54a
BUG: Py3 '-2j' is (NZERO - 2j) causes test failures
ewmoore Oct 9, 2013
def6327
ENH: Import the cacos,casin,cacosh,casinh implemenation from FreeBSD
ewmoore Oct 10, 2013
c8f13ee
TST: Enable signed zero branch cut tests
ewmoore Oct 10, 2013
eab5228
BUG: fix cpow tests to match what npy_cpow does.
ewmoore Oct 10, 2013
2b5f1ad
STY: long lines, whitespace
ewmoore Oct 10, 2013
1fb1b74
MAINT: remove gccisms and unbreak MSVC build.
ewmoore Oct 11, 2013
be42cae
MAINT: fix ldexp/frexp changes to compile with MSVC.
ewmoore Oct 11, 2013
ac075b2
MAINT: npy_a(exp,log,sqrt,fabs) don't really exist.
ewmoore Oct 15, 2013
79afefd
ENH: Run the test_c99complex.c tests with the test suite too.
ewmoore Oct 16, 2013
cfe9fcc
BUG: Fix tests to compile under MSVC
ewmoore Oct 21, 2013
cbc97fa
MAINT: pick sunmath.h from npy_math.h
ewmoore Oct 21, 2013
863d97d
MAINT: Update note about FreeBSD.
ewmoore Oct 22, 2013
2348023
MAINT: make sure npy_math builds when long double is double double
ewmoore Oct 24, 2013
5771dae
MAINT: move npy_(get,clear)_floatstatus() to their own file.
ewmoore Nov 7, 2013
566c15e
BUG Use the floating point status functions in build time tests
ewmoore Nov 7, 2013
503047b
MAINT: move test_c99complex.c to npymath
ewmoore Nov 7, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ENH: npymath: handle clog edge cases more carefully.
  • Loading branch information
ewmoore committed Feb 26, 2014
commit 2d33f7c8ecedead77a9b823c560f3a94a0131303
67 changes: 66 additions & 1 deletion numpy/core/src/npymath/npy_math_complex.c.src
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/*
* vim: syntax=c
*
* Implement some C99-compatible complex math functions
*
* Most of the code is taken from the msun library in FreeBSD (HEAD @ 30th June
Expand Down Expand Up @@ -37,6 +39,8 @@
* #c = f, , l#
* #C = F, , L#
* #TMAX = FLT_MAX, DBL_MAX, LDBL_MAX#
* #TMIN = FLT_MIN, DBL_MIN, LDBL_MIN#
* #TMANT_DIG = FLT_MANT_DIG, DBL_MANT_DIG, LDBL_MANT_DIG#
* #precision = 1, 2, 3#
*/

Expand Down Expand Up @@ -205,9 +209,70 @@ static NPY_INLINE @ctype@ cmuli@c@(@ctype@ a)
#endif

#ifndef HAVE_CLOG@C@
/* algorithm from cpython, rev. d86f5686cef9
*
* The usual formula for the real part is log(hypot(z.real, z.imag)).
* There are four situations where this formula is potentially
* problematic:
*
* (1) the absolute value of z is subnormal. Then hypot is subnormal,
* so has fewer than the usual number of bits of accuracy, hence may
* have large relative error. This then gives a large absolute error
* in the log. This can be solved by rescaling z by a suitable power
* of 2.
*
* (2) the absolute value of z is greater than DBL_MAX (e.g. when both
* z.real and z.imag are within a factor of 1/sqrt(2) of DBL_MAX)
* Again, rescaling solves this.
*
* (3) the absolute value of z is close to 1. In this case it's
* difficult to achieve good accuracy, at least in part because a
* change of 1ulp in the real or imaginary part of z can result in a
* change of billions of ulps in the correctly rounded answer.
*
* (4) z = 0. The simplest thing to do here is to call the
* floating-point log with an argument of 0, and let its behaviour
* (returning -infinity, signaling a floating-point exception, setting
* errno, or whatever) determine that of c_log. So the usual formula
* is fine here.
*/
@ctype@ npy_clog@c@(@ctype@ z)
{
return npy_cpack@c@(npy_log@c@ (npy_cabs@c@ (z)), npy_carg@c@ (z));
@type@ ax = npy_fabs@c@(npy_creal@c@(z));
@type@ ay = npy_fabs@c@(npy_cimag@c@(z));
@type@ rr, ri;

if (ax > @TMAX@/4 || ay > @TMAX@/4) {
rr = npy_log@c@(npy_hypot@c@(ax/2, ay/2)) + NPY_LOGE2@c@;
}
else if (ax < @TMIN@ && ay < @TMIN@) {
if (ax > 0 || ay > 0) {
/* catch cases where hypot(ax, ay) is subnormal */
rr = npy_log@c@(npy_hypot@c@(npy_ldexp@c@(ax, @TMANT_DIG@),
npy_ldexp@c@(ay, @TMANT_DIG@))) - @TMANT_DIG@*NPY_LOGE2@c@;
}
else {
/* log(+/-0 +/- 0i) */
/* raise divide-by-zero floating point exception */
rr = -1.0@c@ / npy_creal@c@(z);
rr = npy_copysign@c@(rr, -1);
ri = npy_carg@c@(z);
return npy_cpack@c@(rr, ri);
}
}
else {
@type@ h = npy_hypot@c@(ax, ay);
if (0.71 <= h && h <= 1.73) {
@type@ am = ax > ay ? ax : ay; /* max(ax, ay) */
@type@ an = ax > ay ? ay : ax; /* min(ax, ay) */
rr = npy_log1p@c@((am-1)*(am+1)+an*an)/2;
}
else {
rr = npy_log@c@(h);
}
}
ri = npy_carg@c@(z);
return npy_cpack@c@(rr, ri);
}
#endif

Expand Down