MCPcopy Create free account
hub / github.com/numpy/numpy / _next

Function _next

numpy/core/src/npymath/ieee754.cpp:28–75  ·  view source on GitHub ↗

* FIXME: There is a lot of redundancy between _next* and npy_nextafter*. * refactor this at some point * * p >= 0, returnx x + nulp * p < 0, returnx x - nulp */

Source from the content-addressed store, hash-verified

26 * p < 0, returnx x - nulp
27 */
28static double
29_next(double x, int p)
30{
31 volatile double t;
32 npy_int32 hx, hy, ix;
33 npy_uint32 lx;
34
35 EXTRACT_WORDS(hx, lx, x);
36 ix = hx & 0x7fffffff; /* |x| */
37
38 if (((ix >= 0x7ff00000) && ((ix - 0x7ff00000) | lx) != 0)) /* x is nan */
39 return x;
40 if ((ix | lx) == 0) { /* x == 0 */
41 if (p >= 0) {
42 INSERT_WORDS(x, 0x0, 1); /* return +minsubnormal */
43 }
44 else {
45 INSERT_WORDS(x, 0x80000000, 1); /* return -minsubnormal */
46 }
47 t = x * x;
48 if (t == x)
49 return t;
50 else
51 return x; /* raise underflow flag */
52 }
53 if (p < 0) { /* x -= ulp */
54 if (lx == 0)
55 hx -= 1;
56 lx -= 1;
57 }
58 else { /* x += ulp */
59 lx += 1;
60 if (lx == 0)
61 hx += 1;
62 }
63 hy = hx & 0x7ff00000;
64 if (hy >= 0x7ff00000)
65 return x + x; /* overflow */
66 if (hy < 0x00100000) { /* underflow */
67 t = x * x;
68 if (t != x) { /* raise underflow flag */
69 INSERT_WORDS(x, hx, lx);
70 return x;
71 }
72 }
73 INSERT_WORDS(x, hx, lx);
74 return x;
75}
76
77static float
78_next(float x, int p)

Callers 1

_npy_spacingFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected