зеркало из https://github.com/github/ruby.git
* numeric.c (num_sadded): prohibit singleton method definition for
Numerics. fill yet another gap between Fixnum and Bignum. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5076 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
b0acbc4c9a
Коммит
ac761cda20
|
@ -1,3 +1,8 @@
|
||||||
|
Mon Dec 1 21:33:08 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
|
* numeric.c (num_sadded): prohibit singleton method definition for
|
||||||
|
Numerics. fill yet another gap between Fixnum and Bignum.
|
||||||
|
|
||||||
Mon Dec 1 17:33:47 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
|
Mon Dec 1 17:33:47 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
* pack.c (htov16): converts endian using swap16. htov32(), hton16,
|
* pack.c (htov16): converts endian using swap16. htov32(), hton16,
|
||||||
|
|
14
numeric.c
14
numeric.c
|
@ -158,6 +158,19 @@ rb_num_coerce_relop(x, y)
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
num_sadded(x, name)
|
||||||
|
VALUE x, name;
|
||||||
|
{
|
||||||
|
ruby_frame = ruby_frame->prev; /* pop frame for "singleton_method_added" */
|
||||||
|
/* Numerics should be values; singleton_methods should not be added to them */
|
||||||
|
rb_raise(rb_eTypeError,
|
||||||
|
"can't define singleton method \"%s\" for %s",
|
||||||
|
rb_id2name(rb_to_id(name)),
|
||||||
|
rb_obj_classname(x));
|
||||||
|
return Qnil; /* not reached */
|
||||||
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
num_init_copy(x, y)
|
num_init_copy(x, y)
|
||||||
VALUE x, y;
|
VALUE x, y;
|
||||||
|
@ -1820,6 +1833,7 @@ Init_Numeric()
|
||||||
rb_eFloatDomainError = rb_define_class("FloatDomainError", rb_eRangeError);
|
rb_eFloatDomainError = rb_define_class("FloatDomainError", rb_eRangeError);
|
||||||
rb_cNumeric = rb_define_class("Numeric", rb_cObject);
|
rb_cNumeric = rb_define_class("Numeric", rb_cObject);
|
||||||
|
|
||||||
|
rb_define_method(rb_cNumeric, "singleton_method_added", num_sadded, 1);
|
||||||
rb_include_module(rb_cNumeric, rb_mComparable);
|
rb_include_module(rb_cNumeric, rb_mComparable);
|
||||||
rb_define_method(rb_cNumeric, "initialize_copy", num_init_copy, 1);
|
rb_define_method(rb_cNumeric, "initialize_copy", num_init_copy, 1);
|
||||||
rb_define_method(rb_cNumeric, "coerce", num_coerce, 1);
|
rb_define_method(rb_cNumeric, "coerce", num_coerce, 1);
|
||||||
|
|
|
@ -1179,27 +1179,27 @@ test_ok(2.6.round == 3)
|
||||||
test_ok((-2.4).truncate == -2)
|
test_ok((-2.4).truncate == -2)
|
||||||
test_ok((13.4 % 1 - 0.4).abs < 0.0001)
|
test_ok((13.4 % 1 - 0.4).abs < 0.0001)
|
||||||
nan = 0.0/0
|
nan = 0.0/0
|
||||||
def nan.test(v)
|
def nan_test(x,y)
|
||||||
test_ok(self != v)
|
test_ok(x != y)
|
||||||
test_ok((self < v) == false)
|
test_ok((x < y) == false)
|
||||||
test_ok((self > v) == false)
|
test_ok((x > y) == false)
|
||||||
test_ok((self <= v) == false)
|
test_ok((x <= y) == false)
|
||||||
test_ok((self >= v) == false)
|
test_ok((x >= y) == false)
|
||||||
end
|
end
|
||||||
nan.test(nan)
|
nan_test(nan, nan)
|
||||||
nan.test(0)
|
nan_test(nan, 0)
|
||||||
nan.test(1)
|
nan_test(nan, 1)
|
||||||
nan.test(-1)
|
nan_test(nan, -1)
|
||||||
nan.test(1000)
|
nan_test(nan, 1000)
|
||||||
nan.test(-1000)
|
nan_test(nan, -1000)
|
||||||
nan.test(1_000_000_000_000)
|
nan_test(nan, 1_000_000_000_000)
|
||||||
nan.test(-1_000_000_000_000)
|
nan_test(nan, -1_000_000_000_000)
|
||||||
nan.test(100.0);
|
nan_test(nan, 100.0);
|
||||||
nan.test(-100.0);
|
nan_test(nan, -100.0);
|
||||||
nan.test(0.001);
|
nan_test(nan, 0.001);
|
||||||
nan.test(-0.001);
|
nan_test(nan, -0.001);
|
||||||
nan.test(1.0/0);
|
nan_test(nan, 1.0/0);
|
||||||
nan.test(-1.0/0);
|
nan_test(nan, -1.0/0);
|
||||||
|
|
||||||
#s = "3.7517675036461267e+17"
|
#s = "3.7517675036461267e+17"
|
||||||
#test_ok(s == sprintf("%.16e", s.to_f))
|
#test_ok(s == sprintf("%.16e", s.to_f))
|
||||||
|
|
|
@ -15,30 +15,30 @@ class TestFloat < Test::Unit::TestCase
|
||||||
assert((13.4 % 1 - 0.4).abs < 0.0001)
|
assert((13.4 % 1 - 0.4).abs < 0.0001)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def nan_test(x,y)
|
||||||
|
extend Test::Unit::Assertions
|
||||||
|
assert(x != y)
|
||||||
|
assert_equal(false, (x < y))
|
||||||
|
assert_equal(false, (x > y))
|
||||||
|
assert_equal(false, (x <= y))
|
||||||
|
assert_equal(false, (x >= y))
|
||||||
|
end
|
||||||
def test_nan
|
def test_nan
|
||||||
nan = 0.0/0
|
nan = 0.0/0
|
||||||
def nan.test(v)
|
nan_test(nan, nan)
|
||||||
extend Test::Unit::Assertions
|
nan_test(nan, 0)
|
||||||
assert(self != v)
|
nan_test(nan, 1)
|
||||||
assert_equal(false, (self < v))
|
nan_test(nan, -1)
|
||||||
assert_equal(false, (self > v))
|
nan_test(nan, 1000)
|
||||||
assert_equal(false, (self <= v))
|
nan_test(nan, -1000)
|
||||||
assert_equal(false, (self >= v))
|
nan_test(nan, 1_000_000_000_000)
|
||||||
end
|
nan_test(nan, -1_000_000_000_000)
|
||||||
nan.test(nan)
|
nan_test(nan, 100.0);
|
||||||
nan.test(0)
|
nan_test(nan, -100.0);
|
||||||
nan.test(1)
|
nan_test(nan, 0.001);
|
||||||
nan.test(-1)
|
nan_test(nan, -0.001);
|
||||||
nan.test(1000)
|
nan_test(nan, 1.0/0);
|
||||||
nan.test(-1000)
|
nan_test(nan, -1.0/0);
|
||||||
nan.test(1_000_000_000_000)
|
|
||||||
nan.test(-1_000_000_000_000)
|
|
||||||
nan.test(100.0);
|
|
||||||
nan.test(-100.0);
|
|
||||||
nan.test(0.001);
|
|
||||||
nan.test(-0.001);
|
|
||||||
nan.test(1.0/0);
|
|
||||||
nan.test(-1.0/0);
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_precision
|
def test_precision
|
||||||
|
|
Загрузка…
Ссылка в новой задаче