{"record":{"id":"2a9dd09a9225427e","repo":"jax-ml/jax","slug":"nextafter-only-supports-float32-and-float64-but","errorCode":null,"errorMessage":"`nextafter` only supports float32 and float64, but got {x.dtype}","messagePattern":"`nextafter` only supports float32 and float64, but got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/pallas/utils.py","lineNumber":375,"sourceCode":"    return (x > 0).astype(x.dtype) - (x < 0).astype(x.dtype)\n\n  if jnp.issubdtype(x.dtype, jnp.floating):\n    out = (x > 0.).astype(x.dtype) - (x < 0.).astype(x.dtype)\n    return jnp.where(jnp.isnan(x), jnp.nan, out)\n\n  raise NotImplementedError(f\"sign_lowering_helper not implemented for {x.dtype}\")\n\n\n# based on https://github.com/openxla/xla/blob/a7a09d56c3599123f8148bbf3e44c9ebc04624b9/xla/mlir_hlo/mhlo/transforms/chlo_legalize_to_hlo/chlo_legalize_to_hlo.cc#L1339-L1422\ndef nextafter_lowering_helper(x, y):\n  if x.dtype != y.dtype:\n    raise ValueError(\n        \"The two inputs to `nextafter` must have the same dtype, but got\"\n        f\" {x.dtype} and {y.dtype}\"\n    )\n\n  if x.dtype not in (jnp.float32, jnp.float64):\n    raise ValueError(\n        f\"`nextafter` only supports float32 and float64, but got {x.dtype}\"\n    )\n\n  jnp_float, jnp_uint, np_float, np_uint, np_int = (\n      jnp.float32, jnp.uint32, np.float32, np.uint32, np.int32,\n  ) if x.dtype == jnp.float32 else (\n      jnp.float64, jnp.uint64, np.float64, np.uint64, np.int64,\n  )\n\n  bitwidth = dtypes.itemsize_bits(x.dtype)\n\n  x_as_int = x.view(jnp_uint)\n  y_as_int = y.view(jnp_uint)\n\n  # The result is NaN if either \"x\" or \"y\" are NaN.\n  nan_input = jnp.isnan(x) | jnp.isnan(y)\n  result_for_nan = jnp.full_like(x_as_int, np_float(np.nan).view(np_uint))\n","sourceCodeStart":357,"sourceCodeEnd":393,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/pallas/utils.py#L357-L393","documentation":"The Pallas Triton lowering of nextafter only implements the bit-twiddling algorithm for float32 and float64. Other dtypes (float16, bfloat16, integers) raise ValueError before lowering.","triggerScenarios":"Calling jnp.nextafter on bfloat16 or float16 tensors inside a pallas triton kernel.","commonSituations":"Half-precision kernels on modern accelerators where bfloat16 is the default dtype calling nextafter (e.g. for epsilon stepping in numerics).","solutions":["Cast to float32: jnp.nextafter(x.astype(jnp.float32), y.astype(jnp.float32)).astype(x.dtype)","Move the nextafter computation outside the pallas kernel"],"exampleFix":"# before\njnp.nextafter(x_bf16, y_bf16)\n# after\njnp.nextafter(x_bf16.astype(jnp.float32), y_bf16.astype(jnp.float32)).astype(jnp.bfloat16)","handlingStrategy":"validation","validationCode":"assert x.dtype in (jnp.float32, jnp.float64)\nx32, y32 = x.astype(jnp.float32), y.astype(jnp.float32)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Compute nextafter in float32 inside pallas kernels"],"tags":["jax","pallas","triton","dtype","nextafter"],"backgroundTag":"unsupported-dtype","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}