diff options
| author | tadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-06-29 16:20:32 +0000 |
|---|---|---|
| committer | tadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-06-29 16:20:32 +0000 |
| commit | 579c43317e0af8b2dcd80a854d88de74679cf07a (patch) | |
| tree | d5416e375ebcd97d9d93899933c846b58dc0ef39 | |
| parent | 72835997446a545e9cb8b726e9a60e39902926a3 (diff) | |
| download | ruby-579c43317e0af8b2dcd80a854d88de74679cf07a.tar.gz ruby-579c43317e0af8b2dcd80a854d88de74679cf07a.tar.xz ruby-579c43317e0af8b2dcd80a854d88de74679cf07a.zip | |
* complex.c (nucomp_expt): do not use rb_fexpt.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@23898 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
| -rw-r--r-- | ChangeLog | 4 | ||||
| -rw-r--r-- | complex.c | 11 | ||||
| -rw-r--r-- | lib/cmath.rb | 25 |
3 files changed, 29 insertions, 11 deletions
@@ -1,3 +1,7 @@ +Tue Jun 30 01:19:53 2009 Tadayoshi Funaba <tadf@dotrb.org> + + * complex.c (nucomp_expt): do not use rb_fexpt. + Mon Jun 29 22:50:10 2009 Yuki Sonoda (Yugui) <yugui@yugui.jp> * Doxyfile.in: removed. merged into template/Doxyfile.template @@ -825,14 +825,6 @@ nucomp_expt(VALUE self, VALUE other) other = dat->real; /* c14n */ } - { - get_dat1(self); - - if (k_exact_p(dat->imag) && f_zero_p(dat->imag) && f_real_p(other)) - return f_complex_new1(CLASS_OF(self), - rb_fexpt(dat->real, other)); /* c14n */ - } - if (k_complex_p(other)) { VALUE r, theta, nr, ntheta; @@ -883,7 +875,8 @@ nucomp_expt(VALUE self, VALUE other) r = f_abs(self); theta = f_arg(self); - return f_complex_polar(CLASS_OF(self), rb_fexpt(r, other), + + return f_complex_polar(CLASS_OF(self), f_expt(r, other), f_mul(theta, other)); } return rb_num_coerce_bin(self, other, id_expt); diff --git a/lib/cmath.rb b/lib/cmath.rb index 6b47e70a1..abca79986 100644 --- a/lib/cmath.rb +++ b/lib/cmath.rb @@ -4,8 +4,10 @@ module CMath alias exp! exp alias log! log + alias log2! log2 alias log10! log10 alias sqrt! sqrt + alias cbrt! cbrt alias sin! sin alias cos! cos @@ -47,6 +49,14 @@ module CMath end end + def log2(z) + if z.real? and z >= 0 + log2!(z) + else + log(z) / log!(2) + end + end + def log10(z) if z.real? and z >= 0 log10!(z) @@ -74,6 +84,15 @@ module CMath end end + def cbrt(z) + if z.real? and z >= 0 + cbrt!(z) + else +# exp(log(z) * (1.0/3)) + Complex(z) ** (1.0/3) + end + end + def sin(z) if z.real? sin!(z) @@ -186,10 +205,14 @@ module CMath module_function :exp module_function :log! module_function :log + module_function :log2! + module_function :log2 module_function :log10! module_function :log10 module_function :sqrt! module_function :sqrt + module_function :cbrt! + module_function :cbrt module_function :sin! module_function :sin @@ -221,8 +244,6 @@ module CMath module_function :atanh! module_function :atanh - module_function :log2 - module_function :cbrt module_function :frexp module_function :ldexp module_function :hypot |
