1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* math.c (rb_math_{atan2,cos,cosh,hypot,log,sin,sinh,sqrt}): added.

* complex.c: follows the above change.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20005 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
tadf 2008-10-28 15:10:40 +00:00
parent b87182fa7f
commit 2d5a281c98
3 changed files with 64 additions and 27 deletions

View file

@ -1,3 +1,9 @@
Wed Oct 29 00:08:05 2008 Tadayoshi Funaba <tadf@dotrb.org>
* math.c (rb_math_{atan2,cos,cosh,hypot,log,sin,sinh,sqrt}): added.
* complex.c: follows the above change.
Tue Oct 28 23:29:06 2008 NARUSE, Yui <naruse@ruby-lang.org> Tue Oct 28 23:29:06 2008 NARUSE, Yui <naruse@ruby-lang.org>
* ext/nkf/nkf-utf8/nkf.c (kanji_convert): output unicode chars. * ext/nkf/nkf-utf8/nkf.c (kanji_convert): output unicode chars.

View file

@ -426,31 +426,31 @@ nucomp_f_complex(int argc, VALUE *argv, VALUE klass)
return rb_funcall2(rb_cComplex, id_convert, argc, argv); return rb_funcall2(rb_cComplex, id_convert, argc, argv);
} }
extern VALUE math_atan2(VALUE obj, VALUE x, VALUE y); extern VALUE rb_math_atan2(VALUE x, VALUE y);
extern VALUE math_cos(VALUE obj, VALUE x); extern VALUE rb_math_cos(VALUE x);
extern VALUE math_cosh(VALUE obj, VALUE x); extern VALUE rb_math_cosh(VALUE x);
extern VALUE math_exp(VALUE obj, VALUE x); extern VALUE rb_math_exp(VALUE x);
extern VALUE math_hypot(VALUE obj, VALUE x, VALUE y); extern VALUE rb_math_hypot(VALUE x, VALUE y);
extern VALUE math_log(int argc, VALUE *argv); extern VALUE rb_math_log(int argc, VALUE *argv);
extern VALUE math_sin(VALUE obj, VALUE x); extern VALUE rb_math_sin(VALUE x);
extern VALUE math_sinh(VALUE obj, VALUE x); extern VALUE rb_math_sinh(VALUE x);
extern VALUE math_sqrt(VALUE obj, VALUE x); extern VALUE rb_math_sqrt(VALUE x);
#define m_atan2_bang(x,y) math_atan2(Qnil,x,y) #define m_atan2_bang(x,y) rb_math_atan2(x,y)
#define m_cos_bang(x) math_cos(Qnil,x) #define m_cos_bang(x) rb_math_cos(x)
#define m_cosh_bang(x) math_cosh(Qnil,x) #define m_cosh_bang(x) rb_math_cosh(x)
#define m_exp_bang(x) math_exp(Qnil,x) #define m_exp_bang(x) rb_math_exp(x)
#define m_hypot(x,y) math_hypot(Qnil,x,y) #define m_hypot(x,y) rb_math_hypot(x,y)
static VALUE static VALUE
m_log_bang(VALUE x) m_log_bang(VALUE x)
{ {
return math_log(1, &x); return rb_math_log(1, &x);
} }
#define m_sin_bang(x) math_sin(Qnil,x) #define m_sin_bang(x) rb_math_sin(x)
#define m_sinh_bang(x) math_sinh(Qnil,x) #define m_sinh_bang(x) rb_math_sinh(x)
#define m_sqrt_bang(x) math_sqrt(Qnil,x) #define m_sqrt_bang(x) rb_math_sqrt(x)
static VALUE static VALUE
m_cos(VALUE x) m_cos(VALUE x)

49
math.c
View file

@ -81,7 +81,7 @@ infinity_check(VALUE arg, double res, const char *msg)
* *
*/ */
VALUE static VALUE
math_atan2(VALUE obj, VALUE y, VALUE x) math_atan2(VALUE obj, VALUE y, VALUE x)
{ {
Need_Float2(y, x); Need_Float2(y, x);
@ -97,7 +97,7 @@ math_atan2(VALUE obj, VALUE y, VALUE x)
* -1..1. * -1..1.
*/ */
VALUE static VALUE
math_cos(VALUE obj, VALUE x) math_cos(VALUE obj, VALUE x)
{ {
Need_Float(x); Need_Float(x);
@ -112,7 +112,7 @@ math_cos(VALUE obj, VALUE x)
* -1..1. * -1..1.
*/ */
VALUE static VALUE
math_sin(VALUE obj, VALUE x) math_sin(VALUE obj, VALUE x)
{ {
Need_Float(x); Need_Float(x);
@ -203,7 +203,7 @@ cosh(double x)
* Computes the hyperbolic cosine of <i>x</i> (expressed in radians). * Computes the hyperbolic cosine of <i>x</i> (expressed in radians).
*/ */
VALUE static VALUE
math_cosh(VALUE obj, VALUE x) math_cosh(VALUE obj, VALUE x)
{ {
Need_Float(x); Need_Float(x);
@ -227,7 +227,7 @@ sinh(double x)
* radians). * radians).
*/ */
VALUE static VALUE
math_sinh(VALUE obj, VALUE x) math_sinh(VALUE obj, VALUE x)
{ {
Need_Float(x); Need_Float(x);
@ -317,7 +317,7 @@ math_atanh(VALUE obj, VALUE x)
* Returns e**x. * Returns e**x.
*/ */
VALUE static VALUE
math_exp(VALUE obj, VALUE x) math_exp(VALUE obj, VALUE x)
{ {
Need_Float(x); Need_Float(x);
@ -343,7 +343,7 @@ math_exp(VALUE obj, VALUE x)
* of logarithm. * of logarithm.
*/ */
VALUE static VALUE
math_log(int argc, VALUE *argv) math_log(int argc, VALUE *argv)
{ {
VALUE x, base; VALUE x, base;
@ -438,7 +438,7 @@ math_log10(VALUE obj, VALUE x)
* *
*/ */
VALUE static VALUE
math_sqrt(VALUE obj, VALUE x) math_sqrt(VALUE obj, VALUE x)
{ {
double d; double d;
@ -540,7 +540,7 @@ math_ldexp(VALUE obj, VALUE x, VALUE n)
* Math.hypot(3, 4) #=> 5.0 * Math.hypot(3, 4) #=> 5.0
*/ */
VALUE static VALUE
math_hypot(VALUE obj, VALUE x, VALUE y) math_hypot(VALUE obj, VALUE x, VALUE y)
{ {
Need_Float2(x, y); Need_Float2(x, y);
@ -653,6 +653,37 @@ math_lgamma(VALUE obj, VALUE x)
return rb_assoc_new(v, INT2FIX(sign)); return rb_assoc_new(v, INT2FIX(sign));
} }
#define exp1(n) \
VALUE \
rb_math_##n(VALUE x)\
{\
return math_##n(rb_mMath, x);\
}
#define exp2(n) \
VALUE \
rb_math_##n(VALUE x, VALUE y)\
{\
return math_##n(rb_mMath, x, y);\
}
exp2(atan2)
exp1(cos)
exp1(cosh)
exp1(exp)
exp2(hypot)
VALUE rb_math_log(int argc, VALUE *argv)
{
return math_log(argc, argv);
}
exp1(sin)
exp1(sinh)
exp1(sqrt)
/* /*
* The <code>Math</code> module contains module functions for basic * The <code>Math</code> module contains module functions for basic
* trigonometric and transcendental functions. See class * trigonometric and transcendental functions. See class