Ruby | Math cbrt() function

The atanh() is an inbuilt function in Ruby returns the cube root of a given value.

Syntax: Math.cbrt(value)

Parameters: The function accepts one mandatory parameter value whose cuberoot is to be returned.



Return Value: It returns the cuberoot of the value.

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

#Ruby program for cbrt() function
  
#Assigning values
val1 = 8 val2 = 27 val3 = 64 val4 = 1000
  
#Prints the cbrt() value
                                    puts Math.cbrt(val1)
                                        puts Math.cbrt(val2)
                                            puts Math.cbrt(val3)
                                                puts Math.cbrt(val4)

chevron_right


Output:

2.0
3.0000000000000004
4.0
10.0

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

#Ruby program for cbrt() function
  
#Assigning values
val1 = 10 val2 = -29 val3 = 899 val4 = -87879
  
#Prints the cbrt() value
                                        puts Math.cbrt(val1)
                                            puts Math.cbrt(val2)
                                                puts Math.cbrt(val3)
                                                    puts Math.cbrt(val4)

chevron_right


Output:

2.1544346900318834
-3.0723168256858475
9.651316634226061
-44.45920597627334

Reference: https://devdocs.io/ruby~2.5/math#method-c-cbrt



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.