What is the Erfinv function in Golang?

The Erfinv function

The Go programming language uses the Erfinv function to find the inverse error function of a certain decimal number.

To use this function, you must import the math package in your file and access the Erfinv function within it using the . notation (math.Erfinv). Here, Erfinv is the actual function, while math is the Go package that stores the definition of this function.

The inverse error function

As the name suggests, the inverse error function is the functional inverse of the error function (also known as the Gauss error function). It is denoted as erfc(x)1^{{-1}}; the following formula defines the erf(x) function:

widget

Function definition

The definition of the Erfinv function inside the math package is:

Parameters

The Erfinv function takes a single argument of type float64. This argument represents the decimal number whose inverse error function you want to find.

Return value

The Erfinv function returns a single value of type float64. This value represents the inverse error function for a particular input argument.

Following are the types of return values only used by the function under certain circumstances:

  • NAN: Not a number, or NAN, is returned in all cases where the input argument is an undefined float or has a value greater than 1 or less than -1.

The error function is a sigmoid function. Its domain is from negative to positive infinity, while its range is between -1 and +1. So, the inverse error function has its domain and range values switched, having a domain of -1 to +1 and a range of -Inf to +Inf.

  • (+-)Inf: The Erfinv function returns +Inf if the input argument has a value equalling +1 infinity and -Inf for -1.

Giving an empty argument or an argument that is not a numeric value results in an error.

Examples

Following is a simple example where we find out the inverse error function of a positive decimal value:

package main
import (
"fmt"
"math"
)
func main() {
x := 0.8
y := math.Erfinv(x)
fmt.Print("The inverse error function of ", x, "is ", y)
}

The following example shows how the Erfinv function deals with an argument out of its domain:

package main
import (
"fmt"
"math"
)
func main() {
y := math.Erfinv(2)
fmt.Print("The inverse error function of 2 is ", y)
}

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved