Open In App

reflect.Complex() Function in Golang with Examples

Last Updated : 03 May, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
Go language provides inbuilt support implementation of run-time reflection and allowing a program to manipulate objects with arbitrary types with the help of reflect package. The reflect.Complex() Function in Golang is used to get the v's underlying value. To access this function, one needs to imports the reflect package in the program.
Syntax:
func (v Value) Complex() complex128
Parameters: This function does not accept any parameters. Return Value: This function returns the v's underlying value.
Below examples illustrate the use of the above method in Golang: Example 1: C
// Golang program to illustrate 
// reflect.complex() Function 

package main
 
 import (
    "fmt"
    "reflect"
 )

 func main() {        
    fmt.Println(reflect.ValueOf(complex(0, 0)).Complex())

 }                 
Output:
(0+0i)
Example 2: C
// Golang program to illustrate 
// reflect.Complex() Function 

package main
 
 import (
    "fmt"
    "reflect"
 )
 
const a = complex(100, 8)

 const b = complex(8, 100)

 func main() {
    fmt.Println("Complex number a : ", a)
    fmt.Println("Complex number b : ", b)
    
    c := a + b
        
    fmt.Println(reflect.ValueOf(c).Complex())

 }         
Output:
Complex number a :  (100+8i)
Complex number b :  (8+100i)
(108+108i)

Next Article
Article Tags :

Similar Reads