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

Skip to content

Commit 742305d

Browse files
committed
revert back to yesterday's version of detecting nan. Added inf detection.
svn path=/trunk/matplotlib/; revision=3522
1 parent aef2600 commit 742305d

3 files changed

Lines changed: 49 additions & 7 deletions

File tree

src/MPL_isnan.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// These definitions modified from numarray's Include/numarray/nummacro.h
2+
3+
// The "64" in this code refers to double precision floating point numbers.
4+
5+
#if defined(SIZEOF_VOID_P)
6+
#if SIZEOF_VOID_P == 8
7+
#define MPL_LP64 1
8+
#else
9+
#define MPL_LP64 0
10+
#endif
11+
#else
12+
#define MPL_LP64 0
13+
#endif
14+
15+
#if MPL_LP64
16+
typedef long int MPL_Int64;
17+
#else /* 32-bit platforms */
18+
#if defined(_MSC_VER)
19+
typedef __int64 MPL_Int64;
20+
#else
21+
typedef long long MPL_Int64;
22+
#endif
23+
#endif
24+
25+
#if !defined(MPL_isnan64)
26+
#define MPL_U64(u) (* (MPL_Int64 *) &(u) )
27+
28+
#if !defined(_MSC_VER)
29+
#define MPL_isnan64(u) \
30+
( (( MPL_U64(u) & 0x7ff0000000000000LL) == 0x7ff0000000000000LL) && ((MPL_U64(u) & 0x000fffffffffffffLL) != 0)) ? 1:0
31+
#else
32+
#define MPL_isnan64(u) \
33+
( (( MPL_U64(u) & 0x7ff0000000000000i64) == 0x7ff0000000000000i64) && ((MPL_U64(u) & 0x000fffffffffffffi64) != 0)) ? 1:0
34+
#endif
35+
36+
#endif /* MPL_isnan64 */
37+
38+
#if !defined(MPL_isinf64)
39+
// This beauty from translated from numpy.
40+
#define MPL_isinf64(x) (!MPL_isnan64((x)) && MPL_isnan64((x)-(x)))
41+
#endif

src/_backend_agg.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "mplutils.h"
2626

2727
#include "swig_runtime.h"
28+
#include "MPL_isnan.h"
2829

2930
#define PY_ARRAY_TYPES_PREFIX NumPy
3031
#include "numpy/arrayobject.h"
@@ -1584,7 +1585,7 @@ RendererAgg::draw_lines(const Py::Tuple& args) {
15841585
moveto = true;
15851586
continue;
15861587
}
1587-
if (std::isnan(thisx) || std::isnan(thisy)) {
1588+
if (MPL_isnan64(thisx) || MPL_isnan64(thisy)) {
15881589
moveto = true;
15891590
continue;
15901591
}

src/_transforms.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#include <functional>
22
#include <limits>
3-
#include <cmath>
43

54
#include <math.h>
65

76
#include "_transforms.h"
87
#include "mplutils.h"
98

109
#include "numpy/arrayobject.h"
10+
#include "MPL_isnan.h"
1111

1212
Value::~Value() {
1313
_VERBOSE("Value::~Value");
@@ -473,7 +473,7 @@ Bbox::update(const Py::Tuple &args) {
473473
tup = xys[i];
474474
double x = Py::Float(tup[0]);
475475
double y = Py::Float(tup[1]);
476-
if (std::isnan(x) || std::isnan(y)) continue;
476+
if (MPL_isnan64(x) || MPL_isnan64(y)) continue;
477477
_posx.update(x);
478478
_posy.update(y);
479479
if (x<minx) minx=x;
@@ -538,7 +538,7 @@ Bbox::update_numerix_xy(const Py::Tuple &args) {
538538
for (size_t i=0; i< Nxy; ++i) {
539539
thisx = *(double *)(xyin->data + i*xyin->strides[0]);
540540
thisy = *(double *)(xyin->data + i*xyin->strides[0] + xyin->strides[1]);
541-
if (std::isnan(thisx) || std::isnan(thisy)) continue;
541+
if (MPL_isnan64(thisx) || MPL_isnan64(thisy)) continue;
542542
_posx.update(thisx);
543543
_posy.update(thisy);
544544
if (thisx<minx) minx=thisx;
@@ -612,7 +612,7 @@ Bbox::update_numerix(const Py::Tuple &args) {
612612
for (size_t i=0; i< Nx; ++i) {
613613
thisx = *(double *)(x->data + i*x->strides[0]);
614614
thisy = *(double *)(y->data + i*y->strides[0]);
615-
if (std::isnan(thisx) || std::isnan(thisy)) continue;
615+
if (MPL_isnan64(thisx) || MPL_isnan64(thisy)) continue;
616616
_posx.update(thisx);
617617
_posy.update(thisy);
618618
if (thisx<minx) minx=thisx;
@@ -1254,12 +1254,12 @@ Transformation::nonlinear_only_numerix(const Py::Tuple & args, const Py::Dict &k
12541254

12551255
double thisx = *(double *)(x->data + i*x->strides[0]);
12561256
double thisy = *(double *)(y->data + i*y->strides[0]);
1257-
if (std::isnan(thisx) || std::isnan(thisy)) {
1257+
if (MPL_isnan64(thisx) || MPL_isnan64(thisy)) {
12581258
if (returnMask) {
12591259
*(unsigned char *)(retmask->data + i*retmask->strides[0]) = 0;
12601260
}
12611261
double MPLnan; // don't require C99 math features - find our own nan
1262-
if (std::isnan(thisx)) {
1262+
if (MPL_isnan64(thisx)) {
12631263
MPLnan=thisx;
12641264
} else {
12651265
MPLnan=thisy;

0 commit comments

Comments
 (0)