×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

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

Parameters

  • 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 »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.