"""Reproduce: scipy.special.nctdtr / scipy.stats.nct.cdf return nan in the far lower tail.

Submitted as an additional reproducer to https://github.com/scipy/scipy/issues/25470
Run: python reproduce.py
"""
import platform
import numpy
import scipy
from scipy import special, stats

CASES = [(3, 10, -4.0), (5, 10, -4.0), (5, 10, -2.0), (30, 6, -4.0), (100, 6, -4.0), (4, 12.25, -2.776)]
print("SciPy", scipy.__version__, "| NumPy", numpy.__version__, "| Python", platform.python_version(), "|", platform.platform())
for df, nc, x in CASES:
    print(f"df={df:<4} nc={nc:<6} x={x:<7} nctdtr={special.nctdtr(df, nc, x)!r:<26} nct.cdf={stats.nct.cdf(x, df, nc)!r}")

# Practical consequence: two-sided power of a t-test with df = 4 and noncentrality ~12.25
df, nc = 4, 12.247448713915890
crit = stats.t.ppf(0.975, df)
print("two-sided power =", stats.nct.sf(crit, df, nc) + stats.nct.cdf(-crit, df, nc))
