Skip to content

i32::pow only handles overflow up to an exponent of 1023 #28012

Closed
@jonas-schievink

Description

@jonas-schievink

Playpen: http://is.gd/zhwksu

fn main() {
    let x: i32 = 2;

    println!("{}", x.pow(1024));
    println!("{}", x.pow(1023));
}

Prints:

0
thread '<main>' panicked at 'arithmetic operation overflowed', ../src/libcore/num/mod.rs:550

Interestingly, this only seems to happen with an even base. The overflow is detected correctly when x is set to 3 or other odd numbers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions