[Rust] Converting Numbers with as

fn multiply(x: i64, y: u8) -> i64 {
    return x * (y as i64);
}

Here we convert u8to i64, which is possible since i64has a wider range than u8; but you cannot do other way around.

 

fn divide(x: i32, y: u16) -> f64 {
    return x as f64 / y as f64;
}

 

posted @ 2024-02-24 19:01  Zhentiw  阅读(1)  评论(0编辑  收藏  举报