Skip to content

np.floor_divide(?, ml_dtypes.???(0.0)) return NaN but np.float16 returns Inf. #170

@apivovarov

Description

@apivovarov

If the second argument of np.floor_divide is 0.0, it returns different results depending on the type: np.dtypes returns Inf, while ml_dtypes returns NaN

Related test: ml_dtypes/tests/custom_float_test.py testBinaryUfunc. The test fails if y has 0.0 elements.

Manual run to confirm the difference in behavior

>>> np.floor_divide(ml_dtypes.float8_e4m3(1.0), ml_dtypes.float8_e4m3(0.0))
nan
>>> np.floor_divide(ml_dtypes.float8_e5m2(1.0), ml_dtypes.float8_e5m2(0.0))
nan
>>> np.floor_divide(ml_dtypes.bfloat16(1.0), ml_dtypes.bfloat16(0.0))
nan
>>> np.floor_divide(np.float16(1.0), np.float16(0.0))
np.float16(inf)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions