V: Allow overloading of ^ and % operators

Created on 26 Jun 2019  路  7Comments  路  Source: vlang/v

Feature Request

All 7 comments

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

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

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.

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

@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.

There's % overloading now

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jtkirkpatrick picture jtkirkpatrick  路  3Comments

taojy123 picture taojy123  路  3Comments

ArcDrake picture ArcDrake  路  3Comments

lobotony picture lobotony  路  3Comments

radare picture radare  路  3Comments