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
proposal: builtin: add abs to get absolute value of numbers( integer and float pointers) #60623
Comments
I thought it might be more convenient to add an |
I think it's a good idea |
Note that you can write this function as If we do want to add this somewhere, I don't think the math package is the right place, as the math package is primarily for floating-point operations. And I definitely don't think that |
How about add a abs function as builtin. it calculate the absolute value of both integers and float pointer numbers. |
This proposal has been added to the active column of the proposals project |
If we were going to add a builtin abs, I would make it take a signed int and return the corresponding unsigned type, so that there are no cases where it can return a negative number. func Abs(int8)int8 cannot do anything useful with Abs(-128) for example. That said, abs comes up far less often than min and max and can easily be provided by third-party libraries for now. |
Based on the discussion above, this proposal seems like a likely decline. |
How would that work on an |
In int8, -(-128) is -128, so it would evaluate max(-128, -128) = -128. |
Same as the proposed abs function. |
No change in consensus, so declined. |
I proposal to add builtin functions abs.
for integer, it's logic like:
for float pointer it acts like math.Abs.
The text was updated successfully, but these errors were encountered: