summaryrefslogtreecommitdiff
path: root/math.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-03-17 10:06:57 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-03-17 10:06:57 +0000
commit4c3d81d323f2876d5528fc9601cff55c88c6f566 (patch)
tree92eb620a2238c53401118b9ca5c920dbb1ca7d91 /math.c
parenta94679135080615136be4d83a66b3f964b8d66a4 (diff)
modulo, frexp, ldexp
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'math.c')
-rw-r--r--math.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/math.c b/math.c
index 775bddaf16..e531e88ffe 100644
--- a/math.c
+++ b/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);
}