Project

General

Profile

Actions

Bug #1250

closed

String#to_r and String#to_c with float number

Added by phasis68 (Heesob Park) over 16 years ago. Updated about 14 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 1.9.1p0 (2009-01-30 revision 21907) [i686-linux]
Backport:
[ruby-core:22697]

Description

=begin
irb(main):001:0> "1/2".to_r
=> (1/2)
irb(main):002:0> "1.5/2".to_r
=> (3/4)
irb(main):003:0> "1.5/2.5".to_r
=> (3/4)
irb(main):004:0> "15/25".to_r
=> (3/5)

I think "1.5/2.5".to_r should be (3/5)

irb(main):013:0> "15/2.5+3/3i".to_c
=> ((15/2)+0i)
irb(main):015:0> "15/25+3/3.1i".to_c
=> ((3/5)+0i)
irb(main):016:0> "3/3.1i+15/25".to_c
=> ((1/1)+0i)
irb(main):017:0> "3/3i+15/25".to_c
=> (0+(1/1)*i)
Some unexpected results
=end

Actions #1

Updated by tadf (tadayoshi funaba) about 16 years ago

=begin
It's not a bug.

The parser accepts float form as numerator.
However, denominator is not.

main@191-20090130> Rational('1.5')
#=> (3/2)
main@191-20090130> Rational('1.5/1')
#=> (3/2)
main@191-20090130> Rational('1.5/2')
#=> (3/4)
main@191-20090130> Rational('1.5/2.5')
ArgumentError: invalid value for Rational: "1.5/2.5"
from (irb):4:in convert' from (irb):4:in Rational'
from (irb):4
from /usr/local/bin/irb191:12:in `'

=end

Actions #2

Updated by yugui (Yuki Sonoda) almost 16 years ago

  • Status changed from Open to Rejected

=begin

=end

Actions

Also available in: Atom PDF

Like0
Like0Like0