Skip to content

Commit 6341692

Browse files
committed
Auto merge of #3094 - RalfJung:float, r=RalfJung
add some float tests Fixes #2649
2 parents 0ead204 + 5eb0dda commit 6341692

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

src/shims/intrinsics/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
324324

325325
"fmaf32" => {
326326
let [a, b, c] = check_arg_count(args)?;
327-
// FIXME: Using host floats, to work around https://github.com/rust-lang/miri/issues/2468.
327+
// FIXME: Using host floats, to work around https://github.com/rust-lang/rustc_apfloat/issues/11
328328
let a = f32::from_bits(this.read_scalar(a)?.to_u32()?);
329329
let b = f32::from_bits(this.read_scalar(b)?.to_u32()?);
330330
let c = f32::from_bits(this.read_scalar(c)?.to_u32()?);
@@ -334,7 +334,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
334334

335335
"fmaf64" => {
336336
let [a, b, c] = check_arg_count(args)?;
337-
// FIXME: Using host floats, to work around https://github.com/rust-lang/miri/issues/2468.
337+
// FIXME: Using host floats, to work around https://github.com/rust-lang/rustc_apfloat/issues/11
338338
let a = f64::from_bits(this.read_scalar(a)?.to_u64()?);
339339
let b = f64::from_bits(this.read_scalar(b)?.to_u64()?);
340340
let c = f64::from_bits(this.read_scalar(c)?.to_u64()?);

tests/pass/float.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,16 @@ fn basic() {
168168
let x: u32 = unsafe { std::mem::transmute(42.0_f32) };
169169
let y: f32 = unsafe { std::mem::transmute(x) };
170170
assert_eq(y, 42.0_f32);
171+
172+
// `%` sign behavior, some of this used to be buggy
173+
assert!((black_box(1.0f32) % 1.0).is_sign_positive());
174+
assert!((black_box(1.0f32) % -1.0).is_sign_positive());
175+
assert!((black_box(-1.0f32) % 1.0).is_sign_negative());
176+
assert!((black_box(-1.0f32) % -1.0).is_sign_negative());
177+
assert!((black_box(1.0f64) % 1.0).is_sign_positive());
178+
assert!((black_box(1.0f64) % -1.0).is_sign_positive());
179+
assert!((black_box(-1.0f64) % 1.0).is_sign_negative());
180+
assert!((black_box(-1.0f64) % -1.0).is_sign_negative());
171181
}
172182

173183
/// Many of these test values are taken from

tests/pass/intrinsics-math.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![feature(float_gamma)]
2+
use std::{f32, f64};
23

34
macro_rules! assert_approx_eq {
45
($a:expr, $b:expr) => {{
@@ -15,8 +16,7 @@ fn ldexp(a: f64, b: i32) -> f64 {
1516
}
1617

1718
pub fn main() {
18-
use std::f32;
19-
use std::f64;
19+
mul_add();
2020

2121
assert_approx_eq!(64f32.sqrt(), 8f32);
2222
assert_approx_eq!(64f64.sqrt(), 8f64);
@@ -48,13 +48,6 @@ pub fn main() {
4848
assert_approx_eq!(8f32.log2(), 3f32);
4949
assert_approx_eq!(f64::consts::E.log2(), f64::consts::LOG2_E);
5050

51-
assert_approx_eq!(3.0f32.mul_add(2.0f32, 5.0f32), 11.0);
52-
assert_eq!(0.0f32.mul_add(-2.0, f32::consts::E), f32::consts::E);
53-
assert_approx_eq!(3.0f64.mul_add(2.0, 5.0), 11.0);
54-
assert_eq!(0.0f64.mul_add(-2.0f64, f64::consts::E), f64::consts::E);
55-
assert_eq!((-3.2f32).mul_add(2.4, f32::NEG_INFINITY), f32::NEG_INFINITY);
56-
assert_eq!((-3.2f64).mul_add(2.4, f64::NEG_INFINITY), f64::NEG_INFINITY);
57-
5851
assert_approx_eq!((-1.0f32).abs(), 1.0f32);
5952
assert_approx_eq!(34.2f64.abs(), 34.2f64);
6053

@@ -146,3 +139,19 @@ pub fn main() {
146139
assert_approx_eq!(val, (2.0 * f64::consts::PI.sqrt()).ln());
147140
assert_eq!(sign, -1);
148141
}
142+
143+
fn mul_add() {
144+
assert_approx_eq!(3.0f32.mul_add(2.0f32, 5.0f32), 11.0);
145+
assert_eq!(0.0f32.mul_add(-2.0, f32::consts::E), f32::consts::E);
146+
assert_approx_eq!(3.0f64.mul_add(2.0, 5.0), 11.0);
147+
assert_eq!(0.0f64.mul_add(-2.0f64, f64::consts::E), f64::consts::E);
148+
assert_eq!((-3.2f32).mul_add(2.4, f32::NEG_INFINITY), f32::NEG_INFINITY);
149+
assert_eq!((-3.2f64).mul_add(2.4, f64::NEG_INFINITY), f64::NEG_INFINITY);
150+
151+
let f = f32::mul_add(
152+
-0.000000000000000000000000000000000000014728589,
153+
0.0000037105144,
154+
0.000000000000000000000000000000000000000000055,
155+
);
156+
assert_eq!(f.to_bits(), f32::to_bits(-0.0));
157+
}

0 commit comments

Comments
 (0)