Skip to content

test_convert_f32 test failed on i686-pc-windows-* target #261

@ghost

Description

test failed on i686-pc-windows-msvc, but succeeded on x86_64-pc-windows-msvc.

toolchain:

$ rustup --version
rustup 1.25.1 (bb60b1e89 2022-07-12)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.65.0 (897e37553 2022-11-02)`

command:

$ cargo test --target=i686-pc-windows-msvc
    Finished test [unoptimized + debuginfo] target(s) in 0.01s
     Running unittests src\lib.rs (target\i686-pc-windows-msvc\debug\deps\num_bigint-4a5286ac62f80819.exe)

running 13 tests
test bigint::test_assign_from_slice ... ok
test bigint::test_from_biguint ... ok
test bigint::test_from_slice ... ok
test biguint::iter::test_iter_u32_digits ... ok
test biguint::iter::test_iter_u32_digits_be ... ok
test biguint::iter::test_iter_u64_digits ... ok
test biguint::iter::test_iter_u64_digits_be ... ok
test biguint::power::test_pow_biguint ... ok
test biguint::multiplication::test_sub_sign ... ok
test biguint::test_from_slice ... ok
test biguint::test_u128_u32_roundtrip ... ok
test biguint::test_u32_u128 ... ok
test biguint::power::test_plain_modpow ... ok

test result: ok. 13 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running tests\bigint.rs (target\i686-pc-windows-msvc\debug\deps\bigint-f180ad9c24c76948.exe)

running 52 tests
test test_abs_sub ... ok
test test_binary ... ok
test test_bit ... ok
test test_checked_add ... ok
test test_checked_sub ... ok
test test_checked_mul ... ok
test test_cmp ... ok
test test_convert_from_biguint ... ok
test test_checked_div ... ok
test test_convert_from_int ... ok
test test_add ... ok
test test_convert_from_uint ... ok
test test_convert_i128 ... ok
test test_convert_f32 ... FAILED
test test_convert_i64 ... ok
test test_convert_to_biguint ... ok
test test_convert_u128 ... ok
test test_convert_f64 ... ok
test test_convert_u64 ... ok
test test_display ... ok
test test_from_bytes_be ... ok
test test_from_bytes_le ... ok
test test_div_ceil ... ok
test test_from_signed_bytes_be ... ok
test test_from_signed_bytes_le ... ok
test test_from_str_radix ... ok
test test_hash ... ok
test test_gcd ... ok
test test_iter_product ... ok
test test_iter_product_generic ... ok
test test_iter_sum ... ok
test test_iter_sum_generic ... ok
test test_lcm ... ok
test test_lower_hex ... ok
test test_neg ... ok
test test_negative_shr ... ok
test test_next_multiple_of ... ok
test test_div_mod_floor ... ok
test test_octal ... ok
test test_prev_multiple_of ... ok
test test_mul ... ok
test test_set_bit ... ok
test test_to_bytes_be ... ok
test test_to_bytes_le ... ok
test test_to_signed_bytes_be ... ok
test test_to_signed_bytes_le ... ok
test test_upper_hex ... ok
test test_sub ... ok
test test_div_rem ... ok
test test_pow ... ok
test test_signed_bytes_le_round_trip ... ok
test test_signed_bytes_be_round_trip ... ok

failures:

---- test_convert_f32 stdout ----
thread 'test_convert_f32' panicked at 'assertion failed: `(left == right)`
  left: `Some(1.8014399e16)`,
 right: `Some(1.8014397e16)`', tests\bigint.rs:410:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    test_convert_f32

test result: FAILED. 51 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.50s

error: test failed, to rerun pass `--test bigint`

Activity

ghost changed the title [-]test failed on i686-pc-windows-msvc[/-] [+]`test_convert_f32` test failed on a 32bit target[/+] on Dec 12, 2022
ghost

ghost commented on Dec 12, 2022

@ghost

It seems that n as i64 as f32 and n as u64 as f32 give different results on a 32-bit target.

num-bigint/tests/bigint.rs

Lines 408 to 413 in a730396

let mut n: i64 = 0b0000000000111111111111111111111111011111111111111111111111111111;
assert!((n as f64) as f32 != n as f32);
assert_eq!(BigInt::from(n).to_f32(), Some(n as f32));
n = -n;
assert!((n as f64) as f32 != n as f32);
assert_eq!(BigInt::from(n).to_f32(), Some(n as f32));

cuviper

cuviper commented on Dec 12, 2022

@cuviper
Member

FWIW, all tests do pass on i686-unknown-linux-gnu, and this is even tested in CI.

ghost changed the title [-]`test_convert_f32` test failed on a 32bit target[/-] [+]`test_convert_f32` test failed on `i686-pc-windows-msvc` target[/+] on Dec 12, 2022
ghost

ghost commented on Dec 12, 2022

@ghost

I haven't tested other 32-bit targets yet, but it seems to be an issue only with 32-bit Windows targets.

ghost closed this as completedon Dec 19, 2022
ghost reopened this on Dec 19, 2022
cuviper

cuviper commented on Jan 1, 2023

@cuviper
Member

Hmm, I was able to reproduce this on i686-pc-windows-gnu as well, so at least I can debug that via Wine in my Linux development environment.

changed the title [-]`test_convert_f32` test failed on `i686-pc-windows-msvc` target[/-] [+]`test_convert_f32` test failed on `i686-pc-windows-*` target[/+] on Jan 1, 2023
CryZe

CryZe commented on Jan 2, 2023

@CryZe

We concluded that it's the FPU Control Word that is configured differently by default on Windows environments to use 53 bits instead of 64 bits like on Linux. This would need to be special cased in LLVM or so.

cuviper

cuviper commented on Jan 2, 2023

@cuviper
Member

By "we", do you mean that you are working with @icedrocket?

I was thinking this should be closed as a compiler issue, and it sounds like you would agree, right?

CryZe

CryZe commented on Jan 2, 2023

@CryZe

No, I simply tried reproducing it once I saw the issue in the rust repo and then figured out what caused it. I'm not affiliated with them. But yeah this for sure is a compiler / LLVM issue.

cuviper

cuviper commented on Jan 2, 2023

@cuviper
Member

Ah, now I see the linked issue rust-lang/rust#105626 -- then let's leave it there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @cuviper@CryZe

        Issue actions

          `test_convert_f32` test failed on `i686-pc-windows-*` target · Issue #261 · rust-num/num-bigint