Skip to content

proposal: math: add IsDivisible(float64, float64) bool #26181

@AyushG3112

Description

@AyushG3112

In the application I'm working on, I came across a requirement to find out whether one float was divisible by another. I tried doing this by using the math.Mod and math.Remainder method to check if the result == 0.0.

package main

import "fmt"
import "math"

func main() {
  fmt.Println(math.Remainder(2000.0, 0.01))
  fmt.Println(math.Mod(2000.0, 0.01))
}

As you can see in this playground sample, neither of those work perfectly. While I was able to hack away the problem by a rather cumbersome hack, I think it would be pretty useful if the go standard library provides a method to check if a float is divisible by another.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions