Project

General

Profile

Actions

Bug #10569

closed

BigDecimal#fix returns a BigDecimal object instead of a Integer

Added by jjconti (Juanjo Conti) about 10 years ago. Updated about 10 years ago.

Status:
Rejected
Target version:
-
ruby -v:
ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-darwin13.0]
[ruby-core:66689]

Description

According docs (http://www.ruby-doc.org/stdlib-2.1.5/libdoc/bigdecimal/rdoc/BigDecimal.html#method-i-fix): fix method return the integer part of the number. But it's returning a BugDecimal:

a = BigDecimal(7)
=> #BigDecimal:7fb18015e698,'0.7E1',9(27)
a.fix
=> #BigDecimal:7fb180185d38,'0.7E1',9(18)
a.fix.to_i
=> 7

Similar problem happens with frac method.

Updated by jjconti (Juanjo Conti) about 10 years ago

BigDecimal, sorry for the typo :)

I'm pasting again the example because some chars were deleted in the original report:

a = BigDecimal(7)
=> #<BigDecimal:7fb18015e698,'0.7E1',9(27)>
a.fix
=> #<BigDecimal:7fb180185d38,'0.7E1',9(18)>
a.fix.to_i
=> 7

Updated by jjconti (Juanjo Conti) about 10 years ago

Seems that Python works the same way. Probably is not a bug:

>>> decimal.Decimal(7).imag
Decimal('0')
>>> decimal.Decimal(7).real
Decimal('7')

Updated by nobu (Nobuyoshi Nakada) about 10 years ago

  • Status changed from Open to Rejected

It returns the integer part as a BigDecimal.

Updated by stomar (Marcus Stollsteimer) about 10 years ago

I submitted a patch that clarifies the documentation accordingly, see issue #10576 (and provides some additional improvements).

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0