Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

cmplx Package in Golang

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Go language provides inbuilt support for basic constants and mathematical functions for complex numbers with the help of the cmplx package.

FunctionDescription
AbsThis function returns the absolute value (also called the modulus) of the specified complex number.
AcosThis function returns the inverse cosine of the specified complex number.
AcoshThis function returns the inverse hyperbolic cosine of the specified complex number.
AsinThis function returns the inverse sine of the specified complex number.
AsinhThis function returns the inverse hyperbolic sine of the specified complex number.
AtanThis function returns the inverse tangent of the specified complex number.
AtanhThis function returns the inverse hyperbolic tangent of the specified complex number.
ConjThis function returns the complex conjugate of the specified complex number.
CosThis function is used to return the cosine of the specified complex number.
CoshThis function returns the hyperbolic cosine of the specified complex number.
CotThis function returns the cotangent of the specified complex number.
ExpThis function returns e**x, the base-e exponential of the specified complex number.
InfThis function returns a complex infinity, complex(+Inf, +Inf).
IsInfThis function report whether either real(x) or imag(x) is an infinity.
IsNaNThis function report whether either real(x) or imag(x) is NaN and neither is an infinity.
LogThis function returns the natural logarithm of the specified complex number.
Log10This function returns the decimal logarithm of the specified complex number.
NaNThis function returns a complex “not-a-number” value.
PhaseThis function returns the phase (also called the argument) of the specified complex number.
PolarThis function returns the absolute value r and phase θ of x, such that x = r * e**θi.
PowThis function returns x**y, the base-x exponential of y
RectThis function returns the complex number x with polar coordinates r, θ.
SinThis function returns the sine of the specified complex number.
SinhThis function returns the hyperbolic sine of the specified complex number.
SqrtThis function returns the square root of the specified complex number.
TanThis function returns the tangent of the specified complex number.
TanhThis function returns the hyperbolic tangent of the specified complex number.

Example 1:




// Golang program to illustrate how to find 
// the sine value of the given complex number 
     
package main 
     
import ( 
    "fmt"
    "math/cmplx"
     
// Main function 
func main() { 
     
    // Finding sine of the  
    // specified complex number 
    // Using Sin() function 
    res_1 := cmplx.Sin(2 + 5i) 
    res_2 := cmplx.Sin(-1 + 8i) 
    res_3 := cmplx.Sin(-1 - 7i) 
     
    // Displaying the result 
    fmt.Println("Result 1:", res_1) 
    fmt.Println("Result 2:", res_2) 
    fmt.Println("Result 3:", res_3) 

Output:

Result 1: (67.47891523845587-30.879431343588244i)
Result 2: (-1254.1949676545178+805.3091464217314i)
Result 3: (-461.3928755590023-296.25646574921427i)

Example 2:




// Golang program to illustrate 
// how to find absolute value 
package main 
     
import ( 
    "fmt"
    "math/cmplx"
     
// Main function 
func main() { 
     
    // Finding absolute value of 
    // the specified complex number 
    // Using Abs() function 
    res_1 := cmplx.Abs(3 + 5i) 
    res_2 := cmplx.Abs(-4 + 8i) 
    res_3 := cmplx.Abs(-8 - 7i) 
     
    // Displaying the result 
    fmt.Println("Random Number 1:", res_1) 
    fmt.Println("Random Number 2: ", res_2) 
    fmt.Println("Random Number 3: ", res_3) 

Output:

Random Number 1: 5.8309518948453
Random Number 2:  8.94427190999916
Random Number 3:  10.63014581273465

My Personal Notes arrow_drop_up
Last Updated : 08 Jun, 2020
Like Article
Save Article
Similar Reads