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

-0.0f{32,64}.next_up() should return the smallest non-zero positive value #134224

Closed
mamekoro opened this issue Dec 12, 2024 · 1 comment
Closed
Labels
A-floating-point Area: Floating point numbers and arithmetic C-discussion Category: Discussion or questions that doesn't represent real issues.

Comments

@mamekoro
Copy link

I tried this code:

#![feature(float_next_up_down)]

fn main() {
    println!("{:?}", -0.0f32.next_up()); // -1e-45
    println!("{:?}", 0.0f32.next_up());  //  1e-45
    println!("{:?}", -0.0f64.next_up()); // -5e-324
    println!("{:?}", 0.0f64.next_up());  //  5e-324
}

I expected to see this happen:

  • Accoding to 3173-float-next-up-down - The Rust RFC Book:
    • -0.0f32.next_up() should return the smallest non-zero positive f32 value (f32::from_bits(0x1), 1e-45).
    • -0.0f64.next_up() should return the smallest non-zero positive f64 value (f64::from_bits(0x1), 5e-324).

Instead, this happened:

  • -0.0f32.next_up() returns -1e-45.
  • -0.0f64.next_up() returns -5e-324.

Meta

rustc --version --verbose:

rustc 1.85.0-nightly (21fe748be 2024-12-11)
binary: rustc
commit-hash: 21fe748be15271ea5804e0507cd699b675efe038
commit-date: 2024-12-11
host: x86_64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.5
@mamekoro mamekoro added the C-bug Category: This is a bug. label Dec 12, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 12, 2024
@mamekoro mamekoro changed the title -0.0f{32,64}.next_up() should return smallest non-zero positive value -0.0f{32,64}.next_up() should return the smallest non-zero positive value Dec 12, 2024
@mamekoro
Copy link
Author

Oh, I apologize; this is not a bug.

I should have enclosed -0.0f{32,64} in parentheses, as shown below, and these work correctly:

  • (-0.0f32).next_up()
  • (-0.0f64).next_up()

@saethlin saethlin added A-floating-point Area: Floating point numbers and arithmetic C-discussion Category: Discussion or questions that doesn't represent real issues. and removed C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-floating-point Area: Floating point numbers and arithmetic C-discussion Category: Discussion or questions that doesn't represent real issues.
Projects
None yet
Development

No branches or pull requests

3 participants