jorisvandenbossche commented on a change in pull request #10016:
URL: https://github.com/apache/arrow/pull/10016#discussion_r613842949



##########
File path: cpp/src/arrow/compute/kernels/scalar_arithmetic.cc
##########
@@ -233,6 +235,43 @@ struct DivideChecked {
   }
 };
 
+struct Negate {
+  template <typename T, typename Arg0>
+  // NOTE [EPM]: Discuss on 0 vs. -0.
+  static constexpr enable_if_floating_point<T> Call(KernelContext*, Arg0 arg) {
+    return -arg;
+  }
+
+  // NOTE [EPM]: How to handle unsigned integers?
+  //  * Promote to signed?
+  //  * State that unsigned numbers are not supported (i.e., undefined 
behavior)?
+  //  * Use C++ integral conversions (e.g., Negate(-128) = -128)?

Review comment:
       For reference, numpy preserves the dtype for unsigned integers:
   
   ```
   In [14]: arr = np.array([0,  255], dtype="uint8")
   
   In [15]: -arr
   Out[15]: array([0, 1], dtype=uint8)
   
   In [16]: np.negative(arr)
   Out[16]: array([0, 1], dtype=uint8)
   ```
   
   (not sure that's very useful, though)




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to