Skip to content

[C++][Compute] Add sign function kernels #28594

Closed

Description

@asfimport

Add the sign function to the compute kernels.

sign(X) =

  • 1 if X > 0
  • 0 if X = 0
  • -1 if X < 0

Reporter: Eduardo Ponce / @edponce
Assignee: Eduardo Ponce / @edponce

Related issues:

PRs and other links:

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

Activity

  1. asfimport commented on May 24, 2021

    @asfimport
    Author

    Eduardo Ponce / @edponce:
    IEEE 754 defines rules for +0.0 and -0.0, thus sign(+0.0) = 1 and sign(-0.0) = -1. On the other hand, integral zero results in sign(0) = 0. Is this behavior reasonable?

    This approach will result in different behavior for floating-point and integral operands.

    1. Floating-point sign(X) =
      -1 if X <= -0.0
      1 if X >= 0.0
    2. Integral sign(X) =
      -1 if X < 0
      0 if X = 0
      1 if X > 0
  2. asfimport commented on May 25, 2021

    @asfimport
    Author

    Ian Cook / @ianmcook:
    @edponce  I think sign(0.0) should return 0 regardless of the sign of the floating point zero, for two reasons: (a) This is what Python, R, all SQL engines, etc. do and therefore it is what users will expect. (b) There is little practical use in knowing the sign of a floating point zero value; this sign kernel will be more consistent and more useful in more ways if it always returns sign zero for value zero.

  3. asfimport commented on May 25, 2021

    @asfimport
    Author

    Eduardo Ponce / @edponce:
    Thanks for the feedback @ianmcook, I agree and will make this change.

  4. asfimport commented on May 25, 2021

    @asfimport
    Author

    Neal Richardson / @nealrichardson:
    I definitely have seen applications that rely on the sign of 0. We may want a FunctionOption for that--but we can also defer that until someone reports it, which as Ian suggests, may never happen.

  5. asfimport commented on Jul 15, 2021

    @asfimport
    Author

    Ben Kietzman / @bkietz:
    Issue resolved by pull request 10395
    #10395

  6. added this to the 5.0.0 milestone on Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions