You can define your own operator as follows:
infix operator </> { associativity left } func </> (a: Int, b: Int) -> Int { return Int(floor(Double(a) / Double(b))) }
so you donβt have to enter this absurd expression. I suggest </> , but of course you can choose your own.
If you don't like creating statements, use it as a regular function:
func div (a: Int, b: Int) -> Int { return Int(floor(Double(a) / Double(b))) }
Finally, but personally I would not use, you can override the division operator :
func / (a: Int, b: Int) -> Int { return Int(floor(Double(a) / Double(b))) }
and in this case it will be applied to all units - should be aware of side effects, although
Antonio
source share