jax icon indicating copy to clipboard operation
jax copied to clipboard

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

Open jayzuccarelli opened this issue 2 months ago • 1 comments

Description

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.

jayzuccarelli avatar Sep 29 '26 15:09 jayzuccarelli

#38651

jakevdp avatar Sep 29 '26 16:09 jakevdp