Skip to content

Float constant evaluation showing incorrect values #14704

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

Closed
tjkirch opened this issue May 1, 2023 · 1 comment · Fixed by #14705 or #14825
Closed

Float constant evaluation showing incorrect values #14704

tjkirch opened this issue May 1, 2023 · 1 comment · Fixed by #14705 or #14825
Assignees
Labels
C-bug Category: bug

Comments

@tjkirch
Copy link

tjkirch commented May 1, 2023

rust-analyzer version: (eg. output of "rust-analyzer: Show RA Version" command, accessible in VSCode via Ctrl/⌘+Shift+P)

  • 0.3.1426-standalone (2023-03-06)
  • 0.3.1498-standalone (2023-05-01)
  • Several releases between those, when I did basic bisecting

rustc version: (eg. output of rustc -V)

  • rustc 1.69.0 (84c898d65 2023-04-16)
  • Also rustc 1.69.0-nightly (ef934d9b6 2023-02-08)

relevant settings: (eg. client settings, or environment variables like CARGO, RUSTC, RUSTUP_HOME or CARGO_HOME)

  • None

I normally use the rustup rust-analyzer, but I was excited to see const evaluation support in newer versions and wanted to try it out. I did cargo init --lib for a blank project and added the following consts:

const ANGLE_01: f64 = 180.0;
const ANGLE_02: f64 = 180.0 - 2.0;

The rust-analyzer info for the plain constant ANGLE_01 is correct:

const ANGLE_01: f64 = 180.0

The (MIR?) const evaluation is incorrect for ANGLE_02, which should just be 178.0:

const ANGLE_02: f64 = 1.0012832363282406e-306

If I change it to an f32, it's similarly wrong:

const ANGLE_02: f32 = 5.2897246e-37

I'd expect these to show 178.0, or close enough for a float. Am I misunderstanding the purpose of the const evaluation support, or am I doing something dumb?

@tjkirch tjkirch added the C-bug Category: bug label May 1, 2023
@HKalbasi HKalbasi self-assigned this May 1, 2023
@bors bors closed this as completed in 86b14c2 May 2, 2023
@tjkirch
Copy link
Author

tjkirch commented May 16, 2023

@HKalbasi Thanks for looking at this! Things are better now in most cases. The following are correct now with rust-analyzer 2023-05-15:

  • 90.0 - 28.0 shows 62.0
  • 0.0 - 14.0 shows -14.0

However, others involving negatives seems to be wrong?

  • -90.0 + 36.0 shows 35.950195 instead of -54.0
  • -1.0 + 1.0 shows -3.0 instead of 0.0
  • -1.0 + -1.0 shows -8.0 instead of -2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
2 participants