Menu Close

Go – Nextafter32() fucntion in math package in go

Here, We will learn about Nextafter32() fucntion in math package in go.  Nextafter32() is used to get the next representable float32 value after 1st number towards 2nd number.

Function prototype:

func Nextafter32(x, y float32) (res float32)

Return value:

Nextafter32() function in math package returns
the next representable float32 value after
x towards y.

Example with code:

package main

import (
  "fmt"
  "math"
)

func main() {

  no := math.Nextafter32(2.3, 2)
  fmt.Println(no)

  no = math.Nextafter32(-2.2, -10)
  fmt.Println(no)

  no = math.Nextafter32(1.2, -1)
  fmt.Println(no)

  no = math.Nextafter32(3, 0)
  fmt.Println(no)

}

Output:

2.2999997
-2.2000003
1.1999999
2.9999998

To learn more about golang, Please refer given below link:

https://www.techieindoor.com/go-lang-tutorial/

References:

https://golang.org/doc/
https://golang.org/pkg/
Posted in golang, math

Leave a Reply

Your email address will not be published.

Contact Us