Skip to content

proposal: math: implement generics for Abs function to include float32 #64871

@gonzalochief

Description

@gonzalochief

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions