Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
H-ZeX opened this issue Sep 12, 2019 · 2 comments
Closed

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

H-ZeX opened this issue Sep 12, 2019 · 2 comments
Labels
C-bug Category: This is a bug. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@H-ZeX
Copy link

H-ZeX commented Sep 12, 2019

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

@jonas-schievink jonas-schievink added C-bug Category: This is a bug. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Sep 12, 2019
@ExpHP
Copy link
Contributor

ExpHP commented Sep 12, 2019

It is represented precisely, it just isn't printed to full precision (only round trip precision)

See #63171

@scottmcm
Copy link
Member

Closing a duplicate of the issue that @ExpHP mentioned.

You can use https://evanw.github.io/float-toy/ to see that both strings mentioned are the same float.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants