是否可以定义一个通用的求幂运算符,其接口如下:
> 10^3 // 1000
> 2.71^2 // 7.3441
> 3.14^(-3.14) // 0.027..
According to the docs it's possible to extend classes with infix functions:
// Define extension to Int
infix fun Int.exp(exponent: Int): Int {
...
}
但他们不允许像^
这样的符号