From 7c3537f27dd9edd5c8ff3cfa4aa2748abd975f44 Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 5 Jun 2002 09:54:09 +0000 Subject: [PATCH] * math.c (Init_Math): backport asin, acos, atan. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_6@2525 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ lib/rational.rb | 6 +++--- math.c | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 33303fa70d..6e8a552c4c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Wed Jun 5 18:53:06 2002 Yukihiro Matsumoto + + * math.c (Init_Math): backport asin, acos, atan. + Tue Jun 4 00:45:50 2002 Nobuyoshi Nakada * ext/socket/addrinfo.h: typo. diff --git a/lib/rational.rb b/lib/rational.rb index decf26b1ba..ff35f36a3e 100644 --- a/lib/rational.rb +++ b/lib/rational.rb @@ -8,7 +8,7 @@ # -- # Usage: # class Rational < Numeric -# (include Compareable) +# (include Comparable) # # Rational(a, b) --> a/b # @@ -47,7 +47,7 @@ class Rational < Numeric @RCS_ID='-$Id: rational.rb,v 1.7 1999/08/24 12:49:28 keiju Exp keiju $-' def Rational.reduce(num, den = 1) - raise ZeroDivisionError, "denometor is 0" if den == 0 + raise ZeroDivisionError, "denominator is 0" if den == 0 if den < 0 num = -num @@ -132,7 +132,7 @@ class Rational < Numeric den = @denominator * a.numerator Rational(num, den) elsif a.kind_of?(Integer) - raise ZeroDivisionError, "devided by 0" if a == 0 + raise ZeroDivisionError, "divided by 0" if a == 0 self / Rational.new!(a, 1) elsif a.kind_of?(Float) Float(self) / a diff --git a/math.c b/math.c index 2cac83e938..86c889dca9 100644 --- a/math.c +++ b/math.c @@ -56,6 +56,39 @@ math_tan(obj, x) return rb_float_new(tan(RFLOAT(x)->value)); } +static VALUE +math_acos(obj, x) + VALUE obj, x; +{ + Need_Float(x); + /* + if (RFLOAT(x)->value < -1.0 || RFLOAT(x)->value > 1.0) + rb_raise(rb_eArgError, "Out of range (-1..1)"); + */ + return rb_float_new(acos(RFLOAT(x)->value)); +} + +static VALUE +math_asin(obj, x) + VALUE obj, x; +{ + Need_Float(x); + /* + if (RFLOAT(x)->value < -1.0 || RFLOAT(x)->value > 1.0) + rb_raise(rb_eArgError, "Out of range (-1..1)"); + */ + return rb_float_new(asin(RFLOAT(x)->value)); +} + +static VALUE +math_atan(obj, x) + VALUE obj, x; +{ + Need_Float(x); + + return rb_float_new(atan(RFLOAT(x)->value)); +} + static VALUE math_exp(obj, x) VALUE obj, x; @@ -140,6 +173,10 @@ Init_Math() 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, "acos", math_acos, 1); + rb_define_module_function(rb_mMath, "asin", math_asin, 1); + rb_define_module_function(rb_mMath, "atan", math_atan, 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);