Trait in prelude::ops auto-imported

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#

NameDescription
powReturns 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);
}

See also#

  • int
  • float
  • Add: The addition operator +.
  • Sub: The subtraction operator -.
  • Mul: The multiplication operator *.
  • Div: The division operator /.
  • Neg: The unary negation operator -x.
  • Rem: The remainder operator %.
↑ ↓ navigate ↵ open