Skip to content

Commit 8233dee

Browse files
authored
Translate std::abs on long and long long as i64 (#591)
1 parent 6b23c59 commit 8233dee

4 files changed

Lines changed: 32 additions & 2 deletions

File tree

‎rules/cmath/tgt_unsafe.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
unsafe fn f1(a0: i32) -> i32 {
55
a0.abs()
66
}
7-
unsafe fn f2(a0: i32) -> i32 {
7+
unsafe fn f2(a0: i64) -> i64 {
88
a0.abs()
99
}
10-
unsafe fn f3(a0: i32) -> i32 {
10+
unsafe fn f3(a0: i64) -> i64 {
1111
a0.abs()
1212
}
1313
unsafe fn f4(a0: f64) -> f64 {

‎tests/unit/fft.cpp‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,15 @@ int main() {
6767
}
6868
assert(reals[0] == 10 && imgs[0] == 0 && reals[1] == -2 && imgs[1] == 2 &&
6969
reals[2] == -2 && imgs[2] == 0 && reals[3] == -2 && imgs[3] == -2);
70+
long l = -5000000000L;
71+
long long ll = -6000000000LL;
72+
assert(std::abs(l) == 5000000000L);
73+
assert(std::abs(ll) == 6000000000LL);
74+
long small = -7;
75+
long long small_ll = -8;
76+
int narrowed = std::abs(small);
77+
int narrowed_ll = std::abs(small_ll);
78+
assert(narrowed == 7);
79+
assert(narrowed_ll == 8);
7080
return 0;
7181
}

‎tests/unit/out/refcount/fft.rs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,16 @@ fn main_0() -> i32 {
259259
.read())
260260
== -2_i32)
261261
);
262+
let mut l: i64 = -5000000000_i64;
263+
let mut ll: i64 = -6000000000_i64;
264+
assert!((l.abs() == 5000000000_i64));
265+
assert!((ll.abs() == 6000000000_i64));
266+
let mut small: i64 = (-7_i32 as i64);
267+
let mut small_ll: i64 = (-8_i32 as i64);
268+
let mut narrowed: i32 = (small.abs() as i32);
269+
let mut narrowed_ll: i32 = (small_ll.abs() as i32);
270+
assert!((narrowed == 7));
271+
assert!((narrowed_ll == 8));
262272
return 0;
263273
}
264274
pub fn __cpp2rust_init_globals() {}

‎tests/unit/out/unsafe/fft.rs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,16 @@ unsafe fn main_0() -> i32 {
266266
.add(3_usize))
267267
== (-2_i32))
268268
);
269+
let mut l: i64 = -5000000000_i64;
270+
let mut ll: i64 = -6000000000_i64;
271+
assert!(((l.abs()) == (5000000000_i64)));
272+
assert!(((ll.abs()) == (6000000000_i64)));
273+
let mut small: i64 = (-7_i32 as i64);
274+
let mut small_ll: i64 = (-8_i32 as i64);
275+
let mut narrowed: i32 = (small.abs() as i32);
276+
let mut narrowed_ll: i32 = (small_ll.abs() as i32);
277+
assert!(((narrowed) == (7)));
278+
assert!(((narrowed_ll) == (8)));
269279
return 0;
270280
}
271281
pub unsafe fn __cpp2rust_init_globals() {}

0 commit comments

Comments
 (0)