v icon indicating copy to clipboard operation
v copied to clipboard

Allow overloading of ^ and % operators

Open Undumendil opened this issue 7 years ago • 10 comments

Undumendil avatar Jun 26 '19 20:06 Undumendil

@Undumendil Examples/use cases would help make this more compelling :-D

elimisteve avatar Jun 27 '19 18:06 elimisteve

Here they are:

fn (a bigi) ^ (b bigi) { ... } // power
fn (a bigi) % (b bigi) { ... } // modulo
fn (a bin_data) ^ (b bin_data) { ... } // xor 
fn (a some_data) % (b some_data) { ... } // take a, reset everything defined in b (not literally), return

Undumendil avatar Jun 27 '19 19:06 Undumendil

Operator overloading should not be used to change the meaning of the operators. I agree that all numeric operators should be overloadable for all kinds of structs representing numerical data.

ntrel avatar Jun 29 '19 10:06 ntrel

Operator overloading is usually used to work with custom types but I can't see use cases where you would need overloaded ^ and %.

serkonda7 avatar May 24 '20 16:05 serkonda7

@Serkonda For a BigInteger type, that doesn't have a fixed maximum value. The use case is the same as for any fixed size integer.

ntrel avatar Jun 03 '20 07:06 ntrel

There's % overloading now

Delta456 avatar Jun 03 '20 08:06 Delta456

The ^ operator is already used for XOR, so I don't think it would be overloaded for power. Should this issue be closed now?

VinWare avatar Nov 30 '20 05:11 VinWare

^ won't available to overload so closing this.

Delta456 avatar Mar 12 '21 11:03 Delta456

The ^ operator is already used for XOR, so I don't think it would be overloaded for power

It shouldn't be overloaded for power, but it is useful for BigInteger bitwise XOR, just like with built-in integers. @Delta456 what was the reasoning for disallowing bitwise operator overloading?

ntrel avatar Mar 12 '21 13:03 ntrel

It has been said many times. Only +, -, *, /, % would be allowed as they are most used ones. Even @medvednikov agrees with it.

Delta456 avatar Mar 12 '21 13:03 Delta456