NUM2xxx

e$B$U$He(B NUM2xxx e$B$,<u$1IU$1$kCM$NHO0O$rD4$Y$?$s$G$9$,!"e(Bunsigned
e$B$J$N$,Ii$NCM$r<u$1IU$1$k$N$C$F$=$&$$$&$b$N$J$s$G$7$?$C$1e(B?

int = long = 32bit, long long = 64bit e$B$J4D6-e(B
NUM2INT: -0x80000000 … 0x7fffffff
NUM2UINT: -0x7fffffff … 0xffffffff
NUM2LONG: -0x80000000 … 0x7fffffff
NUM2ULONG: -0x7fffffff … 0xffffffff
NUM2LL -0x8000000000000000 … 0x7fffffffffffffff
NUM2ULL -0xffffffffffffffff … 0xffffffffffffffff

int = 32bit, long = long long = 64bit (LP64) e$B$J4D6-e(B
NUM2INT: -0x80000000 … 0x7fffffff
NUM2UINT: -0x7fffffffffffffff … 0xffffffff
NUM2LONG: -0x8000000000000000 … 0x7fffffffffffffff
NUM2ULONG: -0x7fffffffffffffff … 0xffffffffffffffff
NUM2LL: -0x8000000000000000 … 0x7fffffffffffffff
NUM2ULL: -0xffffffffffffffff … 0xffffffffffffffff

e$B$H$/$K!"e(BLP64 e$B$G$Ne(B NUM2UINT e$B$,e(B -0x7fffffffffffffff
e$B$^$G<u$1IUe(B
e$B$1$k$N$O$+$J$jJQ$J5$$,$7$^$9!#e(B

e$B$J$*!"0J2<$N$h$&$K$7$Fe(B Ruby e$BB&$+$i8F$S=P$7$FD4$Y$^$7$?!#e(B

Index: object.c

— object.c (revision 15422)
+++ object.c (working copy)
@@ -2322,6 +2322,12 @@ boot_defclass(const char *name, VALUE su

  •                          +----------------+
    

*/

+static VALUE num2int(VALUE _, VALUE arg) { printf(“num2int:%d\n”,
NUM2INT(arg)); return Qnil; }
+static VALUE num2uint(VALUE _, VALUE arg) { printf(“num2int:%u\n”,
NUM2UINT(arg)); return Qnil; }
+static VALUE num2long(VALUE _, VALUE arg) { printf(“num2int:%ld\n”,
NUM2LONG(arg)); return Qnil; }
+static VALUE num2ulong(VALUE _, VALUE arg) { printf(“num2int:%lu\n”,
NUM2ULONG(arg)); return Qnil; }
+static VALUE num2ll(VALUE _, VALUE arg) { printf(“num2int:%lld\n”,
NUM2LL(arg)); return Qnil; }
+static VALUE num2ull(VALUE _, VALUE arg) { printf(“num2int:%llu\n”,
NUM2ULL(arg)); return Qnil; }

/*

  • BasicObject is the parent class of all classes in
    Ruby.
    @@ -2517,4 +2523,11 @@ Init_Object(void)
    id_match = rb_intern("=~");
    id_inspect = rb_intern(“inspect”);
    id_init_copy = rb_intern(“initialize_copy”);
  • rb_define_global_function(“NUM2INT”, num2int, 1);
  • rb_define_global_function(“NUM2UINT”, num2uint, 1);
  • rb_define_global_function(“NUM2LONG”, num2long, 1);
  • rb_define_global_function(“NUM2ULONG”, num2ulong, 1);
  • rb_define_global_function(“NUM2LL”, num2ll, 1);
  • rb_define_global_function(“NUM2ULL”, num2ull, 1);
    }

e$B$3$s$K$A$O!"$J$+$`$ie(B(e$B$&e(B)e$B$G$9!#e(B

In message “[ruby-dev:33683] NUM2xxx”
on Feb.10,2008 17:47:51, [email protected] wrote:

int = 32bit, long = long long = 64bit (LP64) e$B$J4D6-e(B
NUM2INT: -0x80000000 … 0x7fffffff
NUM2UINT: -0x7fffffffffffffff … 0xffffffff
NUM2LONG: -0x8000000000000000 … 0x7fffffffffffffff
NUM2ULONG: -0x7fffffffffffffff … 0xffffffffffffffff
NUM2LL: -0x8000000000000000 … 0x7fffffffffffffff
NUM2ULL: -0xffffffffffffffff … 0xffffffffffffffff

e$B$H$/$K!"e(BLP64 e$B$G$Ne(B NUM2UINT e$B$,e(B -0x7fffffffffffffff e$B$^$G<u$1IUe(B
e$B$1$k$N$O$+$J$jJQ$J5$$,$7$^$9!#e(B

e$B8E$$OC$G$9$,!“e(BIRCe$B$G;XE&$5$l$?$N$G9M$($F$_$^$7$?!#e(B
e$B$H$j$”$($:!"e(BNUM2U*e$B$,Ii$NCM$r<u$1IU$1$k$N$O$=$&$$$&[email protected]$H2>e(B
e$BDj$7$F!“e(BLP64e$B$Ne([email protected]$1BP:v$9$k$H!”$3$s$J$b$s$G$7$g$&$+e(B?

Index: numeric.c

— numeric.c (revision 17790)
+++ numeric.c (working copy)
@@ -1585,10 +1585,10 @@ check_int(SIGNED_VALUE num)
}

static void
-check_uint(VALUE num)
+check_uint(VALUE num, int sign)
{
if (num > UINT_MAX) {

  • rb_raise(rb_eRangeError, "integer %“PRIuVALUE " too big to convert to
    `unsigned int’”, num);
  • rb_raise(rb_eRangeError, "integer %“PRIuVALUE " too %s to convert to
    `unsigned int’”, sign ? “small” : “big”, num);
    }
    }

@@ -1615,9 +1615,7 @@ rb_num2uint(VALUE val)
{
unsigned long num = rb_num2ulong(val);

  • if (RTEST(rb_funcall(INT2FIX(0), ‘<’, 1, val))) {
  • check_uint(num);
  • }
  • check_uint(num, RTEST(val, ‘<’, 1, rb_funcall(INT2FIX(0))));
    return num;
    }

e$B$=$l$G$O!#e(B

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

In message “Re: [ruby-dev:35341] Re: NUM2xxx”
on Thu, 3 Jul 2008 21:34:31 +0900, “U.Nakamura”
[email protected] writes:

|In message “[ruby-dev:33683] NUM2xxx”
| on Feb.10,2008 17:47:51, [email protected] wrote:
|> e$B$U$He(B NUM2xxx e$B$,<u$1IU$1$kCM$NHO0O$rD4$Y$?$s$G$9$,!"e(Bunsigned
|> e$B$J$N$,Ii$NCM$r<u$1IU$1$k$N$C$F$=$&$$$&$b$N$J$s$G$7$?$C$1e(B?

|> e$B$H$/$K!"e(BLP64 e$B$G$Ne(B NUM2UINT e$B$,e(B -0x7fffffffffffffff e$B$^$G<u$1IUe(B
|> e$B$1$k$N$O$+$J$jJQ$J5$$,$7$^$9!#e(B
|
|e$B8E$$OC$G$9$,!“e(BIRCe$B$G;XE&$5$l$?$N$G9M$($F$_$^$7$?!#e(B
|e$B$H$j$”$($:!"e(BNUM2U*e$B$,Ii$NCM$r<u$1IU$1$k$N$O$=$&$$$&[email protected]$H2>e(B
|e$BDj$7$F!“e(BLP64e$B$Ne([email protected]$1BP:v$9$k$H!”$3$s$J$b$s$G$7$g$&$+e(B?

e$B$9$C$+$jK:$l$F$^$7$?!#e(B
NUM2Uxxxe$B$,Ii$NCM$r<u$1$$$l$k$N$O!"$J$s$+M}M3$,$"$C$?$h$&$J5$e(B
e$B$,$9$k$N$G!"$"$H$G9M$($k$H$7$Fe(B(e$B$C$F$^$?K:$l$=$&e(B)e$B!"e(BLP64e$B$N%Q%Ce(B
e$B%A$O%3%_%C%[email protected]$1$^$;$s$+!)e(B

e$B$3$s$K$A$O!"$J$+$`$ie(B(e$B$&e(B)e$B$G$9!#e(B

In message “[ruby-dev:35344] Re: NUM2xxx”
on Jul.04,2008 01:27:51, [email protected] wrote:
| |> e$B$H$/$K!"e(BLP64 e$B$G$Ne(B NUM2UINT e$B$,e(B -0x7fffffffffffffff e$B$^$G<u$1IUe(B
| |> e$B$1$k$N$O$+$J$jJQ$J5$$,$7$^$9!#e(B
| |
| |e$B8E$$OC$G$9$,!"e(BIRCe$B$G;XE&$5$l$?$N$G9M$($F$$^$7$?!#e(B
| |e$B$H$j$"$($:!“e(BNUM2U*e$B$,Ii$NCM$r<u$1IU$1$k$N$O$=$&$$$&[email protected]$H2>e(B
| |e$BDj$7$F!“e(BLP64e$B$Ne([email protected]$1BP:v$9$k$H!”$3$s$J$b$s$G$7$g$&$+e(B?
|
| e$B$9$C$+$jK:$l$F$^$7$?!#e(B
| NUM2Uxxxe$B$,Ii$NCM$r<u$1$$$l$k$N$O!”$J$s$+M}M3$,$"$C$?$h$&$J5$e(B
| e$B$,$9$k$N$G!"$"$H$G9M$($k$H$7$Fe(B(e$B$C$F$^$?K:$l$=$&e(B)e$B!"e(BLP64e$B$N%Q%Ce(B
| e$B%A$O%3%
%C%[email protected]$1$^$;$s$+!)e(B

[email protected]$KE:IU$7$?%Q%C%[email protected]$$$V4V0c$C$F$^$7$?$,e(B(e$B%3%s%Q%$%k3Ne(B
e$BG’A0$N;[email protected]$N$rE=$C$F$7$^$C$?e(B)e$B!"$=$l$bD>$7$F%3%_%C%H$7$^$7$?!#e(B

e$B%F%9%H$bF~$l$?$$$s$G$9$,!"$I$&[email protected]$m$&e(B?

e$B$=$l$G$O!#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