# Math.cbrt

**URL:** <https://www.ruby-forum.com/t/math-cbrt/128597>\
**Category:** Development\
**Created:** [February 9, 2008, 5:04am UTC](https://www.ruby-forum.com/t/math-cbrt/128597 "2008-02-09T05:04:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tanaka\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c67d28/32.png) [@Tanaka\_A](https://www.ruby-forum.com/u/Tanaka_A)\
**Post date:** [February 9, 2008, 5:04am UTC](https://www.ruby-forum.com/t/math-cbrt/128597/1 "2008-02-09T05:04:11Z")

</div>

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);

- 

```
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);

```

+}  
+

---

<div class="post-metadata">

**Author:** ![Tanaka\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c67d28/32.png) [@Tanaka\_A](https://www.ruby-forum.com/u/Tanaka_A)\
**Post date:** [February 9, 2008, 9:38am UTC](https://www.ruby-forum.com/t/math-cbrt/128597/2 "2008-02-09T09:38:59Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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
