when on 128-bit numbers

This commit is contained in:
Folkert 2022-07-29 14:09:50 +02:00
parent d0f1500dad
commit 47bbef30e8
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
3 changed files with 37 additions and 3 deletions

View file

@ -1387,8 +1387,6 @@ fn test_to_equality<'a>(
}
Test::IsInt(test_int, precision) => {
// TODO don't downcast i128 here
debug_assert!(i128::from_ne_bytes(test_int) <= i64::MAX as i128);
let lhs = Expr::Literal(Literal::Int(test_int));
let lhs_symbol = env.unique_symbol();
stores.push((lhs_symbol, Layout::int_width(precision), lhs));

View file

@ -8957,7 +8957,7 @@ impl NumLiteral {
fn to_pattern(&self) -> Pattern<'static> {
match *self {
NumLiteral::Int(n, w) => Pattern::IntLiteral(n, w),
NumLiteral::U128(_) => todo!(),
NumLiteral::U128(n) => Pattern::IntLiteral(n, IntWidth::U128),
NumLiteral::Float(n, w) => Pattern::FloatLiteral(f64::to_bits(n), w),
NumLiteral::Decimal(n) => Pattern::DecimalLiteral(n),
}

View file

@ -3682,3 +3682,39 @@ fn when_on_decimals() {
i64
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn when_on_i128() {
assert_evals_to!(
indoc!(
r#"
when 1701411834604692317316873037158841057i128 is
1701411834604692317316873037158841057 -> 42
32 -> 1
64 -> 2
_ -> 4
"#
),
42,
i64
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn when_on_u128() {
assert_evals_to!(
indoc!(
r#"
when 170141183460469231731687303715884105728u128 is
170141183460469231731687303715884105728u128 -> 42
32 -> 1
64 -> 2
_ -> 4
"#
),
42,
i64
);
}