'0_2'.to_i

String#to_i e$B$,@5$7$/5!G=$7$J$$$3$H$,$"$j$^$9!#e(Bruby
e$B<+?H$N;z6g2r<a$H$be(B
e$B0c$$$^$9!#$?$V$s!"e(B1.8 e$B$bF1$8$G$9!#e(B

$ ./ruby -v -e ‘p “0_2”.to_i’
ruby 1.9.0 (2008-01-29 revision 0) [i386-freebsd6.2]
0

e$B$3$s$J46$8$G$7$g$&$+!#e(B

Index: bignum.c

— bignum.c (revision 15328)
+++ bignum.c (working copy)
@@ -438,7 +438,7 @@
len = 2;
break;
case 8:

  • if (str[0] == ‘0’ && (str[1] == ‘o’||str[1] == ‘O’||str[1] == ‘_’)) {
  • if (str[0] == ‘0’ && (str[1] == ‘o’||str[1] == ‘O’)) {
    str += 2;
    }
    case 4: case 5: case 6: case 7:
    @@ -470,7 +470,7 @@
    break;
    }
    if (str == ‘0’) { / squeeze preceding 0s */
  • while (*++str == ‘0’);
  • while (*++str == ‘0’ || *str == ‘_’);
    if (!(c = *str) || ISSPACE©) --str;
    }
    c = *str;
    Index: test/ruby/test_bignum.rb
    ===================================================================
    — test/ruby/test_bignum.rb (revision 15328)
    +++ test/ruby/test_bignum.rb (working copy)
    @@ -147,6 +147,9 @@
    assert_raise(ArgumentError) { Integer(“1__”) }
    assert_raise(ArgumentError) { Integer(“1_0 x”) }
    assert_equal(T31P, “1111111111111111111111111111111”.to_i(2))
  • assert_equal(0_2, ‘0_2’.to_i)
  • assert_equal(00_2, ‘00_2’.to_i)
  • assert_equal(00_02, ‘00_02’.to_i)
    end

def test_to_s2

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:33506] ‘0_2’.to_i”
on Tue, 29 Jan 2008 23:11:00 +0900, Tadayoshi F.
[email protected] writes:

|String#to_i e$B$,@5$7$/5!G=$7$J$$$3$H$,$"$j$^$9!#e(Bruby e$B<+?H$N;z6g2r<a$H$be(B
|e$B0c$$$^$9!#$?$V$s!"e(B1.8 e$B$bF1$8$G$9!#e(B

|e$B$3$s$J46$8$G$7$g$&$+!#e(B

|— bignum.c (revision 15328)
|+++ bignum.c (working copy)

e$B%3%_%C%H$7$F$/[email protected]$5$$!#[email protected]$7!"%F%9%H$rDI2C$9$k$N$Oe(B
test/ruby/test_integer.rbe$B$NJ}$,NI$$$+$b$7$l$^$;$s!#e(B

e$B%3%_%C%H$7$F$/[email protected]$5$$!#[email protected]$7!"%F%9%H$rDI2C$9$k$N$Oe(B
test/ruby/test_integer.rbe$B$NJ}$,NI$$$+$b$7$l$^$;$s!#e(B

test_integer e$B$K$O!“e(BInteger()
e$B$J$I$N%F%9%H$,$”$j$^$9$,!“e(BString#to_i e$B$Ke(B
e$B$D$$$F$O$J$5$=$&$G$9!#e(Btest_string.rb
e$B$+$J$H$b;W$C$?$s$G$9$,!”;w$?$h$&e(B
e$B$J%F%9%H$,J,;6$7$F$$$k$h$&$G$9!#e(B

e$B$h$/$o$+$i$J$+$C$?$N$G!"$=$N$^$^%3%_%C%H$7$^$7$?$,!"$h$/$J$+$C$?$i!"C/e(B
e$B$+D>$7$F$*$$$F$/[email protected]$5$$!#e(B

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs