Project

General

Profile

Actions

Bug #12780

closed

Updated by noahgibbs (Noah Gibbs) over 8 years ago

The Japanese issue appears to be saying that there's a problem in RubySpec that will need to be fixed, and that fixing it is a problem with (I think?) early 1.9 compatibility.

Updated by shyouhei (Shyouhei Urabe) over 8 years ago

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

Updated by mrkn (Kenta Murata) over 8 years ago

Float#round returns Fixnum value when the argument is 0 or omitted.

irb(main):005:0> 12.34.round.class
=> Fixnum
irb(main):006:0> 12.34.round(0).class
=> Fixnum

If we will fix BigDecimal#round, we should change the return value for the case of the argument 0 is supplied.

Updated by Gat (Dawid Janczak) over 8 years ago

Good point, I didn't catch that. If it was up to me I'd rather have Float#round always return Float as well for consistency. I could work on a for that too if you agree.

Updated by mrkn (Kenta Murata) over 8 years ago

We need matz's approval to change Float#round.

Updated by mrkn (Kenta Murata) over 8 years ago

  • Assignee changed from mrkn (Kenta Murata) to matz (Yukihiro Matsumoto)

Updated by shyouhei (Shyouhei Urabe) over 8 years ago

We (mainly mrkn and matz) discussed why Fixnum#round returns Integer today. The answer is because (unlike other languages, namely C's round(3)) in ruby we can safely store all possible return value that round can theoretically generate, in Integer.

BigDecimal#round's returning BigDecimal instance sounds nice. But matz said he need to think a while for this historic Float behaviour.

Updated by mrkn (Kenta Murata) about 8 years ago

  • Related to : Integer#{round,floor,ceil,truncate} should always return an integer, not a float added

Updated by matz (Yukihiro Matsumoto) over 5 years ago

#round with the argument less than 1 (n < 1) should return Integer value.

Matz.

Updated by jeremyevans0 (Jeremy Evans) almost 5 years ago

  • Assignee changed from matz (Yukihiro Matsumoto) to mrkn (Kenta Murata)

matz (Yukihiro Matsumoto) wrote in #note-9:

#round with the argument less than 1 (n < 1) should return Integer value.

I've submitted a pull request that implements this: https://.com/ruby/bigdecimal/pull/170

Updated by jeremyevans0 (Jeremy Evans) over 4 years ago

  • Status changed from Assigned to Closed
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0