<p dir="auto">When running <code class="notranslate">fourier_uniform</code> from SciPy's <code class="notranslate">ndimage</code>, seem to be getting an inaccurate result with SciPy 1.0.0+. The problem is not present in SciPy pre-1.0.0 (e.g. 0.19.1).</p>
<h3 dir="auto">Reproducing code example:</h3>
<p dir="auto">From SciPy 0.19.1:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="In [1]: import numpy as np

In [2]: import scipy.ndimage as spimg

In [3]: spimg.fourier_uniform(np.arange(5, dtype=float), 1)
Out[3]: array([ 0.        ,  0.93548928,  1.51365346,  2.27048019,  3.74195714])"><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">1</span>]: <span class="pl-s1">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>

<span class="pl-v">In</span> [<span class="pl-c1">2</span>]: <span class="pl-s1">import</span> <span class="pl-s1">scipy</span>.<span class="pl-s1">ndimage</span> <span class="pl-k">as</span> <span class="pl-s1">spimg</span>

<span class="pl-v">In</span> [<span class="pl-c1">3</span>]: <span class="pl-s1">spimg</span>.<span class="pl-en">fourier_uniform</span>(<span class="pl-s1">np</span>.<span class="pl-en">arange</span>(<span class="pl-c1">5</span>, <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s1">float</span>), <span class="pl-c1">1</span>)
<span class="pl-v">Out</span>[<span class="pl-c1">3</span>]: <span class="pl-en">array</span>([ <span class="pl-c1">0.</span>        ,  <span class="pl-c1">0.93548928</span>,  <span class="pl-c1">1.51365346</span>,  <span class="pl-c1">2.27048019</span>,  <span class="pl-c1">3.74195714</span>])</pre></div>
<p dir="auto">From SciPy 1.1.0:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="In [1]: import numpy as np

In [2]: import scipy.ndimage as spimg

In [3]: spimg.fourier_uniform(np.arange(5, dtype=float), 1)
Out[3]: 
array([0.00000000e+000, 5.25819693e-315, 5.28483274e-315, 5.31059453e-315,
       5.34108739e-315])"><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">1</span>]: <span class="pl-s1">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>

<span class="pl-v">In</span> [<span class="pl-c1">2</span>]: <span class="pl-s1">import</span> <span class="pl-s1">scipy</span>.<span class="pl-s1">ndimage</span> <span class="pl-k">as</span> <span class="pl-s1">spimg</span>

<span class="pl-v">In</span> [<span class="pl-c1">3</span>]: <span class="pl-s1">spimg</span>.<span class="pl-en">fourier_uniform</span>(<span class="pl-s1">np</span>.<span class="pl-en">arange</span>(<span class="pl-c1">5</span>, <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s1">float</span>), <span class="pl-c1">1</span>)
<span class="pl-v">Out</span>[<span class="pl-c1">3</span>]: 
<span class="pl-en">array</span>([<span class="pl-c1">0.00000000e+000</span>, <span class="pl-c1">5.25819693e-315</span>, <span class="pl-c1">5.28483274e-315</span>, <span class="pl-c1">5.31059453e-315</span>,
       <span class="pl-c1">5.34108739e-315</span>])</pre></div>
<h3 dir="auto">Scipy/Numpy/Python version information:</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="1.1.0 1.15.1 sys.version_info(major=3, minor=6, micro=6, releaselevel='final', serial=0)"><pre class="notranslate"><code class="notranslate">1.1.0 1.15.1 sys.version_info(major=3, minor=6, micro=6, releaselevel='final', serial=0)
</code></pre></div>
<p dir="auto"><code class="notranslate">bdtr</code> returns <code class="notranslate">nan</code> whenever <code class="notranslate">n</code> &gt; 2**31 - 1.  For example,</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In [14]: import scipy

In [15]: scipy.__version__
Out[15]: '1.2.0.dev0+dfc9a9c'

In [16]: from scipy.special import bdtr

In [17]: bdtr([0, 2**30, 2**31-1], 2**31, 0.5)
Out[17]: array([nan, nan, nan])"><pre class="notranslate"><code class="notranslate">In [14]: import scipy

In [15]: scipy.__version__
Out[15]: '1.2.0.dev0+dfc9a9c'

In [16]: from scipy.special import bdtr

In [17]: bdtr([0, 2**30, 2**31-1], 2**31, 0.5)
Out[17]: array([nan, nan, nan])
</code></pre></div>
<p dir="auto">If I use <code class="notranslate">n = 2**31-1</code>, the values are not <code class="notranslate">nan</code>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In [18]: bdtr([0, 2**30, 2**31-1], 2**31-1, 0.5)
Out[18]: array([0.       , 0.8891082, 1.       ])"><pre class="notranslate"><code class="notranslate">In [18]: bdtr([0, 2**30, 2**31-1], 2**31-1, 0.5)
Out[18]: array([0.       , 0.8891082, 1.       ])
</code></pre></div>
<p dir="auto">This is on a 64 bit system.</p>
<p dir="auto">This looks related to <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="117462073" data-permission-text="Title is private" data-url="https://github.com/scipy/scipy/issues/5503" data-hovercard-type="issue" data-hovercard-url="/scipy/scipy/issues/5503/hovercard" href="https://github.com/scipy/scipy/issues/5503">#5503</a>, but I don't know if it is a duplicate.</p>
<p dir="auto"><code class="notranslate">bdtr(k, n, p)</code> calls <code class="notranslate">incbet(n - k, k+1, 1.0-p)</code>, so the underlying problem is probably in <code class="notranslate">incbet</code>.  Note that the first two arguments of <code class="notranslate">incbet</code> are <code class="notranslate">double</code>, not integers.</p>
<p dir="auto">This problem was reported as <a href="https://stackoverflow.com/questions/53199088/scipy-stats-binom-cdf-returns-nan" rel="nofollow">a question on stackoverflow</a>, where it appeared as a problem with <code class="notranslate">scipy.stats.binom.cdf</code>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In [26]: from scipy.stats import binom

In [27]: binom.cdf([0, 2**30, 2**31-1], 2**31, 0.5)
/Users/warren/miniconda36/lib/python3.6/site-packages/scipy-1.2.0.dev0+dfc9a9c-py3.6-macosx-10.7-x86_64.egg/scipy/stats/_discrete_distns.py:60: RuntimeWarning: floating point number truncated to an integer
  vals = special.bdtr(k, n, p)
Out[27]: array([nan, nan, nan])"><pre class="notranslate"><code class="notranslate">In [26]: from scipy.stats import binom

In [27]: binom.cdf([0, 2**30, 2**31-1], 2**31, 0.5)
/Users/warren/miniconda36/lib/python3.6/site-packages/scipy-1.2.0.dev0+dfc9a9c-py3.6-macosx-10.7-x86_64.egg/scipy/stats/_discrete_distns.py:60: RuntimeWarning: floating point number truncated to an integer
  vals = special.bdtr(k, n, p)
Out[27]: array([nan, nan, nan])
</code></pre></div>