-
Notifications
You must be signed in to change notification settings - Fork 908
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
[BUG] cast from nan to Long and ints is inconsistent #4644
Comments
Sounds like expected behavior to me. https://wandbox.org/permlink/BgMPjI43UJ88WjVr Why is NaN casted to an int expected to be zero? |
Hmm... c={Float.NaN}.asInt() => d = {0} all I'm saying is shouldn't they both be consistent? Btw, neat tool thanks. I have added the int32 cast which isn't 0 in CPP. So I think this is a bug either way? |
I'm not following, casting a NaN to (Your link was the same as my previous one. You need to hit the "Share" button to generate a new link to the updated content.) |
I believe the confusion here lies in the context for the casting operation. I'm pretty sure @razajafri is coming from the JVM perspective, and the Java spec does specify that NaN casts to zero. That isn't the same as C/C++ casting semantics. IMO as long as libcudf is consistent wrt. C/C++ casting semantics then libcudf is correct. libcudf is not a Java library, it is a C++ library. If a Java application wants to implement Java casting semantics for NaN using libcudf then it needs to implement that logic at a higher level (e.g.: screen for NaN values and convert to 0.0 before casting). |
@jrhemstad at the risk of sounding really dumb here is what I am saying. cudf isn't consistent with itself when I run the following snippet
[DEBUG] NaN to int32: 0 Its casting NaN to a zero when cast to int32 column but -9223372036854775808 when cast to Int64. Whereas in cpp casting to int32 or int64 both result in a non-zero value. |
Okay, I agree the inconsistency definitely sounds like a bug. |
If I understand the code correctly, when the source and destination types are numeric, the cast is a simple call to static_cast, and casting from NaN is an undefined behavior in C++. I'll add a floating point specialization that checks for NaN and see if that suffices. |
I didn't realize the cast from Nan was undefined. That makes sense now. |
Based on this discussion it looks like we want to keep libcudf behavior consistent with C++. |
Yep! In summary, casting from NaN is undefined behavior in C++. Therefore, the user is required to first replace all NaN values before casting if a specified value is desired. |
Describe the bug
When casting float.NaN to long returns a negative number (-9223372036854775808)
Steps/Code to reproduce bug
Expected behavior
The above test should pass
Additional context
casting the value to integer returns the zero (0) which is the desired result
The text was updated successfully, but these errors were encountered: