Skip to content

Value differs between debug and release: 1.0 / ((-0.0) * black_box_zero) #102402

Closed
@jruderman

Description

@jruderman

This code has differing behavior in debug and release (playground):

fn main() {
    let black_box_zero = (std::env::args().len() - 1) as f32;
    let result = 1.0 / ((-0.0) * black_box_zero);
    let expected = f32::NEG_INFINITY;
    assert_eq!(result, expected);
}

When compiled in debug mode (without optimizations), the program produces no output.

When compiled in release mode (with optimizations), the assertion fails:

thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `-inf`,
 right: `-inf`', src/main.rs:5:5

(This output doesn't make sense to me: how can they be unequal, but both negative infinity?)

Metadata

Metadata

Assignees

Labels

A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-floating-pointArea: Floating point numbers and arithmeticC-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions