summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-12-01 08:42:53 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-12-01 08:42:53 +0000
commitb0acbc4c9afd41602ec9f4b0ee6914b4461ccd32 (patch)
tree81871465d730636c74a8ba04d080212f0acbf9ad /numeric.c
parent0f54ad5f6ce2a92e70854113c38d76a53a178ad2 (diff)
* pack.c (htov16): converts endian using swap16. htov32(), hton16,
hton32 as well. [ruby-talk:85377] * pack.c (swap16): swap 2 bytes no matter how big short is on the platform. swap32() is also prepared. * numeric.c (rb_num2int): returns long to preserve information. rb_fix2int(), rb_num2uint(), rb_fix2uint() as well. [ruby-talk:85377] * numeric.c (rb_num2uint): should not check for value range if the source value is negative. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5075 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c34
1 files changed, 21 insertions, 13 deletions
diff --git a/numeric.c b/numeric.c
index 7d373e4083..b030d8795a 100644
--- a/numeric.c
+++ b/numeric.c
@@ -1029,54 +1029,62 @@ check_uint(num)
}
}
-int
+long
rb_num2int(val)
VALUE val;
{
long num = rb_num2long(val);
check_int(num);
- return (int)num;
+ return num;
}
-int
+long
rb_fix2int(val)
VALUE val;
{
long num = FIXNUM_P(val)?FIX2LONG(val):rb_num2long(val);
check_int(num);
- return (int)num;
+ return num;
}
-unsigned int
+unsigned long
rb_num2uint(val)
VALUE val;
{
unsigned long num = rb_num2ulong(val);
- check_uint(num);
- return (int)num;
+ if (RTEST(rb_funcall(INT2FIX(0), '<', 1, val))) {
+ check_uint(num);
+ }
+ return num;
}
-unsigned int
+unsigned long
rb_fix2uint(val)
VALUE val;
{
- unsigned long num = FIXNUM_P(val)?FIX2LONG(val):rb_num2ulong(val);
+ unsigned long num;
- check_uint(num);
- return (int)num;
+ if (!FIXNUM_P(val)) {
+ return rb_num2uint(val);
+ }
+ num = FIX2ULONG(val);
+ if (FIX2LONG(val) > 0) {
+ check_uint(num);
+ }
+ return num;
}
#else
-int
+long
rb_num2int(val)
VALUE val;
{
return rb_num2long(val);
}
-int
+long
rb_fix2int(val)
VALUE val;
{