From 2d5a281c98b0f053101049abd34b931d24281157 Mon Sep 17 00:00:00 2001 From: tadf Date: Tue, 28 Oct 2008 15:10:40 +0000 Subject: [PATCH] * 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 --- ChangeLog | 6 ++++++ complex.c | 36 ++++++++++++++++++------------------ math.c | 49 ++++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 64 insertions(+), 27 deletions(-) diff --git a/ChangeLog b/ChangeLog index 531965fb8b..a64991f541 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Wed Oct 29 00:08:05 2008 Tadayoshi Funaba + + * 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 * ext/nkf/nkf-utf8/nkf.c (kanji_convert): output unicode chars. diff --git a/complex.c b/complex.c index e59554eded..d59305eb11 100644 --- a/complex.c +++ b/complex.c @@ -426,31 +426,31 @@ nucomp_f_complex(int argc, VALUE *argv, VALUE klass) return rb_funcall2(rb_cComplex, id_convert, argc, argv); } -extern VALUE math_atan2(VALUE obj, VALUE x, VALUE y); -extern VALUE math_cos(VALUE obj, VALUE x); -extern VALUE math_cosh(VALUE obj, VALUE x); -extern VALUE math_exp(VALUE obj, VALUE x); -extern VALUE math_hypot(VALUE obj, VALUE x, VALUE y); -extern VALUE math_log(int argc, VALUE *argv); -extern VALUE math_sin(VALUE obj, VALUE x); -extern VALUE math_sinh(VALUE obj, VALUE x); -extern VALUE math_sqrt(VALUE obj, VALUE x); +extern VALUE rb_math_atan2(VALUE x, VALUE y); +extern VALUE rb_math_cos(VALUE x); +extern VALUE rb_math_cosh(VALUE x); +extern VALUE rb_math_exp(VALUE x); +extern VALUE rb_math_hypot(VALUE x, VALUE y); +extern VALUE rb_math_log(int argc, VALUE *argv); +extern VALUE rb_math_sin(VALUE x); +extern VALUE rb_math_sinh(VALUE x); +extern VALUE rb_math_sqrt(VALUE x); -#define m_atan2_bang(x,y) math_atan2(Qnil,x,y) -#define m_cos_bang(x) math_cos(Qnil,x) -#define m_cosh_bang(x) math_cosh(Qnil,x) -#define m_exp_bang(x) math_exp(Qnil,x) -#define m_hypot(x,y) math_hypot(Qnil,x,y) +#define m_atan2_bang(x,y) rb_math_atan2(x,y) +#define m_cos_bang(x) rb_math_cos(x) +#define m_cosh_bang(x) rb_math_cosh(x) +#define m_exp_bang(x) rb_math_exp(x) +#define m_hypot(x,y) rb_math_hypot(x,y) static VALUE 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_sinh_bang(x) math_sinh(Qnil,x) -#define m_sqrt_bang(x) math_sqrt(Qnil,x) +#define m_sin_bang(x) rb_math_sin(x) +#define m_sinh_bang(x) rb_math_sinh(x) +#define m_sqrt_bang(x) rb_math_sqrt(x) static VALUE m_cos(VALUE x) diff --git a/math.c b/math.c index 340014b624..d0a8af8700 100644 --- a/math.c +++ b/math.c @@ -81,7 +81,7 @@ infinity_check(VALUE arg, double res, const char *msg) * */ -VALUE +static VALUE math_atan2(VALUE obj, VALUE y, VALUE x) { Need_Float2(y, x); @@ -97,7 +97,7 @@ math_atan2(VALUE obj, VALUE y, VALUE x) * -1..1. */ -VALUE +static VALUE math_cos(VALUE obj, VALUE x) { Need_Float(x); @@ -112,7 +112,7 @@ math_cos(VALUE obj, VALUE x) * -1..1. */ -VALUE +static VALUE math_sin(VALUE obj, VALUE x) { Need_Float(x); @@ -203,7 +203,7 @@ cosh(double x) * Computes the hyperbolic cosine of x (expressed in radians). */ -VALUE +static VALUE math_cosh(VALUE obj, VALUE x) { Need_Float(x); @@ -227,7 +227,7 @@ sinh(double x) * radians). */ -VALUE +static VALUE math_sinh(VALUE obj, VALUE x) { Need_Float(x); @@ -317,7 +317,7 @@ math_atanh(VALUE obj, VALUE x) * Returns e**x. */ -VALUE +static VALUE math_exp(VALUE obj, VALUE x) { Need_Float(x); @@ -343,7 +343,7 @@ math_exp(VALUE obj, VALUE x) * of logarithm. */ -VALUE +static VALUE math_log(int argc, VALUE *argv) { VALUE x, base; @@ -438,7 +438,7 @@ math_log10(VALUE obj, VALUE x) * */ -VALUE +static VALUE math_sqrt(VALUE obj, VALUE x) { double d; @@ -540,7 +540,7 @@ math_ldexp(VALUE obj, VALUE x, VALUE n) * Math.hypot(3, 4) #=> 5.0 */ -VALUE +static VALUE math_hypot(VALUE obj, VALUE x, VALUE y) { Need_Float2(x, y); @@ -653,6 +653,37 @@ math_lgamma(VALUE obj, VALUE x) 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 Math module contains module functions for basic * trigonometric and transcendental functions. See class