Skip to content

math: Document behavior of math.Ceil #15931

@kevinburkeshyp

Description

@kevinburkeshyp

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)?

Tip

  1. What operating system and processor architecture are you using (go env)?

Doesn't matter

  1. What did you do?

The documentation for math.Ceil states:

Ceil returns the least integer value greater than or equal to x.

As far as I know, float representations of numbers can approximate integers but may not be land on them exactly. Also, as far as I know, casting a float to an integer always rounds down, e.g. int64(5.999999999) == 5.

I am worried there could be a situation where math.Ceil(N) could return a float like floor(N).999999999999999999, and this gets cast to an integer and returns a number lower than N. It would be nice if this was explicitly documented.

I'm also confused about why math.Ceil doesn't return an int64, though I'm sure there's a good reason for it. It would be nice if there was information about how to convert this value to an integer. (I am aware there are edge cases around large or small numbers, in this case I'm mostly worried about the values between 2^-30 and 2^30).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions