Skip to content

Commit

Permalink
[ISSUE-0090]: bigdecimal absv function
Browse files Browse the repository at this point in the history
  • Loading branch information
SzigetiJ committed Jan 30, 2024
1 parent 64b3259 commit 3930f5c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/bigdecimal128.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,11 @@ BigDecimal128 bigdecimal128_mulv(const BigDecimal128 a, const BigDecimal128 b) {
BigDecimal128 bigdecimal128_divv(const BigDecimal128 a, const BigDecimal128 b, UInt prec) {
return bigdecimal128_div(&a, &b, prec);
}

BigDecimal128 bigdecimal128_absv(const BigDecimal128 a, buint_bool *result_inv) {
return (BigDecimal128){bigint128_absv(a.val, result_inv), a.prec};
}

buint_bool bigdecimal128_ltv(const BigDecimal128 a, const BigDecimal128 b) {
return bigdecimal128_lt(&a, &b);
}
Expand Down
1 change: 1 addition & 0 deletions src/bigdecimal128.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ BigDecimal128 bigdecimal128_addv(const BigDecimal128 a, const BigDecimal128 b);
BigDecimal128 bigdecimal128_subv(const BigDecimal128 a, const BigDecimal128 b);
BigDecimal128 bigdecimal128_mulv(const BigDecimal128 a, const BigDecimal128 b);
BigDecimal128 bigdecimal128_divv(const BigDecimal128 a, const BigDecimal128 b, UInt prec);
BigDecimal128 bigdecimal128_absv(const BigDecimal128 a, buint_bool *result_inv);
buint_bool bigdecimal128_ltv(const BigDecimal128 a, const BigDecimal128 b);
buint_bool bigdecimal128_eqv(const BigDecimal128 a, const BigDecimal128 b);
buint_size_t bigdecimal128_printv(const BigDecimal128 a, char *buf, buint_size_t buf_len);
Expand Down
4 changes: 4 additions & 0 deletions src/biguint128.c
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,10 @@ BigUIntPair128 bigint128_divv(const BigUInt128 a, const BigUInt128 b) {
return bigint128_div(&a, &b);
}

BigUInt128 bigint128_absv(const BigUInt128 a, buint_bool *b) {
return bigint128_abs(&a, b);
}

BigUInt128 biguint128_andv(const BigUInt128 a, const BigUInt128 b) {
return biguint128_and(&a, &b);
}
Expand Down
1 change: 1 addition & 0 deletions src/biguint128.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ BigUInt128 biguint128_subv(const BigUInt128 a, const BigUInt128 b);
BigUInt128 biguint128_mulv(const BigUInt128 a, const BigUInt128 b);
BigUIntPair128 biguint128_divv(const BigUInt128 a, const BigUInt128 b);
BigUIntPair128 bigint128_divv(const BigUInt128 a, const BigUInt128 b);
BigUInt128 bigint128_absv(const BigUInt128 a, buint_bool *b);

BigUInt128 biguint128_andv(const BigUInt128 a, const BigUInt128 b);
BigUInt128 biguint128_orv(const BigUInt128 a, const BigUInt128 b);
Expand Down
15 changes: 15 additions & 0 deletions tests/bigdecimal128_pval_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,21 @@ static bool compare_all() {
pass = false;
}
}
{ // bigint abs
buint_bool expected_inv, actual_inv[2];
BigDecimal128 expected = {bigint128_abs(&a.val, &expected_inv),a.prec};
BigDecimal128 actual[] = {
{bigint128_absv(a.val, &actual_inv[0]),a.prec},
bigdecimal128_absv(a, &actual_inv[1])
};
for (unsigned int j=0; j<2; ++j) {
pass &= compare_result_(stderr, "biguint abs function", &expected, &actual[j], i, j);
if (!!expected_inv != !!actual_inv[j]) {
fprintf(stderr, "pass-by-value result error at sample #%u, abs#%u result_inv\n", i, j);
pass = false;
}
}
}
}
return pass;
}
Expand Down

0 comments on commit 3930f5c

Please sign in to comment.