Skip to content

(1<<64) can not be precisely represent by f64 in rust (in c, it is ok) #64399

Closed
@H-ZeX

Description

@H-ZeX
fn main() {
    let a: f64 = 2.0f64.powi(64);
    println!("{}", a); 
    let a: f64 = 18446744073709551616.0f64;
    println!("{}", a);

    // wii output 
    // 18446744073709552000
    // 18446744073709552000
}
#include <stdio.h>

int main() {
    double a = 18446744073709551616.0;
    float b = 18446744073709551616.0;
    printf("%lf, %f\n", a, b);

    // will output 
    //18446744073709551616.000000, 18446744073709551616.000000
}

(1<<64) == 18446744073709551616, so IEEE754 can represent it use 64 or 32 float number

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions