Skip to content

Sign of zero from differs between CTFE and normal execution (float % float) #102403

Closed
rust-lang/rustc_apfloat
#1
@jruderman

Description

@jruderman

With this code:

#![feature(const_fn_floating_point_arithmetic)]

const fn f(one: f64) -> f64 {
    (-1.0) % one
}

const RESULT_CT : f64 = f(1.0);

fn main() {
    let black_box_one = (std::env::args().len()) as f64;
    let result_rt = f(black_box_one);
    assert_eq!(RESULT_CT.is_sign_negative(), result_rt.is_sign_negative());
}

The assertion fails: compile-time evaluation gives 0.0 while runtime evaluation gives -0.0.

This is probably relevant to tracking issue #57241.

Metadata

Metadata

Assignees

Labels

A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-floating-pointArea: Floating point numbers and arithmeticA-mir-optArea: MIR optimizationsC-bugCategory: This is a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions