From f7fad2e325576164c2c1ae67084fde328387b6d2 Mon Sep 17 00:00:00 2001 From: dave Date: Sun, 28 Dec 2003 15:44:07 +0000 Subject: Add RDoc comments to math.c git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@5333 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++ math.c | 184 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 188 insertions(+) diff --git a/ChangeLog b/ChangeLog index d66278f4a4..9f26260d6f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Mon Dec 29 00:41:44 2003 Dave Thomas + + * math.c: Add RDoc comments + Sun Dec 28 20:19:11 2003 Tanaka Akira * ext/stringio/stringio.c (strio_sysread): StringIO.new.sysread didn't diff --git a/math.c b/math.c index 5268598750..5b9294e781 100644 --- a/math.c +++ b/math.c @@ -22,6 +22,16 @@ VALUE rb_mMath; Need_Float(y);\ } while (0) + +/* + * call-seq: + * Math.atan2(y, x) => float + * + * Computes the arc tangent given y and x. Returns + * -PI..PI. + * + */ + static VALUE math_atan2(obj, y, x) VALUE obj, x, y; @@ -30,6 +40,16 @@ math_atan2(obj, y, x) return rb_float_new(atan2(RFLOAT(y)->value, RFLOAT(x)->value)); } + + +/* + * call-seq: + * Math.cos(x) => float + * + * Computes the cosine of x (expressed in radians). Returns + * -1..1. + */ + static VALUE math_cos(obj, x) VALUE obj, x; @@ -38,6 +58,14 @@ math_cos(obj, x) return rb_float_new(cos(RFLOAT(x)->value)); } +/* + * call-seq: + * Math.sin(x) => float + * + * Computes the sine of x (expressed in radians). Returns + * -1..1. + */ + static VALUE math_sin(obj, x) VALUE obj, x; @@ -47,6 +75,14 @@ math_sin(obj, x) return rb_float_new(sin(RFLOAT(x)->value)); } + +/* + * call-seq: + * Math.tan(x) => float + * + * Returns the tangent of x (expressed in radians). + */ + static VALUE math_tan(obj, x) VALUE obj, x; @@ -56,6 +92,13 @@ math_tan(obj, x) return rb_float_new(tan(RFLOAT(x)->value)); } +/* + * call-seq: + * Math.acos(x) => float + * + * Computes the arc cosine of x. Returns 0..PI. + */ + static VALUE math_acos(obj, x) VALUE obj, x; @@ -71,6 +114,13 @@ math_acos(obj, x) return rb_float_new(d); } +/* + * call-seq: + * Math.asin(x) => float + * + * Computes the arc sine of x. Returns 0..PI. + */ + static VALUE math_asin(obj, x) VALUE obj, x; @@ -86,6 +136,13 @@ math_asin(obj, x) return rb_float_new(d); } +/* + * call-seq: + * Math.atan(x) => float + * + * Computes the arc tangent of x. Returns -{PI/2} .. {PI/2}. + */ + static VALUE math_atan(obj, x) VALUE obj, x; @@ -103,6 +160,13 @@ cosh(x) } #endif +/* + * call-seq: + * Math.cosh(x) => float + * + * Computes the hyperbolic cosine of x (expressed in radians). + */ + static VALUE math_cosh(obj, x) VALUE obj, x; @@ -121,6 +185,14 @@ sinh(x) } #endif +/* + * call-seq: + * Math.sinh(x) => float + * + * Computes the hyperbolic sine of x (expressed in + * radians). + */ + static VALUE math_sinh(obj, x) VALUE obj, x; @@ -138,6 +210,14 @@ tanh(x) } #endif +/* + * call-seq: + * Math.tanh() => float + * + * Computes the hyperbolic tangent of x (expressed in + * radians). + */ + static VALUE math_tanh(obj, x) VALUE obj, x; @@ -146,6 +226,13 @@ math_tanh(obj, x) return rb_float_new(tanh(RFLOAT(x)->value)); } +/* + * call-seq: + * Math.acosh(x) => float + * + * Computes the inverse hyperbolic cosine of x. + */ + static VALUE math_acosh(obj, x) VALUE obj, x; @@ -161,6 +248,13 @@ math_acosh(obj, x) return rb_float_new(d); } +/* + * call-seq: + * Math.asinh(x) => float + * + * Computes the inverse hyperbolic sine of x. + */ + static VALUE math_asinh(obj, x) VALUE obj, x; @@ -169,6 +263,13 @@ math_asinh(obj, x) return rb_float_new(asinh(RFLOAT(x)->value)); } +/* + * call-seq: + * Math.atanh(x) => float + * + * Computes the inverse hyperbolic tangent of x. + */ + static VALUE math_atanh(obj, x) VALUE obj, x; @@ -184,6 +285,13 @@ math_atanh(obj, x) return rb_float_new(d); } +/* + * call-seq: + * Math.exp(x) => float + * + * Returns e**x. + */ + static VALUE math_exp(obj, x) VALUE obj, x; @@ -201,6 +309,13 @@ math_exp(obj, x) # define log10(x) ((x) < 0.0 ? nan("") : log10(x)) #endif +/* + * call-seq: + * Math.log(numeric) => float + * + * Returns the natural logarithm of numeric. + */ + static VALUE math_log(obj, x) VALUE obj, x; @@ -216,6 +331,13 @@ math_log(obj, x) return rb_float_new(d); } +/* + * call-seq: + * Math.log10(numeric) => float + * + * Returns the base 10 logarithm of numeric. + */ + static VALUE math_log10(obj, x) VALUE obj, x; @@ -231,6 +353,14 @@ math_log10(obj, x) return rb_float_new(d); } +/* + * call-seq: + * Math.sqrt(numeric) => float + * + * Returns the non-negative square root of numeric. Raises + * ArgError if numeric is less than zero. + */ + static VALUE math_sqrt(obj, x) VALUE obj, x; @@ -246,6 +376,18 @@ math_sqrt(obj, x) return rb_float_new(d); } +/* + * call-seq: + * Math.frexp(numeric) => [ fraction, exponent ] + * + * Returns a two-element array containing the normalized fraction (a + * Float) and exponent (a Fixnum) of + * numeric. + * + * fraction, exponent = Math.frexp(1234) #=> [0.6025390625, 11] + * fraction * 2**exponent #=> 1234.0 + */ + static VALUE math_frexp(obj, x) VALUE obj, x; @@ -259,6 +401,16 @@ math_frexp(obj, x) return rb_assoc_new(rb_float_new(d), INT2NUM(exp)); } +/* + * call-seq: + * Math.ldexp(flt, int) -> float + * + * Returns the value of flt*(2**int). + * + * fraction, exponent = Math.frexp(1234) + * Math.ldexp(fraction, exponent) #=> 1234.0 + */ + static VALUE math_ldexp(obj, x, n) VALUE obj, x, n; @@ -267,6 +419,16 @@ math_ldexp(obj, x, n) return rb_float_new(ldexp(RFLOAT(x)->value, NUM2INT(n))); } +/* + * call-seq: + * Math.hypot(x, y) => float + * + * Returns sqrt(x**2 + y**2), the hypotenuse of a right-angled triangle + * with sides x and y. + * + * Math.hypot(3, 4) #=> 5.0 + */ + static VALUE math_hypot(obj, x, y) VALUE obj, x, y; @@ -275,6 +437,13 @@ math_hypot(obj, x, y) return rb_float_new(hypot(RFLOAT(x)->value, RFLOAT(y)->value)); } +/* + * call-seq: + * Math.erf(x) => float + * + * Calculates the error function of x. + */ + static VALUE math_erf(obj, x) VALUE obj, x; @@ -283,6 +452,13 @@ math_erf(obj, x) return rb_float_new(erf(RFLOAT(x)->value)); } +/* + * call-seq: + * Math.erfc(x) => float + * + * Calculates the complementary error function of x. + */ + static VALUE math_erfc(obj, x) VALUE obj, x; @@ -291,6 +467,14 @@ math_erfc(obj, x) return rb_float_new(erfc(RFLOAT(x)->value)); } +/* + * The Math module contains module functions for basic + * trigonometric and transcendental functions. See class + * Float for a list of constants that + * define Ruby's floating point accuracy. + */ + + void Init_Math() { -- cgit v1.2.3