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
2 changes: 1 addition & 1 deletion ext/bigdecimal/bigdecimal.c
Original file line number Diff line number Diff line change
Expand Up @@ -2898,7 +2898,7 @@ rb_convert_to_BigDecimal(VALUE val, size_t digs, int raise_exception)
else if (RB_TYPE_P(val, T_COMPLEX)) {
VALUE im = rb_complex_imag(val);
if (!is_zero(im)) {
/* TODO: handle raise_exception */
if (!raise_exception) return Qnil;
rb_raise(rb_eArgError,
"Unable to make a BigDecimal from non-zero imaginary number");
}
Expand Down
13 changes: 6 additions & 7 deletions test/bigdecimal/test_bigdecimal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,12 @@ def test_BigDecimal_with_exception_keyword
assert_nothing_raised(ArgumentError) {
assert_equal(nil, BigDecimal(4.2, Float::DIG + 2, exception: false))
}
# TODO: support conversion from complex
# assert_raise(RangeError) {
# BigDecimal(1i, exception: true)
# }
# assert_nothing_raised(RangeError) {
# assert_equal(nil, BigDecimal(1i, exception: false))
# }
assert_raise(ArgumentError) {
BigDecimal(1i, exception: true)
}
assert_nothing_raised(ArgumentError) {
assert_equal(nil, BigDecimal(1i, exception: false))
}
assert_raise_with_message(TypeError, "can't convert nil into BigDecimal") {
BigDecimal(nil, exception: true)
}
Expand Down