×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

Golang math.Erfinv() Function with Examples

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

math.Erfinv()

The Erfinv() function is an inbuilt function of the math package which is used to get the inverse error function of x (Erf(x)), where x is the given parameter.

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

Syntax

func Erfinv(x float64) float64

Parameters

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

Return Value

The return type of Erfinv() function is a float64, it returns the inverse error function of x.

Special cases are:

  • Erfinv(1) = +Inf
    If the parameter is 1, the function returns +Inf.
  • Erfinv(-1) = -Inf
    If the parameter is -1, the function returns -Inf.
  • Erfinv(x) = NaN if x < -1 or x > 1
    If the parameter is less than -1 or greater than 1, the function returns NaN.
  • Erfinv(NaN) = NaN
    If the parameter is NaN, the function returns NaN.

Example 1

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

package main

import (
	"fmt"
	"math"
)

func main() {
	fmt.Println(math.Erfinv(0))
	fmt.Println(math.Erfinv(0.5))
	fmt.Println(math.Erfinv(-0.5))

	fmt.Println(math.Erfinv(1))
	fmt.Println(math.Erfinv(-1))
	fmt.Println(math.Erfinv(-1.5))
	fmt.Println(math.Erfinv(1.2))
	fmt.Println(math.Erfinv(math.NaN()))
}

Output:

0
0.4769362762044699
-0.4769362762044699
+Inf
-Inf
NaN
NaN
NaN

Example 2

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

package main

import (
	"fmt"
	"math"
)

func main() {
	var x float64
	var ErfinvX float64

	x = 0
	ErfinvX = math.Erfinv(x)
	fmt.Println("Erfinv(", x, ") = ", ErfinvX)

	x = 0.5
	ErfinvX = math.Erfinv(x)
	fmt.Println("Erfinv(", x, ") = ", ErfinvX)

	x = -0.5
	ErfinvX = math.Erfinv(x)
	fmt.Println("Erfinv(", x, ") = ", ErfinvX)

	x = -1.5
	ErfinvX = math.Erfinv(x)
	fmt.Println("Erfinv(", x, ") = ", ErfinvX)

	x = 1.5
	ErfinvX = math.Erfinv(x)
	fmt.Println("Erfinv(", x, ") = ", ErfinvX)

	x = math.NaN()
	ErfinvX = math.Erfinv(x)
	fmt.Println("Erfinv(", x, ") = ", ErfinvX)
}

Output:

Erfinv( 0 ) =  0
Erfinv( 0.5 ) =  0.4769362762044699
Erfinv( -0.5 ) =  -0.4769362762044699
Erfinv( -1.5 ) =  NaN
Erfinv( 1.5 ) =  NaN
Erfinv( NaN ) =  NaN

Golang math Package Constants and Functions »




Comments and Discussions!

Load comments ↻





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