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

Overflow Occurs When Converting math.MaxUint64 to Floating-Point Types #2004

Closed
notJoon opened this issue Apr 30, 2024 · 0 comments · Fixed by #2024
Closed

Overflow Occurs When Converting math.MaxUint64 to Floating-Point Types #2004

notJoon opened this issue Apr 30, 2024 · 0 comments · Fixed by #2024
Assignees
Labels
📦 🤖 gnovm Issues or PRs gnovm related

Comments

@notJoon
Copy link
Member

notJoon commented Apr 30, 2024

Description

When converting math.MaxUint64 to float32 or float64 types, an overflow occurs. I think precision loss has occured during the type conversion (not sure). Note that, It works fine with math.MaxUint32

package main

import (
  "math"
)

func main() {
  println(float64(math.MaxUint32))         // 4.294967295e+09
  println(float64(math.MaxUint64))         // error
}

// panic: bigint overflows target kind [recovered]
        panic: main/gnovm/tests/files/a0.gno:9: bigint overflows target kind:

Expected Output:

4.294967e+09
5.421011e-02
@deelawn deelawn self-assigned this May 2, 2024
@Kouteki Kouteki moved this from Triage to In Progress in 🧙‍♂️gno.land core team May 10, 2024
@Kouteki Kouteki added the 📦 🤖 gnovm Issues or PRs gnovm related label May 10, 2024
zivkovicmilos added a commit that referenced this issue Jun 14, 2024
Closes #2004. This change allows for passing a value to `defaultTypeOf`.
In the case where we are looking for the default value of an untyped
int, it can use the value, if it exists, in order to determine whether
the default type should be a signed or unsigned int.
<!-- please provide a detailed description of the changes made in this
pull request. -->

<details><summary>Contributors' checklist...</summary>

- [x] Added new tests, or not needed, or not feasible
- [x] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [x] Updated the official documentation or not needed
- [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [x] Added references to related issues and PRs
- [x] Provided any useful hints for running manual tests
- [x] Added new benchmarks to [generated
graphs](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>

---------

Co-authored-by: Miloš Živković <[email protected]>
@github-project-automation github-project-automation bot moved this from In Progress to Done in 🧙‍♂️gno.land core team Jun 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🤖 gnovm Issues or PRs gnovm related
Projects
Development

Successfully merging a pull request may close this issue.

3 participants