Skip to content

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

Closed
@mamekoro

Description

@mamekoro

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-floating-pointArea: Floating point numbers and arithmeticC-discussionCategory: Discussion or questions that doesn't represent real issues.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions