diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-02-09 09:36:03 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-02-09 09:36:03 +0000 |
commit | b160d23c68e2e8fcd82b96fab0977be11c2b9ec6 (patch) | |
tree | d85dbe40e1b2ff4089f4c4f228e65e2eb09243b5 | |
parent | a424741c8e73bbca5d893594abbdfda489794739 (diff) | |
download | ruby-b160d23c68e2e8fcd82b96fab0977be11c2b9ec6.tar.gz |
* math.c (math_cbrt): new method Math.cbrt.
* configure.in (cbrt): check for replacement functions.
* missing/cbrt.c: new file.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15416 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | configure.in | 2 | ||||
-rw-r--r-- | math.c | 15 | ||||
-rw-r--r-- | missing/cbrt.c | 10 |
4 files changed, 34 insertions, 1 deletions
@@ -1,3 +1,11 @@ +Sat Feb 9 18:34:45 2008 Tanaka Akira <akr@fsij.org> + + * 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@ruby-lang.org> * ext/bigdecimal/bigdecimal.c (BigDecimal_to_f): use strtod() for more diff --git a/configure.in b/configure.in index 28e85f39ec..0ede6e4d4b 100644 --- a/configure.in +++ b/configure.in @@ -649,7 +649,7 @@ esac 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\ @@ -402,6 +402,20 @@ math_sqrt(VALUE obj, VALUE x) /* * 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 @@ Init_Math(void) 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); diff --git a/missing/cbrt.c b/missing/cbrt.c new file mode 100644 index 0000000000..54db2703a0 --- /dev/null +++ b/missing/cbrt.c @@ -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); +} + |