Pow
trait Pow<T>
Source: compiler/src/builtin_docs/prelude/ops.hy The exponentiation operator **.
a ** b on a type with a Pow instance calls pow(a, b). int and
float have builtin instances. ** is right-associative
(2 ** 3 ** 2 is 512). For int a negative exponent panics with
negative exponent and a result that does not fit panics with
integer overflow.
Required methods#
| Name | Description |
|---|---|
pow | Returns a raised to the power b. |
Examples#
use tests::assert;
class Gain {
pub g: int,
}
impl Pow for Gain {
pub fn pow(Gain a, Gain b) -> Gain {
return new Gain(a.g ** b.g);
}
}
fn main() {
let p = new Gain(3) ** new Gain(2);
assert!(p.g == 9);
assert!(2 ** 10 == 1024);
}