Skip to content
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: math: implement generics for Abs function to include float32 #64871

Closed
gonzalochief opened this issue Dec 26, 2023 · 2 comments
Closed
Labels
Milestone

Comments

@gonzalochief
Copy link

Proposal Details

As a programmer i need to have an Abs(x) function that accepts both float64, and float32 bit, so i don't have to convert the number to float64, and then back to float32, which is the current experience using the standard math package.
The proposed implementation uses generics (Float type), and type switching to return the appropriate result using the corresponding 32 and 64 bit algorithm.
This implementation provides full backward compatibility, as it does not changes the current function call for float64 values, while allowing the use of the function for float32.
I already have a working implementation on my local machine for the proposed solution, and it works as stated. please advise if i can submit the code proposal.

What version of Go are you using (go version)? 1.21.4
What operating system and processor architecture are you using? MacOs and Linux
What did you do? The proposed implementation uses generics (Float type), and type switching to return the appropriate result using the corresponding 32 and 64 bit algorithm.
What did you expect to see? The code provides float64 and float32 values without modifying current function signature

@gopherbot gopherbot added this to the Proposal milestone Dec 26, 2023
@randall77
Copy link
Contributor

This implementation provides full backward compatibility

Can you do

    f := math.Abs

With your generic implementation? (Which makes f a func(float64)foat64.) Without that ability, it unfortunately isn't completely backward compatible.

@randall77
Copy link
Contributor

Closing as dup of #55929.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants