Project

General

Profile

Bug #11947

BigDecimal#coerce: unexpected behavior with Float

Added by lionel_perrin (Lionel PERRIN) about 5 years ago. Updated about 4 years ago.

Status:
Closed
Priority:
Normal
Target version:
-
[ruby-core:72702]

Description

I've noticed that:

BigDecimal('2') + 1   # => BigDecimal(3), OK
1 + BigDecimal('2')   # => BigDecimal(3), OK
# whereas
BigDecimal('2') + 1.1 # => BigDecimal(3.1), OK
1.1 + BigDecimal('2') # => Float(3.1), WHY?

I was expecting the latest to return a BigDecimal but it retuns a Float. In the unit tests for bigdecimal, one can find the following test:

assert_equal(2, 1 + BigDecimal.new("1"), '[ruby-core:25697]')

May be this behavior is required but I haven't found any reason for this.

Regards,

Lionel

Updated by mrkn (Kenta Murata) about 5 years ago

  • Status changed from Open to Assigned
  • Assignee set to mrkn (Kenta Murata)

Updated by mrkn (Kenta Murata) about 4 years ago

  • Status changed from Assigned to Closed

This fixed on the current master branch of ruby/bigdecimal repository.
So I close this issue.

Also available in: Atom PDF