divide(Object, Object) with (NaN, 0) does not return NaN
Description
Would expect both of these to return NaN but first does not:
Cause: Here we are dividing a double by a long. In the first case, this is parsed as divide(Object, long) which then calls divide(Object, Object), which throws ArithmeticException if the second arg is 0 (regardless of the first arg).
In the second case it's parsed as divide(double, long) which just relies on Java to properly upcast the primitive long to a double to do the divide.
Note that making this call with 2 doubles does return NaN:
or type hinting x to a double works as well:
Proposed: Add checks in divide(Object, Object) to check whether x is NaN and instead return NaN.
Patch: clj-1371-2.patch Prescreened by: Alex Miller
Environment
None
Attachments
2
Activity
Pavlos Vinieratos
October 14, 2016 at 11:06 AM
fix for this issue
Alex Miller
March 7, 2014 at 3:27 PM
Ah, I see the question now.
Here we are dividing a double by a long. In the first case, this is parsed as divide(Object, long) which then calls divide(Object, Object), which throws ArithmeticException if the second arg is 0 (regardless of the first arg).
In the second case it's parsed as divide(double, long) which just relies on Java to properly upcast the primitive long to a double to do the divide.
Note that making this call with 2 doubles does return NaN:
or type hinting x to a double works as well:
I think one option to "fix" this behavior would be to add checks in divide(Object, Object) to check whether x is NaN and instead return NaN.
import
March 7, 2014 at 1:54 PM
Comment made by: yongqli
But in the first example it produces an ArithmeticException.
Would expect both of these to return NaN but first does not:
Cause: Here we are dividing a double by a long. In the first case, this is parsed as divide(Object, long) which then calls divide(Object, Object), which throws ArithmeticException if the second arg is 0 (regardless of the first arg).
In the second case it's parsed as divide(double, long) which just relies on Java to properly upcast the primitive long to a double to do the divide.
Note that making this call with 2 doubles does return NaN:
or type hinting x to a double works as well:
Proposed: Add checks in divide(Object, Object) to check whether x is NaN and instead return NaN.
Patch: clj-1371-2.patch
Prescreened by: Alex Miller