La función complx.Rect() en Golang devuelve el número complejo x con coordenadas polares r, θ. Toma el valor flotante como entrada y devuelve un número complejo. Este método pertenece al paquete complejo.
Sintaxis:
func Rect(r, θ float64) complex128;
Aquí, r y θ son los números complejos con float64 partes reales e imaginarias.
Valor devuelto: Devuelve un número complejo de coordenadas polares r y θ.
Ejemplo 1: este ejemplo calcula el valor pasando argumentos (5, 45).
// Golang program to illustrate // the complx.Rect() Function package main // importing fmt and math/cmplx import ( "fmt" "math/cmplx" ) // Calling Main method func main () { // using the function fmt.Printf ("%.1f", cmplx.Rect (5, 45)) }
Producción:
(2.6+4.3i)
Ejemplo 2:
// Golang program to illustrate // the complx.Rect() Function package main // importing fmt, math and math/cmplx import ( "fmt" "math" "math/cmplx" ) // Calling Main method func main() { // using the function fmt.Printf("%.1f,", cmplx.Rect(5, 4*math.Pi)) fmt.Printf("%.1f", cmplx.Rect(5, 90)) }
Producción:
(5.0-0.0i),(-2.2+4.5i)
Publicación traducida automáticamente
Artículo escrito por PranchalKatiyar y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA