cmplx Package in Golang
Go language provides inbuilt support for basic constants and mathematical functions for complex numbers with the help of the cmplx package.
Function | Description |
---|---|
Abs | This function returns the absolute value (also called the modulus) of the specified complex number. |
Acos | This function returns the inverse cosine of the specified complex number. |
Acosh | This function returns the inverse hyperbolic cosine of the specified complex number. |
Asin | This function returns the inverse sine of the specified complex number. |
Asinh | This function returns the inverse hyperbolic sine of the specified complex number. |
Atan | This function returns the inverse tangent of the specified complex number. |
Atanh | This function returns the inverse hyperbolic tangent of the specified complex number. |
Conj | This function returns the complex conjugate of the specified complex number. |
Cos | This function is used to return the cosine of the specified complex number. |
Cosh | This function returns the hyperbolic cosine of the specified complex number. |
Cot | This function returns the cotangent of the specified complex number. |
Exp | This function returns e**x, the base-e exponential of the specified complex number. |
Inf | This function returns a complex infinity, complex(+Inf, +Inf). |
IsInf | This function report whether either real(x) or imag(x) is an infinity. |
IsNaN | This function report whether either real(x) or imag(x) is NaN and neither is an infinity. |
Log | This function returns the natural logarithm of the specified complex number. |
Log10 | This function returns the decimal logarithm of the specified complex number. |
NaN | This function returns a complex “not-a-number” value. |
Phase | This function returns the phase (also called the argument) of the specified complex number. |
Polar | This function returns the absolute value r and phase θ of x, such that x = r * e**θi. |
Pow | This function returns x**y, the base-x exponential of y |
Rect | This function returns the complex number x with polar coordinates r, θ. |
Sin | This function returns the sine of the specified complex number. |
Sinh | This function returns the hyperbolic sine of the specified complex number. |
Sqrt | This function returns the square root of the specified complex number. |
Tan | This function returns the tangent of the specified complex number. |
Tanh | This 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
Please Login to comment...