#41102·jax

jnp.modf returns nan as the fractional part for +/-inf (numpy returns +/-0)

Author: jayzuccarelliCreated Sep 29, 2026Updated Sep 29, 2026
Labelsbug

Description

python
import jax.numpy as jnp, numpy as np
x = [-0.5, np.inf, -np.inf, 2.5]
jnp.modf(jnp.array(x, jnp.float32))[0]   # [-0.5, nan, nan, 0.5]
np.modf(np.array(x, np.float32))[0]      # [-0.5, 0., -0., 0.5]

jax 0.11.2, CPU, with and without x64. The fractional part is computed as x - whole, so inf - inf gives nan. Returning copysign(0, x) where x is inf would match numpy. Happy to send the one-line fix with a test.

System info (python version, jaxlib version, accelerator, etc.)

jax 0.11.2, CPU, with and without x64. The fractional part is computed as x - whole, so inf - inf gives nan. Returning copysign(0, x) where x is inf would match numpy. Happy to send the one-line fix with a test.