Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions ext/bigdecimal/bigdecimal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1702,8 +1702,8 @@ static VALUE
BigDecimal_neg(VALUE self)
{
BDVALUE a = GetBDValueMust(self);
BDVALUE c = NewZeroWrapLimited(1, a.real->Prec * BASE_FIG);
VpAsgn(c.real, a.real, -1);
BDVALUE c = NewZeroWrapNolimit(1, a.real->Prec * BASE_FIG);
VpAsgn(c.real, a.real, -10);
RB_GC_GUARD(a.bigdecimal);
return CheckGetValue(c);
}
Expand Down Expand Up @@ -2176,8 +2176,8 @@ static VALUE
BigDecimal_abs(VALUE self)
{
BDVALUE a = GetBDValueMust(self);
BDVALUE c = NewZeroWrapLimited(1, a.real->Prec * BASE_FIG);
VpAsgn(c.real, a.real, 1);
BDVALUE c = NewZeroWrapNolimit(1, a.real->Prec * BASE_FIG);
VpAsgn(c.real, a.real, 10);
VpChangeSign(c.real, 1);
RB_GC_GUARD(a.bigdecimal);
return CheckGetValue(c);
Expand Down Expand Up @@ -2215,7 +2215,7 @@ static VALUE
BigDecimal_fix(VALUE self)
{
BDVALUE a = GetBDValueMust(self);
BDVALUE c = NewZeroWrapLimited(1, (a.real->Prec + 1) * BASE_FIG);
BDVALUE c = NewZeroWrapNolimit(1, (a.real->Prec + 1) * BASE_FIG);
VpActiveRound(c.real, a.real, VP_ROUND_DOWN, 0); /* 0: round off */
RB_GC_GUARD(a.bigdecimal);
return CheckGetValue(c);
Expand Down Expand Up @@ -2359,7 +2359,7 @@ static VALUE
BigDecimal_frac(VALUE self)
{
BDVALUE a = GetBDValueMust(self);
BDVALUE c = NewZeroWrapLimited(1, (a.real->Prec + 1) * BASE_FIG);
BDVALUE c = NewZeroWrapNolimit(1, (a.real->Prec + 1) * BASE_FIG);
VpFrac(c.real, a.real);
RB_GC_GUARD(a.bigdecimal);
return CheckGetValue(c);
Expand Down
25 changes: 25 additions & 0 deletions test/bigdecimal/test_bigdecimal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2051,6 +2051,31 @@ def test_div_mod_rem_operation_with_limit
end
end

def test_sign_operator_ignores_limit
plus_x = BigDecimal('7' * 100)
minus_x = -plus_x
BigDecimal.save_limit do
BigDecimal.limit(3)
assert_equal(plus_x, +plus_x)
assert_equal(minus_x, +minus_x)
assert_equal(minus_x, -plus_x)
assert_equal(plus_x, -minus_x)
assert_equal(plus_x, minus_x.abs)
assert_equal(plus_x, plus_x.abs)
end
end

def test_fix_frac_ignores_limit
fix = BigDecimal("#{'4' * 56}")
frac = BigDecimal("0.#{'7' * 89}")
x = fix + frac
BigDecimal.save_limit do
BigDecimal.limit(3)
assert_equal(fix, x.fix)
assert_equal(frac, x.frac)
end
end

def test_sign
BigDecimal.mode(BigDecimal::EXCEPTION_OVERFLOW, false)
BigDecimal.mode(BigDecimal::EXCEPTION_NaN, false)
Expand Down
Loading