Skip to content

Conversation

lewis6991
Copy link
Collaborator

math.floor(math.huge) == math.huge so should define it as an integer.

`math.floor(math.huge) == math.huge` so should define it as an integer.
@CppCXY CppCXY merged commit 1f448e0 into EmmyLuaLs:main Apr 7, 2025
14 checks passed
@taminomara
Copy link
Contributor

Sorry but this is wrong, math.huge is a floating point infinity value, it should not be an integer:

math.tointeger(math.huge) == nil

@lewis6991
Copy link
Collaborator Author

Then please explain math.floor(math.huge) == math.huge

If this isn't true then math.floor doesn't return integers.

@taminomara
Copy link
Contributor

taminomara commented May 14, 2025

Then please explain math.floor(math.huge) == math.huge

If this isn't true then math.floor doesn't return integers.

It's true, if math.floor gets a floating point number, then it returns a rounded down floating point number. That includes all caveats regarding special values for floating points (inf, nan, etc.) That also holds true for cases when the given value does not fit a 64-bit signed integer:

math.floor(2 ^ 64) -- not an integer: 1.844674407371e+19

So, yes, technically math.floor should return a number.

@taminomara
Copy link
Contributor

I'm not sure how to annotate math.floor, though. If we want to force users to check for these corner cases, then we should go with number. If we prefer it to be more ergonomic, then we should go with integer (most users will not run into these corner cases, probably).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants