Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C++] Can divide (optionally?) return Inf when dividing by integer 0? #29427

Closed
asfimport opened this issue Aug 30, 2021 · 7 comments
Closed

Comments

@asfimport
Copy link

asfimport commented Aug 30, 2021

See also ARROW-13800. In R, both integer and float division by 0 results in Inf. Maybe that only makes sense because of how R finesses the difference between integer and float. But it would be nice if there were a way to achieve this behavior instead of failing with an error. (Or maybe that's the behavior we support: if you get an error, cast to float and retry?)

Reporter: Neal Richardson / @nealrichardson

Related issues:

Note: This issue was originally created as ARROW-13801. Please see the migration documentation for further details.

@asfimport
Copy link
Author

Eduardo Ponce / @edponce:
Here is my opinion for adding an option to control behavior of divide-by-zero.

@asfimport
Copy link
Author

Antoine Pitrou / @pitrou:
Our integer division returns an integer, so that's not possible. You can cast to float first if you want to get a float result.

@asfimport
Copy link
Author

Joris Van den Bossche / @jorisvandenbossche:
I suppose that's also what R should (can?) do: cast to float first so you can get Inf? (without needing changes on the C++ side)

Note that 0/0 will then give NaN. I don't know the details of R integers, but can they also contain NaN?

@asfimport
Copy link
Author

Neal Richardson / @nealrichardson:
In both cases in R, you get promoted to double so you can hold Inf or NaN

@asfimport
Copy link
Author

Joris Van den Bossche / @jorisvandenbossche:
But if division of integers always give double in R, you can also do this cast to float before dividing instead of setting an option in the division kernel to get this behaviour? And if this is done in the R bindings, the R user sees the expected behaviour for float.

BTW, also in pandas/numpy, division of integers results in float typed array.

@asfimport
Copy link
Author

Neal Richardson / @nealrichardson:
I guess that's true, it turns out that even non-zero division of integers results in a double (by "both cases" I meant 1L/0L and 0L/0L but this is also true for 2L/1L), and if you want an integer you do integer division (a different operator in R).

I'll rewrite the issue to change how R handles / on integer

@asfimport
Copy link
Author

Neal Richardson / @nealrichardson:
Actually I'll close this and handle it in the divide_checked issue I made right before this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant