Integrate Fixnum class into Integer class

* The `Fixnum` constant is now an alias for the `Integer` class.
* Remove `struct mrb_state::fixnum_class` member.
  If necessary, use `struct mrb_state::integer_class` instead.
This commit is contained in:
dearblue
2020-01-19 09:48:14 +09:00
committed by Yukihiro "Matz" Matsumoto
parent 40d0d8fe0e
commit 80fe9838d2
31 changed files with 99 additions and 99 deletions
+1 -1
View File
@@ -17,7 +17,7 @@ Please help to improve it by submitting your findings.
## `1/2` gives `0.5`
Since mruby does not have `Bignum`, bigger integers are represented
by `Float` numbers. To enhance interoperability between `Fixnum`
by `Float` numbers. To enhance interoperability between `Integer`
and `Float`, mruby provides `Float#upto` and other iterating
methods for the `Float` class. As a side effect, `1/2` gives `0.5`
not `0`.
+3 -3
View File
@@ -248,7 +248,7 @@ typedef struct mrb_state {
#ifndef MRB_NO_FLOAT
struct RClass *float_class;
#endif
struct RClass *fixnum_class;
struct RClass *integer_class;
struct RClass *true_class;
struct RClass *false_class;
struct RClass *nil_class;
@@ -890,8 +890,8 @@ MRB_API struct RClass* mrb_define_module_under_id(mrb_state *mrb, struct RClass
* | `s` | {String} | const char *, {mrb_int} | Receive two arguments; `s!` gives (`NULL`,`0`) for `nil` |
* | `z` | {String} | const char * | `NULL` terminated string; `z!` gives `NULL` for `nil` |
* | `a` | {Array} | {mrb_value} *, {mrb_int} | Receive two arguments; `a!` gives (`NULL`,`0`) for `nil` |
* | `f` | {Fixnum}/{Float} | {mrb_float} | |
* | `i` | {Fixnum}/{Float} | {mrb_int} | |
* | `f` | {Integer}/{Float} | {mrb_float} | |
* | `i` | {Integer}/{Float} | {mrb_int} | |
* | `b` | boolean | {mrb_bool} | |
* | `n` | {String}/{Symbol} | {mrb_sym} | |
* | `d` | data | void *, {mrb_data_type} const | 2nd argument will be used to check data type so it won't be modified; when `!` follows, the value may be `nil` |
+1 -1
View File
@@ -36,7 +36,7 @@ mrb_class(mrb_state *mrb, mrb_value v)
case MRB_TT_SYMBOL:
return mrb->symbol_class;
case MRB_TT_FIXNUM:
return mrb->fixnum_class;
return mrb->integer_class;
#ifndef MRB_NO_FLOAT
case MRB_TT_FLOAT:
return mrb->float_class;
+2 -2
View File
@@ -1,5 +1,5 @@
/**
** @file mruby/numeric.h - Numeric, Integer, Float, Fixnum class
** @file mruby/numeric.h - Numeric, Integer, Float class
**
** See Copyright Notice in mruby.h
*/
@@ -12,7 +12,7 @@
/**
* Numeric class and it's sub-classes.
*
* Integer, Float and Fixnum
* Integer and Float
*/
MRB_BEGIN_DECL
+1 -1
View File
@@ -104,7 +104,7 @@ class Complex < Numeric
alias_method :imag, :imaginary
[Fixnum, Float].each do |cls|
[Integer, Float].each do |cls|
[:+, :-, :*, :/, :==].each do |op|
cls.instance_eval do
original_operator_name = :"__original_operator_#{op}_complex"
+1 -1
View File
@@ -2,7 +2,7 @@ class File < IO
attr_accessor :path
def initialize(fd_or_path, mode = "r", perm = 0666)
if fd_or_path.kind_of? Fixnum
if fd_or_path.kind_of? Integer
super(fd_or_path, mode)
else
@path = fd_or_path
+2 -2
View File
@@ -186,7 +186,7 @@ class IO
def read(length = nil, outbuf = "")
unless length.nil?
unless length.is_a? Fixnum
unless length.is_a? Integer
raise TypeError.new "can't convert #{length.class} into Integer"
end
if length < 0
@@ -229,7 +229,7 @@ class IO
case arg
when String
rs = arg
when Fixnum
when Integer
rs = "\n"
limit = arg
else
+2 -2
View File
@@ -7,7 +7,7 @@ $cr, $crlf, $cmd = MRubyIOTestUtil.win? ? [1, "\r\n", "cmd /c "] : [0, "\n", ""]
def assert_io_open(meth)
assert "assert_io_open" do
fd = IO.sysopen($mrbtest_io_rfname)
assert_equal Fixnum, fd.class
assert_equal Integer, fd.class
io1 = IO.__send__(meth, fd)
begin
assert_equal IO, io1.class
@@ -433,7 +433,7 @@ assert('IO.popen') do
$? = nil
io = IO.popen("#{$cmd}echo mruby-io")
assert_true io.close_on_exec?
assert_equal Fixnum, io.pid.class
assert_equal Integer, io.pid.class
out = io.read
assert_equal out.class, String
+1 -1
View File
@@ -84,7 +84,7 @@ mrb_f_method(mrb_state *mrb, mrb_value self)
* call-seq:
* Integer(arg,base=0) -> integer
*
* Converts <i>arg</i> to a <code>Fixnum</code>.
* Converts <i>arg</i> to a <code>Integer</code>.
* Numeric types are converted directly (with floating point numbers
* being truncated). <i>base</i> (0, or between 2 and 36) is a base for
* integer string representation. If <i>arg</i> is a <code>String</code>,
+1 -1
View File
@@ -629,7 +629,7 @@ math_cbrt(mrb_state *mrb, mrb_value obj)
* Math.frexp(numeric) -> [ fraction, exponent ]
*
* Returns a two-element array containing the normalized fraction (a
* <code>Float</code>) and exponent (a <code>Fixnum</code>) of
* <code>Float</code>) and exponent (a <code>Integer</code>) of
* <i>numeric</i>.
*
* fraction, exponent = Math.frexp(1234) #=> [0.6025390625, 11]
+4 -4
View File
@@ -395,15 +395,15 @@ end
assert('alias_method and remove_method') do
begin
Fixnum.alias_method :to_s_, :to_s
Fixnum.remove_method :to_s
Integer.alias_method :to_s_, :to_s
Integer.remove_method :to_s
assert_nothing_raised do
# segfaults if mrb_cptr is used
1.to_s
end
ensure
Fixnum.alias_method :to_s, :to_s_
Fixnum.remove_method :to_s_
Integer.alias_method :to_s, :to_s_
Integer.remove_method :to_s_
end
end
+4 -4
View File
@@ -77,7 +77,7 @@ end
assert 'instance' do
assert_kind_of Method, 1.method(:+)
assert_kind_of UnboundMethod, Fixnum.instance_method(:+)
assert_kind_of UnboundMethod, Integer.instance_method(:+)
end
assert 'Method#call' do
@@ -404,9 +404,9 @@ assert 'UnboundMethod#arity' do
end
assert 'UnboundMethod#==' do
assert_false(Fixnum.instance_method(:+) == Fixnum.instance_method(:-))
assert_true(Fixnum.instance_method(:+) == Fixnum.instance_method(:+))
assert_false(Fixnum.instance_method(:+) == Float.instance_method(:+))
assert_false(Integer.instance_method(:+) == Integer.instance_method(:-))
assert_true(Integer.instance_method(:+) == Integer.instance_method(:+))
assert_false(Integer.instance_method(:+) == Float.instance_method(:+))
assert_true(UnboundMethod.instance_method(:==) == UnboundMethod.instance_method(:eql?))
end
+4 -4
View File
@@ -290,7 +290,7 @@ unpack_l(mrb_state *mrb, const unsigned char *src, int srclen, mrb_value ary, un
#ifndef MRB_INT64
if (!FIXABLE(sl)) {
i32tostr(msg, sizeof(msg), sl);
mrb_raisef(mrb, E_RANGE_ERROR, "cannot unpack to Fixnum: %s", msg);
mrb_raisef(mrb, E_RANGE_ERROR, "cannot unpack to Integer: %s", msg);
}
#endif
n = sl;
@@ -298,7 +298,7 @@ unpack_l(mrb_state *mrb, const unsigned char *src, int srclen, mrb_value ary, un
#ifndef MRB_INT64
if (!POSFIXABLE(ul)) {
u32tostr(msg, sizeof(msg), ul);
mrb_raisef(mrb, E_RANGE_ERROR, "cannot unpack to Fixnum: %s", msg);
mrb_raisef(mrb, E_RANGE_ERROR, "cannot unpack to Integer: %s", msg);
}
#endif
n = ul;
@@ -411,13 +411,13 @@ unpack_q(mrb_state *mrb, const unsigned char *src, int srclen, mrb_value ary, un
int64_t sll = ull;
if (!FIXABLE(sll)) {
i64tostr(msg, sizeof(msg), sll);
mrb_raisef(mrb, E_RANGE_ERROR, "cannot unpack to Fixnum: %s", msg);
mrb_raisef(mrb, E_RANGE_ERROR, "cannot unpack to Integer: %s", msg);
}
n = (mrb_int)sll;
} else {
if (!POSFIXABLE(ull)) {
u64tostr(msg, sizeof(msg), ull);
mrb_raisef(mrb, E_RANGE_ERROR, "cannot unpack to Fixnum: %s", msg);
mrb_raisef(mrb, E_RANGE_ERROR, "cannot unpack to Integer: %s", msg);
}
n = (mrb_int)ull;
}
+2 -2
View File
@@ -32,8 +32,8 @@ assert("Random.srand") do
end
assert("return class of Kernel.rand") do
assert_kind_of(Fixnum, rand(3))
assert_kind_of(Fixnum, rand(1.5))
assert_kind_of(Integer, rand(3))
assert_kind_of(Integer, rand(1.5))
assert_kind_of(Float, rand)
assert_kind_of(Float, rand(0.5))
end
+1 -1
View File
@@ -33,7 +33,7 @@ class Range
# fast path for numerics
if val.kind_of?(Numeric) && last.kind_of?(Numeric)
raise TypeError if exclude_end? && !last.kind_of?(Fixnum)
raise TypeError if exclude_end? && !last.kind_of?(Integer)
return nil if val > last
return nil if val == last && exclude_end?
+1 -1
View File
@@ -92,7 +92,7 @@ module Kernel
[:+, :-, :*, :/, :<=>, :==, :<, :<=, :>, :>=].each do |op|
original_operator_name = :"__original_operator_#{op}_rational"
Fixnum.instance_eval do
Integer.instance_eval do
alias_method original_operator_name, op
define_method op do |rhs|
if rhs.is_a? Rational
+1 -1
View File
@@ -200,7 +200,7 @@ void mrb_mruby_rational_gem_init(mrb_state *mrb)
mrb_define_method(mrb, rat, "to_i", rational_to_i, MRB_ARGS_NONE());
mrb_define_method(mrb, rat, "to_r", rational_to_r, MRB_ARGS_NONE());
mrb_define_method(mrb, rat, "negative?", rational_negative_p, MRB_ARGS_NONE());
mrb_define_method(mrb, mrb->fixnum_class, "to_r", fix_to_r, MRB_ARGS_NONE());
mrb_define_method(mrb, mrb->integer_class, "to_r", fix_to_r, MRB_ARGS_NONE());
}
void
+6 -6
View File
@@ -143,7 +143,7 @@ assert 'Rational#==, Rational#!=' do
assert_equal_rational(false, 1r, ComplexLikeNumeric.new(2))
end
assert 'Fixnum#==(Rational), Fixnum#!=(Rational)' do
assert 'Integer#==(Rational), Integer#!=(Rational)' do
assert_equal_rational(true, 2, Rational(4,2))
assert_equal_rational(true, -2, Rational(-4,2))
assert_equal_rational(true, -2, Rational(4,-2))
@@ -186,7 +186,7 @@ assert 'Rational#<=>' do
assert_raise(NoMethodError) { 1r <=> ComplexLikeNumeric.new(2) }
end
assert 'Fixnum#<=>(Rational)' do
assert 'Integer#<=>(Rational)' do
assert_cmp(-1, -2, Rational(-9,5))
assert_cmp(0, 5, 5r)
assert_cmp(1, 3, Rational(8,3))
@@ -210,7 +210,7 @@ assert 'Rational#<' do
assert_raise(ArgumentError) { 1r < "2" }
end
assert 'Fixnum#<(Rational)' do
assert 'Integer#<(Rational)' do
assert_not_operator(1, :<, Rational(2,3))
assert_not_operator(2, :<, 2r)
assert_operator(-3, :<, Rational(2,3))
@@ -234,7 +234,7 @@ assert 'Rational#<=' do
assert_raise(ArgumentError) { 1r <= "2" }
end
assert 'Fixnum#<=(Rational)' do
assert 'Integer#<=(Rational)' do
assert_not_operator(1, :<=, Rational(2,3))
assert_operator(2, :<=, 2r)
assert_operator(-3, :<=, Rational(2,3))
@@ -258,7 +258,7 @@ assert 'Rational#>' do
assert_raise(ArgumentError) { 1r > "2" }
end
assert 'Fixnum#>(Rational)' do
assert 'Integer#>(Rational)' do
assert_operator(1, :>, Rational(2,3))
assert_not_operator(2, :>, 2r)
assert_not_operator(-3, :>, Rational(2,3))
@@ -282,7 +282,7 @@ assert 'Rational#>=' do
assert_raise(ArgumentError) { 1r >= "2" }
end
assert 'Fixnum#>=(Rational)' do
assert 'Integer#>=(Rational)' do
assert_operator(1, :>=, Rational(2,3))
assert_operator(2, :>=, 2r)
assert_not_operator(-3, :>=, Rational(2,3))
+1 -1
View File
@@ -145,7 +145,7 @@ mrb_addrinfo_getaddrinfo(mrb_state *mrb, mrb_value klass)
} else if (mrb_nil_p(service)) {
servname = NULL;
} else {
mrb_raise(mrb, E_TYPE_ERROR, "service must be String, Fixnum, or nil");
mrb_raise(mrb, E_TYPE_ERROR, "service must be String, Integer, or nil");
}
memset(&hints, 0, sizeof(hints));
+2 -2
View File
@@ -604,8 +604,8 @@ mrb_struct_eql(mrb_state *mrb, mrb_value s)
/*
* call-seq:
* struct.length -> Fixnum
* struct.size -> Fixnum
* struct.length -> Integer
* struct.size -> Integer
*
* Returns number of struct members.
*/
+1 -1
View File
@@ -15,7 +15,7 @@ class Range
val = self.first
last = self.last
if val.kind_of?(Fixnum) && last.kind_of?(Fixnum) # fixnums are special
if val.kind_of?(Integer) && last.kind_of?(Integer) # fixnums are special
lim = last
lim += 1 unless exclude_end?
i = val
+3 -3
View File
@@ -638,8 +638,8 @@ void mrb_hash_check_kdict(mrb_state *mrb, mrb_value self);
z: String [const char*] NUL terminated string; z! gives NULL for nil
a: Array [mrb_value*,mrb_int] Receive two arguments; a! gives (NULL,0) for nil
c: Class/Module [strcut RClass*]
f: Fixnum/Float [mrb_float]
i: Fixnum/Float [mrb_int]
f: Integer/Float [mrb_float]
i: Integer/Float [mrb_int]
b: boolean [mrb_bool]
n: String/Symbol [mrb_sym]
d: data [void*,mrb_data_type const] 2nd argument will be used to check data type so it won't be modified; when ! follows, the value may be nil
@@ -1874,7 +1874,7 @@ mrb_module_new(mrb_state *mrb)
* called with an explicit receiver, as <code>class</code> is also a
* reserved word in Ruby.
*
* 1.class #=> Fixnum
* 1.class #=> Integer
* self.class #=> Object
*/
+1 -1
View File
@@ -932,7 +932,7 @@ root_scan_phase(mrb_state *mrb, mrb_gc *gc)
#ifndef MRB_NO_FLOAT
mrb_gc_mark(mrb, (struct RBasic*)mrb->float_class);
#endif
mrb_gc_mark(mrb, (struct RBasic*)mrb->fixnum_class);
mrb_gc_mark(mrb, (struct RBasic*)mrb->integer_class);
mrb_gc_mark(mrb, (struct RBasic*)mrb->true_class);
mrb_gc_mark(mrb, (struct RBasic*)mrb->false_class);
mrb_gc_mark(mrb, (struct RBasic*)mrb->nil_class);
+4 -4
View File
@@ -209,7 +209,7 @@ mrb_f_block_given_p_m(mrb_state *mrb, mrb_value self)
* called with an explicit receiver, as <code>class</code> is also a
* reserved word in Ruby.
*
* 1.class #=> Fixnum
* 1.class #=> Integer
* self.class #=> Object
*/
static mrb_value
@@ -341,7 +341,7 @@ init_copy(mrb_state *mrb, mrb_value dest, mrb_value obj)
* behavior will be documented under the #+initialize_copy+ method of
* the class.
*
* Some Class(True False Nil Symbol Fixnum Float) Object cannot clone.
* Some Class(True False Nil Symbol Integer Float) Object cannot clone.
*/
MRB_API mrb_value
mrb_obj_clone(mrb_state *mrb, mrb_value self)
@@ -480,11 +480,11 @@ mrb_obj_frozen(mrb_state *mrb, mrb_value self)
* call-seq:
* obj.hash -> fixnum
*
* Generates a <code>Fixnum</code> hash value for this object. This
* Generates a <code>Integer</code> hash value for this object. This
* function must have the property that <code>a.eql?(b)</code> implies
* <code>a.hash == b.hash</code>. The hash value is used by class
* <code>Hash</code>. Any hash value that exceeds the capacity of a
* <code>Fixnum</code> will be truncated before being used.
* <code>Integer</code> will be truncated before being used.
*/
static mrb_value
mrb_obj_hash(mrb_state *mrb, mrb_value self)
+39 -39
View File
@@ -1,5 +1,5 @@
/*
** numeric.c - Numeric, Integer, Float, Fixnum class
** numeric.c - Numeric, Integer, Float class
**
** See Copyright Notice in mruby.h
*/
@@ -378,7 +378,7 @@ flo_mod(mrb_state *mrb, mrb_value x)
* (1.0).eql?(1.0) #=> true
*/
static mrb_value
fix_eql(mrb_state *mrb, mrb_value x)
int_eql(mrb_state *mrb, mrb_value x)
{
mrb_value y = mrb_get_arg1(mrb);
@@ -771,8 +771,7 @@ flo_nan_p(mrb_state *mrb, mrb_value num)
/*
* Document-class: Integer
*
* <code>Integer</code> is the basis for the two concrete classes that
* hold whole numbers, <code>Bignum</code> and <code>Fixnum</code>.
* <code>Integer</code> is hold whole numbers.
*
*/
@@ -842,7 +841,7 @@ mrb_num_mul(mrb_state *mrb, mrb_value x, mrb_value y)
*/
static mrb_value
fix_mul(mrb_state *mrb, mrb_value x)
int_mul(mrb_state *mrb, mrb_value x)
{
mrb_value y = mrb_get_arg1(mrb);
@@ -888,7 +887,7 @@ fixdivmod(mrb_state *mrb, mrb_int x, mrb_int y, mrb_int *divp, mrb_int *modp)
*/
static mrb_value
fix_mod(mrb_state *mrb, mrb_value x)
int_mod(mrb_state *mrb, mrb_value x)
{
mrb_value y = mrb_get_arg1(mrb);
mrb_int a, b;
@@ -929,7 +928,7 @@ fix_mod(mrb_state *mrb, mrb_value x)
* See <code>Numeric#divmod</code>.
*/
static mrb_value
fix_divmod(mrb_state *mrb, mrb_value x)
int_divmod(mrb_state *mrb, mrb_value x)
{
mrb_value y = mrb_get_arg1(mrb);
@@ -992,7 +991,7 @@ flo_divmod(mrb_state *mrb, mrb_value x)
*/
static mrb_value
fix_equal(mrb_state *mrb, mrb_value x)
int_equal(mrb_state *mrb, mrb_value x)
{
mrb_value y = mrb_get_arg1(mrb);
@@ -1020,7 +1019,7 @@ fix_equal(mrb_state *mrb, mrb_value x)
*/
static mrb_value
fix_rev(mrb_state *mrb, mrb_value num)
int_rev(mrb_state *mrb, mrb_value num)
{
mrb_int val = mrb_fixnum(num);
@@ -1050,7 +1049,7 @@ static mrb_value flo_xor(mrb_state *mrb, mrb_value x);
*/
static mrb_value
fix_and(mrb_state *mrb, mrb_value x)
int_and(mrb_state *mrb, mrb_value x)
{
mrb_value y = mrb_get_arg1(mrb);
@@ -1066,7 +1065,7 @@ fix_and(mrb_state *mrb, mrb_value x)
*/
static mrb_value
fix_or(mrb_state *mrb, mrb_value x)
int_or(mrb_state *mrb, mrb_value x)
{
mrb_value y = mrb_get_arg1(mrb);
@@ -1082,7 +1081,7 @@ fix_or(mrb_state *mrb, mrb_value x)
*/
static mrb_value
fix_xor(mrb_state *mrb, mrb_value x)
int_xor(mrb_state *mrb, mrb_value x)
{
mrb_value y = mrb_get_arg1(mrb);
@@ -1160,7 +1159,7 @@ rshift(mrb_int val, mrb_int width)
*/
static mrb_value
fix_lshift(mrb_state *mrb, mrb_value x)
int_lshift(mrb_state *mrb, mrb_value x)
{
mrb_int width, val;
@@ -1185,7 +1184,7 @@ fix_lshift(mrb_state *mrb, mrb_value x)
*/
static mrb_value
fix_rshift(mrb_state *mrb, mrb_value x)
int_rshift(mrb_state *mrb, mrb_value x)
{
mrb_int width, val;
@@ -1212,7 +1211,7 @@ fix_rshift(mrb_state *mrb, mrb_value x)
#ifndef MRB_NO_FLOAT
static mrb_value
fix_to_f(mrb_state *mrb, mrb_value num)
int_to_f(mrb_state *mrb, mrb_value num)
{
return mrb_float_value(mrb, (mrb_float)mrb_fixnum(num));
}
@@ -1305,7 +1304,7 @@ mrb_num_plus(mrb_state *mrb, mrb_value x, mrb_value y)
* result.
*/
static mrb_value
fix_plus(mrb_state *mrb, mrb_value self)
int_plus(mrb_state *mrb, mrb_value self)
{
mrb_value other = mrb_get_arg1(mrb);
@@ -1362,7 +1361,7 @@ mrb_num_minus(mrb_state *mrb, mrb_value x, mrb_value y)
* result.
*/
static mrb_value
fix_minus(mrb_state *mrb, mrb_value self)
int_minus(mrb_state *mrb, mrb_value self)
{
mrb_value other = mrb_get_arg1(mrb);
@@ -1419,7 +1418,7 @@ mrb_fixnum_to_str(mrb_state *mrb, mrb_value x, mrb_int base)
*
*/
static mrb_value
fix_to_s(mrb_state *mrb, mrb_value self)
int_to_s(mrb_state *mrb, mrb_value self)
{
mrb_int base = 10;
@@ -1599,7 +1598,7 @@ flo_plus(mrb_state *mrb, mrb_value x)
void
mrb_init_numeric(mrb_state *mrb)
{
struct RClass *numeric, *integer, *fixnum, *integral;
struct RClass *numeric, *integer, *integral;
#ifndef MRB_NO_FLOAT
struct RClass *fl;
#endif
@@ -1622,7 +1621,7 @@ mrb_init_numeric(mrb_state *mrb)
mrb_define_method(mrb, numeric, "infinite?",num_infinite_p, MRB_ARGS_NONE());
/* Integer Class */
integer = mrb_define_class(mrb, "Integer", numeric); /* 15.2.8 */
mrb->integer_class = integer = mrb_define_class(mrb, "Integer", numeric); /* 15.2.8 */
MRB_SET_INSTANCE_TT(integer, MRB_TT_FIXNUM);
mrb_undef_class_method(mrb, integer, "new");
mrb_define_method(mrb, integer, "to_i", int_to_i, MRB_ARGS_NONE()); /* 15.2.8.3.24 */
@@ -1634,26 +1633,27 @@ mrb_init_numeric(mrb_state *mrb)
mrb_define_method(mrb, integer, "truncate", int_to_i, MRB_ARGS_NONE()); /* 15.2.8.3.15 (x) */
#endif
/* Fixnum Class */
mrb->fixnum_class = fixnum = mrb_define_class(mrb, "Fixnum", integer);
mrb_define_method(mrb, fixnum, "+", fix_plus, MRB_ARGS_REQ(1)); /* 15.2.8.3.1 */
mrb_define_method(mrb, fixnum, "-", fix_minus, MRB_ARGS_REQ(1)); /* 15.2.8.3.2 */
mrb_define_method(mrb, fixnum, "*", fix_mul, MRB_ARGS_REQ(1)); /* 15.2.8.3.3 */
mrb_define_method(mrb, fixnum, "%", fix_mod, MRB_ARGS_REQ(1)); /* 15.2.8.3.5 */
mrb_define_method(mrb, fixnum, "==", fix_equal, MRB_ARGS_REQ(1)); /* 15.2.8.3.7 */
mrb_define_method(mrb, fixnum, "~", fix_rev, MRB_ARGS_NONE()); /* 15.2.8.3.8 */
mrb_define_method(mrb, fixnum, "&", fix_and, MRB_ARGS_REQ(1)); /* 15.2.8.3.9 */
mrb_define_method(mrb, fixnum, "|", fix_or, MRB_ARGS_REQ(1)); /* 15.2.8.3.10 */
mrb_define_method(mrb, fixnum, "^", fix_xor, MRB_ARGS_REQ(1)); /* 15.2.8.3.11 */
mrb_define_method(mrb, fixnum, "<<", fix_lshift, MRB_ARGS_REQ(1)); /* 15.2.8.3.12 */
mrb_define_method(mrb, fixnum, ">>", fix_rshift, MRB_ARGS_REQ(1)); /* 15.2.8.3.13 */
mrb_define_method(mrb, fixnum, "eql?", fix_eql, MRB_ARGS_REQ(1)); /* 15.2.8.3.16 */
#ifndef MRB_NO_FLOAT
mrb_define_method(mrb, fixnum, "to_f", fix_to_f, MRB_ARGS_NONE()); /* 15.2.8.3.23 */
mrb_define_method(mrb, integer, "+", int_plus, MRB_ARGS_REQ(1)); /* 15.2.8.3.1 */
mrb_define_method(mrb, integer, "-", int_minus, MRB_ARGS_REQ(1)); /* 15.2.8.3.2 */
mrb_define_method(mrb, integer, "*", int_mul, MRB_ARGS_REQ(1)); /* 15.2.8.3.3 */
mrb_define_method(mrb, integer, "%", int_mod, MRB_ARGS_REQ(1)); /* 15.2.8.3.5 */
mrb_define_method(mrb, integer, "==", int_equal, MRB_ARGS_REQ(1)); /* 15.2.8.3.7 */
mrb_define_method(mrb, integer, "~", int_rev, MRB_ARGS_NONE()); /* 15.2.8.3.8 */
mrb_define_method(mrb, integer, "&", int_and, MRB_ARGS_REQ(1)); /* 15.2.8.3.9 */
mrb_define_method(mrb, integer, "|", int_or, MRB_ARGS_REQ(1)); /* 15.2.8.3.10 */
mrb_define_method(mrb, integer, "^", int_xor, MRB_ARGS_REQ(1)); /* 15.2.8.3.11 */
mrb_define_method(mrb, integer, "<<", int_lshift, MRB_ARGS_REQ(1)); /* 15.2.8.3.12 */
mrb_define_method(mrb, integer, ">>", int_rshift, MRB_ARGS_REQ(1)); /* 15.2.8.3.13 */
mrb_define_method(mrb, integer, "eql?", int_eql, MRB_ARGS_REQ(1)); /* 15.2.8.3.16 */
#ifndef MRB_WITHOUT_FLOAT
mrb_define_method(mrb, integer, "to_f", int_to_f, MRB_ARGS_NONE()); /* 15.2.8.3.23 */
#endif
mrb_define_method(mrb, fixnum, "to_s", fix_to_s, MRB_ARGS_OPT(1)); /* 15.2.8.3.25 */
mrb_define_method(mrb, fixnum, "inspect", fix_to_s, MRB_ARGS_OPT(1));
mrb_define_method(mrb, fixnum, "divmod", fix_divmod, MRB_ARGS_REQ(1)); /* 15.2.8.3.30 (x) */
mrb_define_method(mrb, integer, "to_s", int_to_s, MRB_ARGS_OPT(1)); /* 15.2.8.3.25 */
mrb_define_method(mrb, integer, "inspect", int_to_s, MRB_ARGS_OPT(1));
mrb_define_method(mrb, integer, "divmod", int_divmod, MRB_ARGS_REQ(1)); /* 15.2.8.3.30 (x) */
/* Fixnum Class for compatibility */
mrb_define_const(mrb, mrb->object_class, "Fixnum", mrb_obj_value(integer));
#ifndef MRB_NO_FLOAT
/* Float Class */
+3 -3
View File
@@ -1186,7 +1186,7 @@ range_arg:
break;
}
mrb_raise(mrb, E_TYPE_ERROR, "can't convert to Fixnum");
mrb_raise(mrb, E_TYPE_ERROR, "can't convert to Integer");
}
}
return STR_OUT_OF_RANGE;
@@ -1230,8 +1230,8 @@ mrb_str_aref(mrb_state *mrb, mrb_value str, mrb_value indx, mrb_value alen)
* str.slice(range) => new_str or nil
* str.slice(other_str) => new_str or nil
*
* Element Reference---If passed a single <code>Fixnum</code>, returns the code
* of the character at that position. If passed two <code>Fixnum</code>
* Element Reference---If passed a single <code>Integer</code>, returns the code
* of the character at that position. If passed two <code>Integer</code>
* objects, returns a substring starting at the offset given by the first, and
* a length given by the second. If given a range, a substring containing
* characters at offsets given by the range is returned. In all three cases, if
+1 -1
View File
@@ -34,5 +34,5 @@ assert('BS Literal 8') do
end
assert('BS Literal 9') do
assert_equal Fixnum, 1234.class
assert_equal Integer, 1234.class
end
+1 -1
View File
@@ -156,7 +156,7 @@ assert('Integer#<<', '15.2.8.3.12') do
skip unless Object.const_defined?(:Float)
# Overflow to Fixnum
# Overflow to Integer
assert_float 9223372036854775808.0, 1 << 63
assert_float(-13835058055282163712.0, -3 << 62)
end
+1 -1
View File
@@ -76,7 +76,7 @@ assert('Kernel.raise', '15.3.1.2.12') do
end
assert('Kernel#__id__', '15.3.1.3.3') do
assert_equal Fixnum, __id__.class
assert_equal Integer, __id__.class
end
assert('Kernel#__send__', '15.3.1.3.4') do
+1 -1
View File
@@ -593,7 +593,7 @@ end
# to_f / other
# end
# end
# Fixnum.send(:prepend, M)
# Integer.send(:prepend, M)
# assert_equal(0.5, 1 / 2, "#{bug7983}")
# }
# assert_equal(0, 1 / 2)
+3 -3
View File
@@ -17,7 +17,7 @@ assert('mrb_vformat') do
assert_equal '`t`: NilClass', vf.v('`t`: %t', nil)
assert_equal '`t`: FalseClass', vf.v('`t`: %t', false)
assert_equal '`t`: TrueClass', vf.v('`t`: %t', true)
assert_equal '`t`: Fixnum', vf.v('`t`: %t', 0)
assert_equal '`t`: Integer', vf.v('`t`: %t', 0)
assert_equal '`t`: Hash', vf.v('`t`: %t', {k: "value"})
assert_match '#<Class:#<Class:#<Hash:0x*>>>', vf.v('%t', sclass({}))
assert_equal 'string and length', vf.l('string %l length', 'andante', 3)
@@ -29,13 +29,13 @@ assert('mrb_vformat') do
assert_equal '`T`: NilClass', vf.v('`T`: %T', nil)
assert_equal '`T`: FalseClass', vf.v('`T`: %T', false)
assert_equal '`T`: TrueClass', vf.v('`T`: %T', true)
assert_equal '`T`: Fixnum', vf.v('`T`: %T', 0)
assert_equal '`T`: Integer', vf.v('`T`: %T', 0)
assert_equal '`T`: Hash', vf.v('`T`: %T', {k: "value"})
assert_match 'Class', vf.v('%T', sclass({}))
assert_equal '`Y`: nil', vf.v('`Y`: %Y', nil)
assert_equal '`Y`: false', vf.v('`Y`: %Y', false)
assert_equal '`Y`: true', vf.v('`Y`: %Y', true)
assert_equal '`Y`: Fixnum', vf.v('`Y`: %Y', 0)
assert_equal '`Y`: Integer', vf.v('`Y`: %Y', 0)
assert_equal '`Y`: Hash', vf.v('`Y`: %Y', {k: "value"})
assert_equal 'Class', vf.v('%Y', sclass({}))
assert_match '#<Class:#<String:0x*>>', vf.v('%v', sclass(""))