Trait in prelude::ops auto-imported

Mul

trait Mul<T>
Source: compiler/src/builtin_docs/prelude/ops.hy

The multiplication operator *.

a * b on a type with a Mul instance calls mul(a, b). int and float have builtin instances. On Matrix values * is matrix multiplication.

Required methods#

NameDescription
mulReturns a * b.

Examples#

use tests::assert;
class V2 {
    pub x: int,
    pub y: int,
}

impl Mul for V2 {
    pub fn mul(V2 a, V2 b) -> V2 {
        return new V2(a.x * b.x, a.y * b.y);
    }
}

fn main() {
    let p = new V2(2, 3) * new V2(4, 5);
    assert!(p.x == 8);
    assert!(p.y == 15);
}

See also#

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