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
commit210367ec889f5910e270d6ea2c7ddb8a8d939e61 (patch)
treefeb35473da45947378fbc02defe39bcd79ef600e /math.c
parent9c5b1986a36c7a700b4c76817e35aa874ba7907c (diff)
This commit was generated by cvs2svn to compensate for changes in r372,
which included commits to RCS files with non-trunk default branches. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@373 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 0e42703..3ea30bd 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);
}