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

Function _arange_safe_ceil_to_intp

numpy/core/src/multiarray/ctors.c:2916–2935  ·  view source on GitHub ↗

* Like ceil(value), but check for overflow. * * Return 0 on success, -1 on failure. In case of failure, set a PyExc_Overflow * exception */

Source from the content-addressed store, hash-verified

2914 * exception
2915 */
2916static npy_intp
2917_arange_safe_ceil_to_intp(double value)
2918{
2919 double ivalue;
2920
2921 ivalue = npy_ceil(value);
2922 /* condition inverted to handle NaN */
2923 if (npy_isnan(ivalue)) {
2924 PyErr_SetString(PyExc_ValueError,
2925 "arange: cannot compute length");
2926 return -1;
2927 }
2928 if (!((double)NPY_MIN_INTP <= ivalue && ivalue <= (double)NPY_MAX_INTP)) {
2929 PyErr_SetString(PyExc_OverflowError,
2930 "arange: overflow while computing length");
2931 return -1;
2932 }
2933
2934 return (npy_intp)ivalue;
2935}
2936
2937
2938/*NUMPY_API

Callers 2

PyArray_ArangeFunction · 0.85
_calc_lengthFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected