Skip to content

Implementation of std::f64::powi function gives inconsistent answers in multiple Rust tool-chains #73920

Closed as duplicate of#71355
@hansieodendaal

Description

@hansieodendaal

Problem code

I tried this code (also in Rust playpen here):

fn main() {
    let base = 0.999_999_560_409_038_5f64;
    let i = [
        9182i32, 9430i32, 10855i32, 10856i32, 10857i32, 11708i32, 30335i32, 33923i32, 34947i32,
    ];
    // Reference results from:
    // - stable-x86_64-unknown-linux-gnu  (Debug)
    // - stable-x86_64-pc-windows-gnu     (Debug, Release)
    // - stable-x86_64-pc-windows-msvc    (Debug)
    // - nightly-x86_64-unknown-linux-gnu (Debug)
    // - nightly-x86_64-pc-windows-gnu    (Debug, Release)
    let result = [
        0.9959718099156295f64, 
        0.9958632363991619f64, 
        0.9952396058283226f64, 
        0.9952391683299874f64, 
        0.9952387308318444f64, 
        0.9948664896246138f64, 
        0.9867535223990311f64, 
        0.9851983894664985f64, 
        0.9847550108373471f64, 
    ];
    let iter = i.iter().zip(&result);
    for item in iter {
        let v = base.powi(*item.0);
        assert_eq!(v, *item.1)
    }
}

I expected to see this happen:

  • The code should always give consistent answers in Windows and Linux, either in release or debug mode, using stable or nightly.
  • The code should always give consistent answers in Rust playpen, either in release or debug mode, using stable, beta or nightly.

Instead, this happened:

Toolchains tested (Windows 10)

# Tool-chain (Windows) Debug/Release Pass/Fail
1 stable-x86_64-pc-windows-gnu Debug Pass
[1.44.1 (c7087fe 2020-06-17)] Release Pass
-- ----------------------------------------- ------------- ---------
2 stable-x86_64-pc-windows-msvc Debug Pass
[1.44.1 (c7087fe 2020-06-17)] Release Fail
-- ----------------------------------------- ------------- ---------
3 nightly-x86_64-pc-windows-gnu Debug Pass
[1.46.0-nightly (16957bd 2020-06-30)] Release Pass
-- ----------------------------------------- ------------- ---------
4 nightly-x86_64-pc-windows-msvc Debug Fail
[1.46.0-nightly (16957bd 2020-06-30)] Release Fail
-- ----------------------------------------- -------------- ---------
5 nightly-2019-05-12-x86_64-pc-windows-msvc Debug Pass
[1.36.0-nightly (af98304 2019-05-11)] Release Fail
-- ----------------------------------------- ------------- ---------
6 nightly-2019-07-31-x86_64-pc-windows-msvc Debug Pass
[1.38.0-nightly (dddb7fc 2019-07-30)] Release Fail
-- ------------------------------------------ ------------- ---------
7 nightly-2019-10-04-x86_64-pc-windows-msvc Debug Pass
[1.40.0-nightly (032a53a 2019-10-03)] Release Fail
-- ----------------------------------------- ------------- ---------
8 nightly-2020-01-08-x86_64-pc-windows-msvc Debug Pass
[1.42.0-nightly (8597644 2020-01-07)] Release Fail
-- ----------------------------------------- ------------- ---------
9 nightly-2020-02-23-x86_64-pc-windows-msvc Debug Pass
[1.43.0-nightly (436494b 2020-02-22)] Release Fail
-- ----------------------------------------- ------------- ---------
10 nightly-2020-06-10-x86_64-pc-windows-msvc Debug Fail
[1.46.0-nightly (feb3536 2020-06-09)] Release Fail

Toolchains tested (Linux Ubuntu)

# Tool-chain (Linux) Debug/Release Pass/Fail
1 stable-x86_64-unknown-linux-gnu Debug Pass
[1.44.1 (c7087fe 2020-06-17)] Release Fail
-- ------------------------------------------- ------------- ---------
2 nightly-2019-07-31-x86_64-unknown-linux-gnu Debug Pass
[1.38.0-nightly (dddb7fc 2019-07-30)] Release Fail
-- ------------------------------------------- ------------- ---------
3 nightly-2020-01-08-x86_64-unknown-linux-gnu Debug Pass
[1.42.0-nightly (8597644 2020-01-07)] Release Fail
-- ------------------------------------------- ------------- ---------
4 nightly-2020-06-10-x86_64-unknown-linux-gnu Debug Pass
[1.46.0-nightly (feb3536 2020-06-09)] Release Fail
-- ------------------------------------------- ------------- ---------
5 nightly-x86_64-unknown-linux-gnu Debug Pass
[1.46.0-nightly (16957bd 2020-06-30)] Release Fail

Rust playpen

# Tool-chain (Rust playpen) Debug/Release Pass/Fail
1 Stable channel Debug Pass
[Stable version: 1.44.1] Release Fail
-- --------------------------------------- ------------- ---------
2 Beta channel Debug Pass
[1.45.0-beta.3 (2020-06-27 8196407)] Release Fail
-- -------------------------------------- ------------- ---------
3 Nightly channel Debug Pass
[1.46.0-nightly (2020-06-30 16957bd)] Release Fail
-- --------------------------------------- ------------- ---------

Meta

rustc --version --verbose:
See detail information in the tables above.

Backtrace

C:\Code\f64_powi_issue>cargo run --release
warning: unused config key `build.RUSTFLAGS` in `C:\Users\.cargo\config`
    Finished release [optimized] target(s) in 0.05s
     Running `target\release\f64_powi_issue.exe`
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `0.9959718099154268`,
 right: `0.9959718099156295`', src\main.rs:22:9
stack backtrace:
   0: backtrace::backtrace::trace_unsynchronized
             at C:\Users\VssAdministrator\.cargo\registry\src\github.com-1ecc6299db9ec823\backtrace-0.3.46\src\backtrace\mod.rs:66
   1: std::sys_common::backtrace::_print_fmt
             at /rustc/c7087fe00d2ba919df1d813c040a5d47e43b0fe7\/src\libstd\sys_common\backtrace.rs:78
   2: std::sys_common::backtrace::_print::{{impl}}::fmt
             at /rustc/c7087fe00d2ba919df1d813c040a5d47e43b0fe7\/src\libstd\sys_common\backtrace.rs:59
   3: core::fmt::write
             at /rustc/c7087fe00d2ba919df1d813c040a5d47e43b0fe7\/src\libcore\fmt\mod.rs:1069
   4: std::io::Write::write_fmt<std::sys::windows::stdio::Stderr>
             at /rustc/c7087fe00d2ba919df1d813c040a5d47e43b0fe7\/src\libstd\io\mod.rs:1504
   5: std::sys_common::backtrace::_print
             at /rustc/c7087fe00d2ba919df1d813c040a5d47e43b0fe7\/src\libstd\sys_common\backtrace.rs:62
   6: std::sys_common::backtrace::print
             at /rustc/c7087fe00d2ba919df1d813c040a5d47e43b0fe7\/src\libstd\sys_common\backtrace.rs:49
   7: std::panicking::default_hook::{{closure}}
             at /rustc/c7087fe00d2ba919df1d813c040a5d47e43b0fe7\/src\libstd\panicking.rs:198
   8: std::panicking::default_hook
             at /rustc/c7087fe00d2ba919df1d813c040a5d47e43b0fe7\/src\libstd\panicking.rs:218
   9: std::panicking::rust_panic_with_hook
             at /rustc/c7087fe00d2ba919df1d813c040a5d47e43b0fe7\/src\libstd\panicking.rs:511
  10: std::panicking::begin_panic_handler
             at /rustc/c7087fe00d2ba919df1d813c040a5d47e43b0fe7\/src\libstd\panicking.rs:419
  11: std::panicking::begin_panic_fmt
             at /rustc/c7087fe00d2ba919df1d813c040a5d47e43b0fe7\/src\libstd\panicking.rs:373
  12: __ImageBase
  13: __ImageBase
  14: std::rt::lang_start_internal::{{closure}}
             at /rustc/c7087fe00d2ba919df1d813c040a5d47e43b0fe7\/src\libstd\rt.rs:52
  15: std::panicking::try::do_call
             at /rustc/c7087fe00d2ba919df1d813c040a5d47e43b0fe7\/src\libstd\panicking.rs:331
  16: std::panicking::try
             at /rustc/c7087fe00d2ba919df1d813c040a5d47e43b0fe7\/src\libstd\panicking.rs:274
  17: std::panic::catch_unwind
             at /rustc/c7087fe00d2ba919df1d813c040a5d47e43b0fe7\/src\libstd\panic.rs:394
  18: std::rt::lang_start_internal
             at /rustc/c7087fe00d2ba919df1d813c040a5d47e43b0fe7\/src\libstd\rt.rs:51
  19: main
  20: invoke_main
             at d:\agent\_work\5\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78
  21: __scrt_common_main_seh
             at d:\agent\_work\5\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
  22: BaseThreadInitThunk
  23: RtlUserThreadStart
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
error: process didn't exit successfully: `target\release\f64_powi_issue.exe` (exit code: 101)

C:\Code\f64_powi_issue>rustc --version --verbose
rustc 1.44.1 (c7087fe00 2020-06-17)
binary: rustc
commit-hash: c7087fe00d2ba919df1d813c040a5d47e43b0fe7
commit-date: 2020-06-17
host: x86_64-pc-windows-msvc
release: 1.44.1
LLVM version: 9.0

Metadata

Metadata

Assignees

No one assigned

    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.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions