ruby-changes:3926
From: ko1@a...
Date: Sat, 9 Feb 2008 18:36:23 +0900 (JST)
Subject: [ruby-changes:3926] akr - Ruby:r15416 (trunk): * math.c (math_cbrt): new method Math.cbrt.
akr 2008-02-09 18:36:03 +0900 (Sat, 09 Feb 2008) New Revision: 15416 Added files: trunk/missing/cbrt.c Modified files: trunk/ChangeLog trunk/configure.in trunk/math.c Log: * math.c (math_cbrt): new method Math.cbrt. * configure.in (cbrt): check for replacement functions. * missing/cbrt.c: new file. http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/math.c?r1=15416&r2=15415&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=15416&r2=15415&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/missing/cbrt.c?revision=15416&view=markup http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/missing/cbrt.c?r1=15416&r2=15415&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/configure.in?r1=15416&r2=15415&diff_format=u Index: math.c =================================================================== --- math.c (revision 15415) +++ math.c (revision 15416) @@ -402,6 +402,20 @@ /* * call-seq: + * Math.cbrt(numeric) => float + * + * Returns the cube root of <i>numeric</i>. + */ + +static VALUE +math_cbrt(VALUE obj, VALUE x) +{ + Need_Float(x); + return DOUBLE2NUM(cbrt(RFLOAT_VALUE(x))); +} + +/* + * call-seq: * Math.frexp(numeric) => [ fraction, exponent ] * * Returns a two-element array containing the normalized fraction (a @@ -611,6 +625,7 @@ rb_define_module_function(rb_mMath, "log2", math_log2, 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(rb_mMath, "cbrt", math_cbrt, 1); rb_define_module_function(rb_mMath, "frexp", math_frexp, 1); rb_define_module_function(rb_mMath, "ldexp", math_ldexp, 2); Index: configure.in =================================================================== --- configure.in (revision 15415) +++ configure.in (revision 15416) @@ -649,7 +649,7 @@ AC_FUNC_MEMCMP AC_REPLACE_FUNCS(dup2 memmove strerror strftime\ strchr strstr crypt flock vsnprintf\ - isnan finite isinf hypot acosh erf tgamma lgamma_r \ + isnan finite isinf hypot acosh erf tgamma lgamma_r cbrt \ strlcpy strlcat) AC_CHECK_FUNCS(fmod killpg wait4 waitpid fork spawnv syscall chroot fsync getcwd eaccess\ truncate chsize times utimes utimensat fcntl lockf lstat\ Index: ChangeLog =================================================================== --- ChangeLog (revision 15415) +++ ChangeLog (revision 15416) @@ -1,3 +1,11 @@ +Sat Feb 9 18:34:45 2008 Tanaka Akira <akr@f...> + + * math.c (math_cbrt): new method Math.cbrt. + + * configure.in (cbrt): check for replacement functions. + + * missing/cbrt.c: new file. + Sat Feb 9 17:51:24 2008 Nobuyoshi Nakada <nobu@r...> * ext/bigdecimal/bigdecimal.c (BigDecimal_to_f): use strtod() for more Index: missing/cbrt.c =================================================================== --- missing/cbrt.c (revision 0) +++ missing/cbrt.c (revision 15416) @@ -0,0 +1,10 @@ +#include <math.h> + +double cbrt(double x) +{ + if (x < 0) + return -pow(-x, 1/3.0); + else + return pow(x, 1/3.0); +} + Property changes on: missing/cbrt.c ___________________________________________________________________ Name: svn:eol-style + LF -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/