cube root Archives - Welcome To Golang By Example https://vikasboss.github.io/tag/cube-root/ Thu, 26 Mar 2020 05:32:17 +0000 en-US hourly 1 https://wordpress.org/?v=6.8.1 https://i0.wp.com/golangbyexamples.com/wp-content/uploads/2021/05/cropped-go_border-1.png?fit=32%2C32&ssl=1 cube root Archives - Welcome To Golang By Example https://vikasboss.github.io/tag/cube-root/ 32 32 159787465 Cube Root of a number in Go (Golang) https://vikasboss.github.io/cube-root-number-golang/ https://vikasboss.github.io/cube-root-number-golang/#respond Thu, 26 Mar 2020 05:32:12 +0000 https://vikasboss.github.io/?p=1842 Overview math package of GO provides a Cbrt method that can be used to get the cube root of that number. Below is the signature of the function. It takes input a...

The post Cube Root of a number in Go (Golang) appeared first on Welcome To Golang By Example.

]]>
Overview

math package of GO provides a Cbrt method that can be used to get the cube root of that number.

Below is the signature of the function. It takes input a float and also returns a float.

func Cbrt(x float64) float64

Some special cases of Cbrt function are

  • Cbrt(±0) = ±0
  • Cbrt(±Inf) = ±Inf
  • Cbrt(NaN) = NaN

Code:

package main

import (
    "fmt"
    "math"
)

func main() {
    res := math.Cbrt(8)
    fmt.Println(res)

    res = math.Cbrt(27)
    fmt.Println(res)

    res = math.Cbrt(30.33)
    fmt.Println(res)
}

Output:

2
3
3.118584170228812

The post Cube Root of a number in Go (Golang) appeared first on Welcome To Golang By Example.

]]>
https://vikasboss.github.io/cube-root-number-golang/feed/ 0 1842