Monday, May 20, 2024
HomeGolangMath package deal and generics - Getting Assist

Math package deal and generics – Getting Assist


Why has the math package deal (and perhaps others) not been rewritten utilizing generics? It has been years now, since we had generics, and I nonetheless must convert backwards and forwards between float64 and float32/intXX when utilizing the math.Abs() perform, for instance.

It looks like math.Abs() ought to settle for all numeric sorts, and all trigonomical capabilities, like math.Sin() and so forth, ought to settle for no less than float64 and float32.

Is there a cause for this, that I don’t perceive?



1 Like

FYI: math: implement Abs perform utilizing generics by felipe88alves · Pull Request #55931 · golang/go · GitHub

Fascinating, however why wasn’t it merged in 2022? What does it imply when Rob Pike says: Patch Set 1: Maintain+1?

And it additionally fastened solely the math.Abs() perform…

Observe the hyperlinks to the opposite discussions.

Okay, thanks, now I perceive why it was rejected, I nonetheless suppose although {that a} new package deal must be created as an alternative, for instance math2, that helps generics. Backwards compatibility can be stored since math nonetheless exists…

Yeah, I don’t disagree that it’d be good, I don’t know that creating that form of precedent in stdlib is the most effective answer, however as per that dialogue, I don’t know that there’s any good answer. I’m undecided what stage of motivation there’s to resolve it in stdlib contemplating how simple it’s to have your personal workaround/wrapper in your personal tasks.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments