From 4c3d81d323f2876d5528fc9601cff55c88c6f566 Mon Sep 17 00:00:00 2001 From: matz Date: Tue, 17 Mar 1998 10:06:57 +0000 Subject: modulo, frexp, ldexp git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- math.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'math.c') 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); } -- cgit v1.2.3