Finding Complementary Error Function of Float in Golang
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. You are allowed to find the complementary error function of the specified number with the help of the Erfc() function provided by the math package. So, you need to add a math package in your program with the help of the import keyword to access the Erfc() function.
Syntax:
func Erfc(a float64) float64
- If you pass +Inf in this function, then this function will return 0.
- If you pass -Inf in this function, then this function will return 2.
- If you pass NaN in this function, then this function will return NaN.
Example 1:
// Golang program to illustrate how to find // complementary error function of the // given number package main import ( "fmt" "math" ) // Main function func main() { // Finding complementary error function // Using Erfc() function res_1 := math.Erfc(4.8) res_2 := math.Erfc(math.Inf(-3)) res_3 := math.Erfc(math.Inf(3)) res_4 := math.Erfc(math.NaN()) // Displaying the result fmt.Printf( "Result 1: %.1f" , res_1) fmt.Printf( "\nResult 2: %.1f" , res_2) fmt.Printf( "\nResult 3: %.1f" , res_3) fmt.Printf( "\nResult 4: %.1f" , res_4) } |
chevron_right
filter_none
Output:
Result 1: 0.0 Result 2: 2.0 Result 3: 0.0 Result 4: NaN
Example 2:
// Golang program to illustrate how to find // complementary error function of the // given number package main import ( "fmt" "math" ) // Main function func main() { // Finding complementary // error function // Using Erfc() function nvalue_1 := math.Erfc(math.Inf(-3)) nvalue_2 := math.Erfc(4.9) res := nvalue_1 + nvalue_2 fmt.Printf( "%.1f + %.1f = %.1f" , nvalue_1, nvalue_2, res) } |
chevron_right
filter_none
Output:
2.0 + 0.0 = 2.0