ADVERTISEMENT
ADVERTISEMENT

Golang math.Erfc() Function with Examples

Golang | math.Erfc() Function: Here, we are going to learn about the Erfc() function of the math package with its usages, syntax, and examples.
Submitted by IncludeHelp, on August 30, 2021

math.Erfc()

The Erfc() function is an inbuilt function of the math package which is used to get the complementary error function of the given parameter.

It accepts a parameter (x) and returns the complementary error function of x.

Syntax:

func Erfc(x float64) float64

Parameter(s):

  • x : The value of float64 type whose complementary error function is to be found.

Return Value:

The return type of Erfc() function is a float64, it returns the complementary error function of the given parameter.

Special cases are:

  • Erfc(+Inf) = 0
    If the parameter is the positive infinity, the function returns 0.
  • Erfc(-Inf) = 2
    If the parameter is the negative infinity, the function returns 2.
  • Erfc(NaN) = NaN
    If the parameter is NaN (Not-A-Number), the function returns NaN.

Example 1:

// Golang program to demonstrate the
// example of math.Erfc() Function

package main

import (
	"fmt"
	"math"
)

func main() {
	fmt.Println(math.Erfc(-10))
	fmt.Println(math.Erfc(10))
	fmt.Println(math.Erfc(-1))
	fmt.Println(math.Erfc(1))
	fmt.Println(math.Erfc(-0.89))
	fmt.Println(math.Erfc(0.89))

	fmt.Println(math.Erfc(math.Inf(-1)))
	fmt.Println(math.Erfc(math.Inf(1)))
	fmt.Println(math.Erfc(math.NaN()))
}

Output:

2
2.0884875837625446e-45
1.8427007929497148
0.15729920705028513
1.7918432468144954
0.20815675318550464
2
0
NaN

Example 2:

// Golang program to demonstrate the
// example of math.Erfc() Function

package main

import (
	"fmt"
	"math"
)

func main() {
	var x float64
	var ErfcX float64

	x = -10
	ErfcX = math.Erfc(x)
	fmt.Println("Erfc(", x, ") = ", ErfcX)

	x = 0.89
	ErfcX = math.Erfc(x)
	fmt.Println("Erfc(", x, ") = ", ErfcX)

	x = -1
	ErfcX = math.Erfc(x)
	fmt.Println("Erfc(", x, ") = ", ErfcX)

	x = math.Inf(-1)
	ErfcX = math.Erfc(x)
	fmt.Println("Erfc(", x, ") = ", ErfcX)

	x = math.NaN()
	ErfcX = math.Erfc(x)
	fmt.Println("Erfc(", x, ") = ", ErfcX)
}

Output:

Erfc( -10 ) =  2
Erfc( 0.89 ) =  0.20815675318550464
Erfc( -1 ) =  1.8427007929497148
Erfc( -Inf ) =  2
Erfc( NaN ) =  NaN

Golang math Package Constants and Functions »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.