Project

General

Profile

Feature #6973 ยป integral.patch

regularfry (Alex Young), 09/04/2012 06:03 AM

View differences:

numeric.c
return Qfalse;
}
/*
* call-seq:
* num.abs -> numeric
......
}
/*
* call-seq:
* x.integral? -> true or false
*
* Returns <code>true</code> iff <i>x</i> has an integer value.
*
* 1.integral? #=> true
* 1.0.integral? #=> true
* 1.2.integral? #=> false
*/
static VALUE
num_integral_p(VALUE x)
{
VALUE y;
if (rb_respond_to(x, rb_intern("to_i"))) {
y = num_to_int(x);
return rb_funcall(x, id_eq, 1, y);
}
else {
return Qfalse;
}
}
/********************************************************************
*
* Document-class: Float
......
rb_define_method(rb_cNumeric, "real?", num_real_p, 0);
rb_define_method(rb_cNumeric, "integer?", num_int_p, 0);
rb_define_method(rb_cNumeric, "integral?", num_integral_p, 0);
rb_define_method(rb_cNumeric, "zero?", num_zero_p, 0);
rb_define_method(rb_cNumeric, "nonzero?", num_nonzero_p, 0);
test/ruby/test_integer.rb
assert(1.integer?)
end
def test_integral_p
assert(1.integral?)
end
def test_odd_p_even_p
Fixnum.class_eval do
alias odd_bak odd?
test/ruby/test_numeric.rb
assert(!Numeric.new.integer?)
end
def test_integral_p
assert(!Numeric.new.integral?)
end
def test_abs
a = DummyNumeric.new
DummyNumeric.class_eval do
......
assert(!(1.eql?(1.0)))
assert(!(1.eql?(2)))
end
def test_integral?
assert(1.integral?, "1 is not integral")
assert(1.0.integral?, "1.0 is not integral")
assert(!1.2.integral?, "1.2 is integral")
end
end
    (1-1/1)