Skip to content

operator overloading for a better decimal implementation #19770

Closed
@maj-o

Description

@maj-o

It would be GREAT to have operator overloading like this:

operator (a,b MyType) + (result MyType) {
result = a.Add(b) // just to show what it would do
}


This can be used for instance a native or packaged Go decimal type.

res := a + b * (c / d)

is much more readable then

res := a.Add(b.Mult(c.Div(d)))

decimals are hardly needed !
But decimals without operators are unreadable. I can also think of other types like vectors, points, maps and other types like floats or even new types like Number where it also would be great to be able to implement operators. Operators should only be daclarable in the same package or file in which the significant type is declared - so, not overridable.

If somebody wants a comfortable and precise Number type and does not care about performance, this would be easy.

Please, think about it.

Regards,
maj-o

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions