summaryrefslogtreecommitdiff
path: root/math.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-01-20 04:59:39 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-01-20 04:59:39 +0000
commit62e648e148b3cb9f96dcce808c55c02b7ccb4486 (patch)
tree9708892ece92e860d81559ab55e6b1f9400d7ffc /math.c
parentaeb049c573be4dc24dd20650f40e4777e0f698cf (diff)
ruby 1.3 cycle
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/RUBY@372 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'math.c')
-rw-r--r--math.c74
1 files changed, 50 insertions, 24 deletions
diff --git a/math.c b/math.c
index 0e427035f4..3ea30bdbba 100644
--- a/math.c
+++ b/math.c
@@ -6,14 +6,14 @@
$Date$
created at: Tue Jan 25 14:12:56 JST 1994
- Copyright (C) 1993-1996 Yukihiro Matsumoto
+ Copyright (C) 1993-1998 Yukihiro Matsumoto
************************************************/
#include "ruby.h"
#include <math.h>
-VALUE mMath;
+VALUE rb_mMath;
#define Need_Float(x) (x) = rb_Float(x)
#define Need_Float2(x,y) {\
@@ -26,7 +26,7 @@ math_atan2(obj, x, y)
VALUE obj, x, y;
{
Need_Float2(x, y);
- return float_new(atan2(RFLOAT(x)->value, RFLOAT(y)->value));
+ return rb_float_new(atan2(RFLOAT(x)->value, RFLOAT(y)->value));
}
static VALUE
@@ -35,7 +35,7 @@ math_cos(obj, x)
{
Need_Float(x);
- return float_new(cos(RFLOAT(x)->value));
+ return rb_float_new(cos(RFLOAT(x)->value));
}
static VALUE
@@ -44,7 +44,7 @@ math_sin(obj, x)
{
Need_Float(x);
- return float_new(sin(RFLOAT(x)->value));
+ return rb_float_new(sin(RFLOAT(x)->value));
}
static VALUE
@@ -53,7 +53,7 @@ math_tan(obj, x)
{
Need_Float(x);
- return float_new(tan(RFLOAT(x)->value));
+ return rb_float_new(tan(RFLOAT(x)->value));
}
static VALUE
@@ -61,7 +61,7 @@ math_exp(obj, x)
VALUE obj, x;
{
Need_Float(x);
- return float_new(exp(RFLOAT(x)->value));
+ return rb_float_new(exp(RFLOAT(x)->value));
}
static VALUE
@@ -69,7 +69,7 @@ math_log(obj, x)
VALUE obj, x;
{
Need_Float(x);
- return float_new(log(RFLOAT(x)->value));
+ return rb_float_new(log(RFLOAT(x)->value));
}
static VALUE
@@ -77,7 +77,7 @@ math_log10(obj, x)
VALUE obj, x;
{
Need_Float(x);
- return float_new(log10(RFLOAT(x)->value));
+ return rb_float_new(log10(RFLOAT(x)->value));
}
static VALUE
@@ -86,34 +86,60 @@ math_sqrt(obj, x)
{
Need_Float(x);
- if (RFLOAT(x)->value < 0.0) ArgError("square root for negative number");
- return float_new(sqrt(RFLOAT(x)->value));
+ if (RFLOAT(x)->value < 0.0) rb_raise(rb_eArgError, "square root for negative number");
+ return rb_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 rb_assoc_new(rb_float_new(d), INT2NUM(exp));
+}
+
+static VALUE
+math_ldexp(obj, x, n)
+ VALUE obj, x, n;
+{
+ double d;
+
+ Need_Float(x);
+ return rb_float_new(d = ldexp(RFLOAT(x)->value, NUM2INT(n)));
}
void
Init_Math()
{
- mMath = rb_define_module("Math");
+ rb_mMath = rb_define_module("Math");
#ifdef M_PI
- rb_define_const(mMath, "PI", float_new(M_PI));
+ rb_define_const(rb_mMath, "PI", rb_float_new(M_PI));
#else
- rb_define_const(mMath, "PI", float_new(atan(1.0)*4.0));
+ rb_define_const(rb_mMath, "PI", rb_float_new(atan(1.0)*4.0));
#endif
#ifdef M_E
- rb_define_const(mMath, "E", float_new(M_E));
+ rb_define_const(rb_mMath, "E", rb_float_new(M_E));
#else
- rb_define_const(mMath, "E", float_new(exp(1.0)));
+ rb_define_const(rb_mMath, "E", rb_float_new(exp(1.0)));
#endif
- rb_define_module_function(mMath, "atan2", math_atan2, 2);
- rb_define_module_function(mMath, "cos", math_cos, 1);
- rb_define_module_function(mMath, "sin", math_sin, 1);
- rb_define_module_function(mMath, "tan", math_tan, 1);
+ rb_define_module_function(rb_mMath, "atan2", math_atan2, 2);
+ rb_define_module_function(rb_mMath, "cos", math_cos, 1);
+ rb_define_module_function(rb_mMath, "sin", math_sin, 1);
+ rb_define_module_function(rb_mMath, "tan", math_tan, 1);
+
+ rb_define_module_function(rb_mMath, "exp", math_exp, 1);
+ rb_define_module_function(rb_mMath, "log", math_log, 1);
+ rb_define_module_function(rb_mMath, "log10", math_log10, 1);
+ rb_define_module_function(rb_mMath, "sqrt", math_sqrt, 1);
- 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(rb_mMath, "frexp", math_frexp, 1);
+ rb_define_module_function(rb_mMath, "ldexp", math_ldexp, 2);
}