Menu Close

Go – How to get the IEEE 754 floating-point remainder of x/y in go

Here, We will learn how to get the IEEE 754 floating-point remainder of x/y in go. We can get it by using Remainder() function in math package in go golang.

Function prototype:

func Remainder(x, y float64) float64

Return value:

Remainder() function in math package returns 
IEEE 754 floating-point remainder of x/y.

Example with code:

package main

import (
  "fmt"
  "math"
)

func main() {

  no := math.Remainder(3, 5)
  fmt.Println(no)

  no = math.Remainder(2.3, 2)
  fmt.Println(no)

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

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

}

Output:

-2
0.2999999999999998
-2.2
NaN

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/
Posted in golang, math

Leave a Reply

Your email address will not be published. Required fields are marked *