bignum: Compute correct bignum type for difference

When we have a wordsize of 64 or more, we need to select the same
bignum type for the difference as the input.

Fixes: #1097

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
This commit is contained in:
Christophe de Dinechin 2024-08-02 02:26:17 +02:00
parent 4c2306d2a5
commit e43f1971e7
2 changed files with 16 additions and 2 deletions

View file

@ -417,7 +417,10 @@ bignum_g bignum::add_sub(bignum_r y, bignum_r x, bool issub)
if (cmp >= 0)
{
// abs Y > abs X: result has opposite type of X
id ty = cmp == 0 ? ID_bignum: issub ? xt : opposite_type(xt);
id ty = based ? xt
: cmp == 0 ? ID_bignum
: issub ? xt
: opposite_type(xt);
return binary<false>(sub_op, yg, xg, ty);
}
else

View file

@ -165,7 +165,8 @@ void tests::run(bool onlyCurrent)
if (onlyCurrent)
{
here().begin("Current");
eqnlib_columns_and_beams();
// eqnlib_columns_and_beams();
logical_operations();
}
else
{
@ -2077,16 +2078,19 @@ void tests::logical_operations()
test(CLEAR, "30 STWS", ENTER).noerror();
test(CLEAR, "#142 not", ENTER).expect("#3FFFFEBD₁₆");
test("not", ENTER).expect("#142₁₆");
test("#3 #5 -", ENTER).expect("#3FFFFFFE₁₆");
step("Set word size to 48");
test(CLEAR, "48 STWS", ENTER).noerror();
test(CLEAR, "#233 not", ENTER).expect("#FFFFFFFFFDCC₁₆");
test("not", ENTER).expect("#233₁₆");
test("#8 #15 -", ENTER).expect("#FFFFFFFFFFF3₁₆");
step("Set word size to 64");
test(CLEAR, "64 STWS", ENTER).noerror();
test(CLEAR, "#64123 not", ENTER).expect("#FFFFFFFFFFF9BEDC₁₆");
test("not", ENTER).expect("#64123₁₆");
test("#8 #21 -", ENTER).expect("#FFFFFFFFFFFFFFE7₁₆");
step("Set word size to 128");
test(CLEAR, "128 STWS", ENTER).noerror();
@ -2094,6 +2098,8 @@ void tests::logical_operations()
.expect("#FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFED₁₆");
test("dup not", ENTER).expect("#12₁₆");
test("xor not", ENTER).expect("#0₁₆");
test("#7A02 #21445 -", ENTER)
.expect("#FFFFFFFFFFFFFFFFFFFFFFFFFFFE65BD₁₆");
step("Set word size to 623");
test(CLEAR, "623 STWS", ENTER).noerror();
@ -2104,6 +2110,11 @@ void tests::logical_operations()
"FFFFFFFFFFED₁₆");
test("dup not", ENTER).expect("#12₁₆");
test("xor not", ENTER).expect("#0₁₆");
test("#7A03 #21447 -", ENTER)
.expect("#7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
"FFFFFFFE65BC₁₆");
step("Check that arithmetic truncates to small word size (#624)")
.test("15 STWS", ENTER).noerror()