mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
modulo, frexp, ldexp
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a946791350
commit
4c3d81d323
6 changed files with 137 additions and 17 deletions
28
math.c
28
math.c
|
@ -90,6 +90,30 @@ math_sqrt(obj, x)
|
|||
return float_new(sqrt(RFLOAT(x)->value));
|
||||
}
|
||||
|
||||
static VALUE
|
||||
math_frexp(obj, x)
|
||||
VALUE obj, x;
|
||||
{
|
||||
double d;
|
||||
int exp;
|
||||
|
||||
Need_Float(x);
|
||||
d = frexp(RFLOAT(x)->value, &exp);
|
||||
|
||||
return assoc_new(float_new(d), INT2NUM(exp));
|
||||
}
|
||||
|
||||
static VALUE
|
||||
math_ldexp(obj, x, n)
|
||||
VALUE obj, x, n;
|
||||
{
|
||||
double d;
|
||||
int exp;
|
||||
|
||||
Need_Float(x);
|
||||
return float_new(d = ldexp(RFLOAT(x)->value, NUM2INT(n)));
|
||||
}
|
||||
|
||||
void
|
||||
Init_Math()
|
||||
{
|
||||
|
@ -115,5 +139,7 @@ Init_Math()
|
|||
rb_define_module_function(mMath, "exp", math_exp, 1);
|
||||
rb_define_module_function(mMath, "log", math_log, 1);
|
||||
rb_define_module_function(mMath, "log10", math_log10, 1);
|
||||
rb_define_module_function(mMath, "sqrt", math_sqrt, 1);
|
||||
|
||||
rb_define_module_function(mMath, "frexp", math_frexp, 1);
|
||||
rb_define_module_function(mMath, "ldexp", math_ldexp, 2);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue