Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The conversion of Float to UInt64 doesn't behave as described in the documentation. #5483

Closed
3 tasks done
TomasPuverle opened this issue Sep 26, 2024 · 2 comments · Fixed by #5497
Closed
3 tasks done
Labels
bug Something isn't working P-medium We may work on this issue if we find the time

Comments

@TomasPuverle
Copy link
Contributor

Prerequisites

Please put an X between the brackets as you perform the following steps:

Description

The conversion of Float to UInt64 (etc) doesn't behave as described in the documentation.

From Data/Float.lean:

/-- If the given float is positive, truncates the value to the nearest positive integer.
If negative or larger than the maximum value for UInt64, returns 0. -/
@[extern "lean_float_to_uint64"] opaque Float.toUInt64 : Float → UInt64

However, the following seems problematic:

def inf : Float := 1.0 / 0.0

-- All of the statements below return true
#eval Float.isInf inf
#eval inf.toUInt64.toNat == (UInt64.size - 1)
#eval (UInt64.size.toFloat * 2).toUInt64.toNat == (UInt64.size - 1)

Context

As discussed on Zulip

Steps to Reproduce

  1. See the code above

Expected behavior:

  • Either fix the code to return 0
  • Update documentation to reflect that the "largest Uint64 value" is returned

Actual behavior:

  • Currently returns UIntXX.size - 1

Versions

"4.12.0, commit 5dea30f", MacOS

Additional Information

I'm happy to create a PR, either to fix the behavior or the documentation.

Impact

@TomasPuverle TomasPuverle added the bug Something isn't working label Sep 26, 2024
@Kha
Copy link
Member

Kha commented Sep 27, 2024

Yes, the documentation is wrong. Docfix appreciated.

@leanprover-bot leanprover-bot added the P-medium We may work on this issue if we find the time label Sep 27, 2024
@TomasPuverle
Copy link
Contributor Author

TomasPuverle commented Sep 27, 2024

PR is up: #5497

github-merge-queue bot pushed a commit that referenced this issue Sep 29, 2024
Update documentation on functions to reflect actual behavior.
Add tests to ensure said behavior is as documented.

Closes #5483
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P-medium We may work on this issue if we find the time
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants