Here, We will learn about Nextafter() fucntion in math package in go. Nextafter() is used to get the next representable float64 value after 1st number towards 2nd number.
Function prototype:
func Nextafter(x, y float64) (res float64)
Return value:
Nextafter() function in math package returns
the next representable float64 value after
x towards y.
Example with code:
package main
import (
"fmt"
"math"
)
func main() {
no := math.Nextafter(2.3, 2)
fmt.Println(no)
no = math.Nextafter(-2.2, -10)
fmt.Println(no)
no = math.Nextafter(1.2, -1)
fmt.Println(no)
no = math.Nextafter(3, 0)
fmt.Println(no)
}
Output:
2.2999999999999994
-2.2000000000000006
1.1999999999999997
2.9999999999999996
To learn more about golang, Please refer given below link:
https://techieindoor.com/go-lang-tutorial/
References:
https://golang.org/doc/
https://golang.org/pkg/