Math.cbrt

e$B$D$$$G$Ke(B 3e$B>h:,$Ne(B Math.cbrt
e$B$b:n$C$?$s$G$9$,$I$&$G$7$g$&$+!#e(B

cbrt e$B$Oe(B C99 e$B$GDj5A$5$l$F$$$^$9!#e(B

Index: math.c

— math.c (revision 15410)
+++ math.c (working copy)
@@ -402,6 +402,20 @@ math_sqrt(VALUE obj, VALUE x)

/*

  • call-seq:
    • Math.cbrt(numeric)    => float
      
    • Returns the cube root of numeric.
  • */

+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
      @@ -603,6 +617,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);
    Index: configure.in
    ===================================================================
    — configure.in (revision 15410)
    +++ configure.in (working copy)
    @@ -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
Index: missing/cbrt.c

— missing/cbrt.c (revision 0)
+++ missing/cbrt.c (revision 0)
@@ -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);
    

+}
+

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:33667] Math.cbrt”
on Sat, 9 Feb 2008 13:03:44 +0900, Tanaka A. [email protected]
writes:

|e$B$D$$$G$Ke(B 3e$B>h:,$Ne(B Math.cbrt e$B$b:n$C$?$s$G$9$,$I$&$G$7$g$&$+!#e(B
|
|cbrt e$B$Oe(B C99 e$B$GDj5A$5$l$F$$$^$9!#e(B

e$B$I$&$>!#$@$s$@$sBg$-$/$J$k$J$"!#JL$K9=$o$J$$$1$I!#e(B