mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* complex.c (numeric_abs2): new.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18998 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
8aae9dc62c
commit
1d9a079b1c
4 changed files with 22 additions and 2 deletions
|
@ -1,3 +1,7 @@
|
|||
Sun Aug 31 20:49:42 2008 Tadayoshi Funaba <tadf@dotrb.org>
|
||||
|
||||
* complex.c (numeric_abs2): new.
|
||||
|
||||
Sun Aug 31 18:22:04 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* lib/mkmf.rb (have_devel?): checks if the compiler works.
|
||||
|
|
|
@ -1291,6 +1291,12 @@ numeric_image(VALUE self)
|
|||
return INT2FIX(0);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
numeric_abs2(VALUE self)
|
||||
{
|
||||
return f_mul(self, self);
|
||||
}
|
||||
|
||||
#define id_PI rb_intern("PI")
|
||||
|
||||
static VALUE
|
||||
|
@ -1473,6 +1479,7 @@ Init_Complex(void)
|
|||
rb_define_method(rb_cNumeric, "real", numeric_real, 0);
|
||||
rb_define_method(rb_cNumeric, "image", numeric_image, 0);
|
||||
rb_define_method(rb_cNumeric, "imag", numeric_image, 0);
|
||||
rb_define_method(rb_cNumeric, "abs2", numeric_abs2, 0);
|
||||
rb_define_method(rb_cNumeric, "arg", numeric_arg, 0);
|
||||
rb_define_method(rb_cNumeric, "angle", numeric_arg, 0);
|
||||
rb_define_method(rb_cNumeric, "phase", numeric_arg, 0);
|
||||
|
|
|
@ -856,6 +856,11 @@ class Complex_Test < Test::Unit::TestCase
|
|||
assert_equal(1, 1.0.magnitude)
|
||||
assert_equal(1, -1.0.magnitude)
|
||||
|
||||
assert_equal(4, 2.abs2)
|
||||
assert_equal(4, -2.abs2)
|
||||
assert_equal(4.0, 2.0.abs2)
|
||||
assert_equal(4.0, -2.0.abs2)
|
||||
|
||||
assert_equal(0, 1.arg)
|
||||
assert_equal(0, 1.angle)
|
||||
assert_equal(0, 1.phase)
|
||||
|
|
|
@ -953,6 +953,10 @@ class Rational_Test < Test::Unit::TestCase
|
|||
assert_equal(Rational(9,1), Rational(1,9).reciprocal)
|
||||
assert_equal(Rational(-1,9), Rational(-9,1).reciprocal)
|
||||
assert_equal(Rational(-9,1), Rational(-1,9).reciprocal)
|
||||
assert_equal(Rational(1,9), Rational(9,1).inverse)
|
||||
assert_equal(Rational(9,1), Rational(1,9).inverse)
|
||||
assert_equal(Rational(-1,9), Rational(-9,1).inverse)
|
||||
assert_equal(Rational(-9,1), Rational(-1,9).inverse)
|
||||
end
|
||||
=end
|
||||
|
||||
|
@ -1047,9 +1051,9 @@ class Rational_Test < Test::Unit::TestCase
|
|||
|
||||
=begin
|
||||
assert_equal(Rational(1,9), 9.reciprocal)
|
||||
assert_equal(Rational(1,9), 9.0.reciprocal)
|
||||
assert_in_delta(0.1111, 9.0.reciprocal, 0.001)
|
||||
assert_equal(Rational(1,9), 9.inverse)
|
||||
assert_equal(Rational(1,9), 9.0.inverse)
|
||||
assert_in_delta(0.1111, 9.0.inverse, 0.001)
|
||||
=end
|
||||
|
||||
assert_equal(Rational(1,2), 1.quo(2))
|
||||
|
|
Loading…
Add table
Reference in a new issue